5 use RT::Test::GnuPG tests => 198, gnupg_options => { passphrase => 'rt-test' };
7 use Digest::MD5 qw(md5_hex);
9 RT::Test->import_gnupg_key('rt-recipient@example.com');
10 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
11 RT::Test->trust_gnupg_key('rt-test@example.com');
13 my ($baseurl, $m) = RT::Test->started_ok;
14 ok $m->login, 'we did log in';
15 $m->get_ok( '/Admin/Queues/');
16 $m->follow_link_ok( {text => 'General'} );
17 $m->submit_form( form_number => 3,
18 fields => { CorrespondAddress => 'rt-recipient@example.com' } );
19 $m->content_like(qr/rt-recipient\@example.com.* - never/, 'has key info.');
22 for my $usage (qw/signed encrypted signed&encrypted/) {
23 for my $format (qw/MIME inline/) {
24 for my $attachment (qw/plain text-attachment binary-attachment/) {
26 diag "Email $eid: $usage, $attachment email with $format format";
27 eval { email_ok($eid, $usage, $format, $attachment) };
34 my ($usage, $format, $attachment) = ('signed', 'inline', 'plain');
36 diag "Email $eid: $usage, $attachment email with $format format";
37 eval { email_ok($eid, $usage, $format, $attachment) };
41 my ($eid, $usage, $format, $attachment) = @_;
42 diag "email_ok $eid: $usage, $format, $attachment";
44 my $emaildatadir = RT::Test::get_relocatable_dir(File::Spec->updir(),
45 qw(data gnupg emails));
46 my ($file) = glob("$emaildatadir/$eid-*");
47 my $mail = RT::Test->file_content($file);
49 my ($status, $id) = RT::Test->send_via_mailgate($mail);
50 is ($status >> 8, 0, "$eid: The mail gateway exited normally");
51 ok ($id, "$eid: got id of a newly created ticket - $id");
53 my $tick = RT::Ticket->new( RT->SystemUser );
55 ok ($tick->id, "$eid: loaded ticket #$id");
59 "$eid: Created the ticket"
62 my $txn = $tick->Transactions->First;
63 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
65 is( $msg->GetHeader('X-RT-Privacy'),
67 "$eid: recorded incoming mail that is encrypted"
70 if ($usage =~ /encrypted/) {
71 if ( $format eq 'MIME' || $attachment eq 'plain' ) {
72 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
74 "$eid: recorded incoming mail that is encrypted"
77 is( $attachments[0]->GetHeader('X-RT-Incoming-Encryption'),
79 "$eid: recorded incoming mail that is encrypted"
81 is( $attachments[1]->GetHeader('X-RT-Incoming-Encryption'),
83 "$eid: recorded incoming mail that is encrypted"
86 like( $attachments[0]->Content, qr/ID:$eid/,
87 "$eid: incoming mail did NOT have original body"
91 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
93 "$eid: recorded incoming mail that is not encrypted"
95 like( $msg->Content || $attachments[0]->Content, qr/ID:$eid/,
96 "$eid: got original content"
100 if ($usage =~ /signed/) {
101 # XXX: FIXME: TODO: 6-signed-inline-with-attachment should be re-generated as it's actually RFC format
102 if ( $format eq 'MIME' || $attachment eq 'plain' || ($format eq 'inline' && $attachment =~ /binary/ && $usage !~ /encrypted/) ) {
103 is( $msg->GetHeader('X-RT-Incoming-Signature'),
104 'RT Test <rt-test@example.com>',
105 "$eid: recorded incoming mail that is signed"
109 is( $attachments[0]->GetHeader('X-RT-Incoming-Signature'),
110 'RT Test <rt-test@example.com>',
111 "$eid: recorded incoming mail that is signed"
113 is( $attachments[1]->GetHeader('X-RT-Incoming-Signature'),
114 'RT Test <rt-test@example.com>',
115 "$eid: recorded incoming mail that is signed"
120 is( $msg->GetHeader('X-RT-Incoming-Signature'),
122 "$eid: recorded incoming mail that is not signed"
126 if ($attachment =~ /attachment/) {
127 # signed messages should sign each attachment too
128 if ($usage =~ /signed/) {
129 my $sig = pop @attachments;
130 ok ($sig->Id, "$eid: loaded attachment.sig object");
131 my $acontent = $sig->Content;
134 my ($a) = grep $_->Filename, @attachments;
135 ok ($a && $a->Id, "$eid: found attachment with filename");
137 my $acontent = $a->Content;
138 if ($attachment =~ /binary/)
140 is(md5_hex($acontent), '1e35f1aa90c98ca2bab85c26ae3e1ba7', "$eid: The binary attachment's md5sum matches");
144 like($acontent, qr/zanzibar/, "$eid: The attachment isn't screwed up in the database.");