4 use RT::Test::SMIME tests => undef, actual_server => 1;
5 my $test = 'RT::Test::SMIME';
8 use String::ShellQuote 'shell_quote';
12 my ($url, $m) = RT::Test->started_ok;
13 ok $m->login, "logged in";
15 # configure key for General queue
16 RT::Test::SMIME->import_key('sender@example.com');
17 my $queue = RT::Test->load_or_create_queue(
19 CorrespondAddress => 'sender@example.com',
20 CommentAddress => 'sender@example.com',
22 ok $queue && $queue->id, 'loaded or created queue';
24 my $user = RT::Test->load_or_create_user(
25 Name => 'root@example.com',
26 EmailAddress => 'root@example.com',
28 RT::Test::SMIME->import_key('root@example.com.crt', $user);
29 RT::Test->add_rights( Principal => $user, Right => 'SuperUser', Object => RT->System );
31 my $mail = RT::Test->open_mailgate_ok($url);
35 Subject: This is a test of new ticket creation as root
40 RT::Test->close_mailgate_ok($mail);
43 my $tick = RT::Test->last_ticket;
45 'This is a test of new ticket creation as root',
48 my $txn = $tick->Transactions->First;
50 $txn->Attachments->First->Headers,
51 qr/^X-RT-Incoming-Encryption: Not encrypted/m,
52 'recorded incoming mail that is not encrypted'
54 like( $txn->Attachments->First->Content, qr'Blah');
58 # test for encrypted mail
62 qw(openssl smime -encrypt -des3),
63 -from => 'root@example.com',
64 -to => 'sender@example.com',
65 -subject => "Encrypted message for queue",
66 $test->key_path('sender@example.com.crt'),
68 \"Subject: test\n\norzzzzzz",
73 my ($status, $tid) = RT::Test->send_via_mailgate( $buf );
74 is ($status >> 8, 0, "The mail gateway exited normally");
76 my $tick = RT::Ticket->new( $RT::SystemUser );
78 is( $tick->Subject, 'Encrypted message for queue',
82 my $txn = $tick->Transactions->First;
83 my ($msg, $attach, $orig) = @{$txn->Attachments->ItemsArrayRef};
84 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
86 'recorded incoming mail that is encrypted'
88 is( $msg->GetHeader('X-RT-Privacy'),
90 'recorded incoming mail that is encrypted'
92 like( $attach->Content, qr'orz');
94 is( $orig->GetHeader('Content-Type'), 'application/x-rt-original-message');
104 RT->Config->Get('SMIME')->{'OpenSSL'},
105 qw( smime -sign -nodetach -passin pass:123456),
106 -signer => $test->key_path('root@example.com.crt'),
107 -inkey => $test->key_path('root@example.com.key'),
111 qw(openssl smime -encrypt -des3),
112 -from => 'root@example.com',
113 -to => 'sender@example.com',
114 -subject => "Encrypted and signed message for queue",
115 $test->key_path('sender@example.com.crt'),
117 \"Subject: test\n\norzzzzzz",
122 my ($status, $tid) = RT::Test->send_via_mailgate( $buf );
124 my $tick = RT::Ticket->new( $RT::SystemUser );
126 ok( $tick->Id, "found ticket " . $tick->Id );
127 is( $tick->Subject, 'Encrypted and signed message for queue',
131 my $txn = $tick->Transactions->First;
132 my ($msg, $attach, $orig) = @{$txn->Attachments->ItemsArrayRef};
133 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
135 'recorded incoming mail that is encrypted'
137 like( $attach->Content, qr'orzzzz');
145 RT->Config->Get('SMIME')->{'OpenSSL'},
146 qw( smime -sign -passin pass:123456),
147 -signer => $test->key_path('root@example.com.crt'),
148 -inkey => $test->key_path('root@example.com.key'),
150 \"Content-type: text/plain\n\nThis is the body",
154 $buf = "Subject: Signed email\n"
155 . "From: root\@example.com\n"
159 my ($status, $tid) = RT::Test->send_via_mailgate( $buf );
161 my $tick = RT::Ticket->new( $RT::SystemUser );
163 ok( $tick->Id, "found ticket " . $tick->Id );
164 is( $tick->Subject, 'Signed email',
168 my $txn = $tick->Transactions->First;
169 my ($msg, $attach, $orig) = @{$txn->Attachments->ItemsArrayRef};
170 is( $msg->GetHeader('X-RT-Incoming-Signature'),
171 '"Enoch Root" <root@example.com>',
174 like( $attach->Content, qr/This is the body/ );
177 # Make the signature not match
178 $buf =~ s/This is the body/This is not the body/;
181 my ($status, $tid) = RT::Test->send_via_mailgate( $buf );
183 my $tick = RT::Ticket->new( $RT::SystemUser );
185 ok( $tick->Id, "found ticket " . $tick->Id );
186 is( $tick->Subject, 'Signed email',
190 my $txn = $tick->Transactions->First;
191 my ($msg, $attach, $orig) = @{$txn->Attachments->ItemsArrayRef};
192 isnt( $msg->GetHeader('X-RT-Incoming-Signature'),
193 '"Enoch Root" <root@example.com>',
194 "Message was not marked signed"
196 like( $attach->Content, qr/This is not the body/ );
197 } qr/Failure during SMIME verify: The signature did not verify/;