RT 4.2.11, ticket#13852
[freeside.git] / rt / t / crypt / smime / attachments-in-db.t
1 use strict;
2 use warnings;
3
4 use RT::Test::SMIME tests => undef;
5
6 use IPC::Run3 'run3';
7 use String::ShellQuote 'shell_quote';
8 use RT::Tickets;
9
10 RT->Config->Get('Crypt')->{'AllowEncryptDataInDB'} = 1;
11
12 RT::Test::SMIME->import_key('sender@example.com');
13 my $queue = RT::Test->load_or_create_queue(
14     Name              => 'General',
15     CorrespondAddress => 'sender@example.com',
16 );
17 ok $queue && $queue->id, 'loaded or created queue';
18
19 {
20     my $ticket = RT::Test->create_ticket(
21         Queue   => $queue->id,
22         Subject => 'test',
23         Content => 'test',
24     );
25
26     my $txn = $ticket->Transactions->First;
27     ok $txn && $txn->id, 'found first transaction';
28     is $txn->Type, 'Create', 'it is Create transaction';
29
30     my $attach = $txn->Attachments->First;
31     ok $attach && $attach->id, 'found attachment';
32     is $attach->Content, 'test', 'correct content';
33
34     my ($status, $msg) = $attach->Encrypt;
35     ok $status, 'encrypted attachment' or diag "error: $msg";
36
37     isnt $attach->Content, 'test', 'correct content';
38
39     ($status, $msg) = $attach->Decrypt;
40     ok $status, 'decrypted attachment' or diag "error: $msg";
41
42     is $attach->Content, 'test', 'correct content';
43 }
44
45 done_testing;