RT 4.2.11, ticket#13852
[freeside.git] / rt / t / crypt / gnupg / attachments-in-db.t
1 use strict;
2 use warnings;
3
4 use RT::Test::GnuPG
5     tests         => 12,
6     gnupg_options => {
7         passphrase    => 'recipient',
8         'trust-model' => 'always',
9     }
10 ;
11
12 RT->Config->Get('Crypt')->{'AllowEncryptDataInDB'} = 1;
13
14 RT::Test->import_gnupg_key('general@example.com', 'public');
15 RT::Test->import_gnupg_key('general@example.com', 'secret');
16 my $queue = RT::Test->load_or_create_queue(
17     Name              => 'General',
18     CorrespondAddress => 'general@example.com',
19 );
20 ok $queue && $queue->id, 'loaded or created queue';
21
22 {
23     my $ticket = RT::Test->create_ticket(
24         Queue   => $queue->id,
25         Subject => 'test',
26         Content => 'test',
27     );
28
29     my $txn = $ticket->Transactions->First;
30     ok $txn && $txn->id, 'found first transaction';
31     is $txn->Type, 'Create', 'it is Create transaction';
32
33     my $attach = $txn->Attachments->First;
34     ok $attach && $attach->id, 'found attachment';
35     is $attach->Content, 'test', 'correct content';
36
37     my ($status, $msg) = $attach->Encrypt;
38     ok $status, 'encrypted attachment';
39
40     isnt $attach->Content, 'test', 'correct content';
41
42     ($status, $msg) = $attach->Decrypt;
43     ok $status, 'decrypted attachment';
44
45     is $attach->Content, 'test', 'correct content';
46 }
47
48
49