4 use RT::Test::GnuPG tests => 198, gnupg_options => { passphrase => 'rt-test' };
6 use Digest::MD5 qw(md5_hex);
8 RT::Test->import_gnupg_key('rt-recipient@example.com');
9 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
10 RT::Test->trust_gnupg_key('rt-test@example.com');
12 my ($baseurl, $m) = RT::Test->started_ok;
13 ok $m->login, 'we did log in';
14 $m->get_ok( '/Admin/Queues/');
15 $m->follow_link_ok( {text => 'General'} );
16 $m->submit_form( form_number => 3,
17 fields => { CorrespondAddress => 'rt-recipient@example.com' } );
18 $m->content_like(qr/rt-recipient\@example.com.* - never/, 'has key info.');
21 for my $usage (qw/signed encrypted signed&encrypted/) {
22 for my $format (qw/MIME inline/) {
23 for my $attachment (qw/plain text-attachment binary-attachment/) {
25 diag "Email $eid: $usage, $attachment email with $format format";
26 eval { email_ok($eid, $usage, $format, $attachment) };
33 my ($usage, $format, $attachment) = ('signed', 'inline', 'plain');
35 diag "Email $eid: $usage, $attachment email with $format format";
36 eval { email_ok($eid, $usage, $format, $attachment) };
40 my ($eid, $usage, $format, $attachment) = @_;
41 diag "email_ok $eid: $usage, $format, $attachment";
43 my $emaildatadir = RT::Test::get_relocatable_dir(File::Spec->updir(),
44 qw(data gnupg emails));
45 my ($file) = glob("$emaildatadir/$eid-*");
46 my $mail = RT::Test->file_content($file);
48 my ($status, $id) = RT::Test->send_via_mailgate($mail);
49 is ($status >> 8, 0, "$eid: The mail gateway exited normally");
50 ok ($id, "$eid: got id of a newly created ticket - $id");
52 my $tick = RT::Ticket->new( RT->SystemUser );
54 ok ($tick->id, "$eid: loaded ticket #$id");
58 "$eid: Created the ticket"
61 my $txn = $tick->Transactions->First;
62 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
64 is( $msg->GetHeader('X-RT-Privacy'),
66 "$eid: recorded incoming mail that is encrypted"
69 if ($usage =~ /encrypted/) {
70 if ( $format eq 'MIME' || $attachment eq 'plain' ) {
71 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
73 "$eid: recorded incoming mail that is encrypted"
76 is( $attachments[0]->GetHeader('X-RT-Incoming-Encryption'),
78 "$eid: recorded incoming mail that is encrypted"
80 is( $attachments[1]->GetHeader('X-RT-Incoming-Encryption'),
82 "$eid: recorded incoming mail that is encrypted"
85 like( $attachments[0]->Content, qr/ID:$eid/,
86 "$eid: incoming mail did NOT have original body"
90 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
92 "$eid: recorded incoming mail that is not encrypted"
94 like( $msg->Content || $attachments[0]->Content, qr/ID:$eid/,
95 "$eid: got original content"
99 if ($usage =~ /signed/) {
100 # XXX: FIXME: TODO: 6-signed-inline-with-attachment should be re-generated as it's actually RFC format
101 if ( $format eq 'MIME' || $attachment eq 'plain' || ($format eq 'inline' && $attachment =~ /binary/ && $usage !~ /encrypted/) ) {
102 is( $msg->GetHeader('X-RT-Incoming-Signature'),
103 'RT Test <rt-test@example.com>',
104 "$eid: recorded incoming mail that is signed"
108 is( $attachments[0]->GetHeader('X-RT-Incoming-Signature'),
109 'RT Test <rt-test@example.com>',
110 "$eid: recorded incoming mail that is signed"
112 is( $attachments[1]->GetHeader('X-RT-Incoming-Signature'),
113 'RT Test <rt-test@example.com>',
114 "$eid: recorded incoming mail that is signed"
119 is( $msg->GetHeader('X-RT-Incoming-Signature'),
121 "$eid: recorded incoming mail that is not signed"
125 if ($attachment =~ /attachment/) {
126 # signed messages should sign each attachment too
127 if ($usage =~ /signed/) {
128 my $sig = pop @attachments;
129 ok ($sig->Id, "$eid: loaded attachment.sig object");
130 my $acontent = $sig->Content;
133 my ($a) = grep $_->Filename, @attachments;
134 ok ($a && $a->Id, "$eid: found attachment with filename");
136 my $acontent = $a->Content;
137 if ($attachment =~ /binary/)
139 is(md5_hex($acontent), '1e35f1aa90c98ca2bab85c26ae3e1ba7', "$eid: The binary attachment's md5sum matches");
143 like($acontent, qr/zanzibar/, "$eid: The attachment isn't screwed up in the database.");