4 use RT::Test::SMIME tests => undef;
5 use Digest::MD5 qw(md5_hex);
7 my $test = 'RT::Test::SMIME';
8 my $mails = $test->mail_set_path;
10 RT->Config->Get('SMIME')->{AcceptUntrustedCAs} = 1;
12 RT::Test::SMIME->import_key('root@example.com');
13 RT::Test::SMIME->import_key('sender@example.com');
15 my ($baseurl, $m) = RT::Test->started_ok;
16 ok $m->login, 'we did log in';
17 $m->get_ok( '/Admin/Queues/');
18 $m->follow_link_ok( {text => 'General'} );
19 $m->submit_form( form_number => 3,
20 fields => { CorrespondAddress => 'root@example.com' } );
22 diag "load Everyone group" if $ENV{'TEST_VERBOSE'};
25 $everyone = RT::Group->new( $RT::SystemUser );
26 $everyone->LoadSystemInternalGroup('Everyone');
27 ok $everyone->id, "loaded 'everyone' group";
31 Principal => $everyone,
32 Right => ['CreateTicket'],
37 for my $usage (qw/signed encrypted signed&encrypted/) {
38 for my $attachment (qw/plain text-attachment binary-attachment/) {
40 diag "Email $eid: $usage, $attachment email" if $ENV{TEST_VERBOSE};
41 eval { email_ok($eid, $usage, $attachment) };
49 my ($eid, $usage, $attachment) = @_;
50 diag "email_ok $eid: $usage, $attachment" if $ENV{'TEST_VERBOSE'};
52 my ($file) = glob("$mails/$eid-*");
53 my $mail = RT::Test->file_content($file);
55 my ($status, $id) = RT::Test->send_via_mailgate($mail);
56 is ($status >> 8, 0, "$eid: The mail gateway exited normally");
57 ok ($id, "$eid: got id of a newly created ticket - $id");
59 my $tick = RT::Ticket->new( $RT::SystemUser );
61 ok ($tick->id, "$eid: loaded ticket #$id");
65 "$eid: Created the ticket"
68 my $txn = $tick->Transactions->First;
69 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
71 is( $msg->GetHeader('X-RT-Privacy'),
73 "$eid: recorded incoming mail that is secured"
76 if ($usage =~ /encrypted/) {
77 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
79 "$eid: recorded incoming mail that is encrypted"
81 like( $attachments[0]->Content, qr/ID:$eid/,
82 "$eid: incoming mail did NOT have original body"
86 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
88 "$eid: recorded incoming mail that is not encrypted"
90 like( $msg->Content || $attachments[0]->Content, qr/ID:$eid/,
91 "$eid: got original content"
95 if ($usage =~ /signed/) {
96 is( $msg->GetHeader('X-RT-Incoming-Signature'),
97 '"sender" <sender@example.com>',
98 "$eid: recorded incoming mail that is signed"
102 is( $msg->GetHeader('X-RT-Incoming-Signature'),
104 "$eid: recorded incoming mail that is not signed"
108 if ($attachment =~ /attachment/) {
109 my ($a) = grep $_->Filename, @attachments;
110 ok ($a && $a->Id, "$eid: found attachment with filename");
112 my $acontent = $a->Content;
113 if ($attachment =~ /binary/)
115 is(md5_hex($acontent), '1e35f1aa90c98ca2bab85c26ae3e1ba7', "$eid: The binary attachment's md5sum matches");
119 like($acontent, qr/zanzibar/, "$eid: The attachment isn't screwed up in the database.");