7 passphrase => 'recipient',
8 'trust-model' => 'always',
13 use RT::Action::SendEmail;
15 RT->Config->Set( CommentAddress => 'general@example.com');
16 RT->Config->Set( CorrespondAddress => 'general@example.com');
17 RT->Config->Set( DefaultSearchResultFormat => qq{
18 '<B><A HREF="__WebPath__/Ticket/Display.html?id=__id__">__id__</a></B>/TITLE:#',
19 '<B><A HREF="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a></B>/TITLE:Subject',
21 'OR-__Requestors__-O',
23 'KR-__KeyRequestors__-K',
27 RT::Test->import_gnupg_key('recipient@example.com', 'public');
28 RT::Test->import_gnupg_key('recipient@example.com', 'secret');
29 RT::Test->import_gnupg_key('general@example.com', 'public');
30 RT::Test->import_gnupg_key('general@example.com', 'secret');
31 RT::Test->import_gnupg_key('general@example.com.2', 'public');
32 RT::Test->import_gnupg_key('general@example.com.2', 'secret');
34 ok(my $user = RT::User->new(RT->SystemUser));
35 ok($user->Load('root'), "Loaded user 'root'");
36 $user->SetEmailAddress('recipient@example.com');
38 my $queue = RT::Test->load_or_create_queue(
40 CorrespondAddress => 'general@example.com',
42 ok $queue && $queue->id, 'loaded or created queue';
45 my ($baseurl, $m) = RT::Test->started_ok;
46 ok $m->login, 'logged in';
48 $m->get_ok("/Admin/Queues/Modify.html?id=$qid");
49 $m->form_with_fields('Sign', 'Encrypt');
50 $m->field(Encrypt => 1);
53 RT::Test->clean_caught_mails;
55 $m->goto_create_ticket( $queue );
56 $m->form_name('TicketCreate');
57 $m->field('Requestors', 'recipient@example.com');
58 $m->field('Subject', 'Encryption test');
59 $m->field('Content', 'Some content');
60 ok($m->value('Encrypt', 2), "encrypt tick box is checked");
61 ok(!$m->value('Sign', 2), "sign tick box is unchecked");
63 is($m->status, 200, "request successful");
65 $m->get($baseurl); # ensure that the mail has been processed
67 my @mail = RT::Test->fetch_caught_mails;
68 ok(@mail, "got some mail");
70 $user->SetEmailAddress('general@example.com');
71 for my $mail (@mail) {
72 unlike $mail, qr/Some content/, "outgoing mail was encrypted";
74 my ($content_type, $mime_version) = get_headers($mail, "Content-Type", "MIME-Version");
75 my $body = strip_headers($mail);
78 Subject: RT mail sent back into RT
79 From: general\@example.com
80 To: recipient\@example.com
87 my ($status, $id) = RT::Test->send_via_mailgate($mail);
88 is ($status >> 8, 0, "The mail gateway exited normally");
89 ok ($id, "got id of a newly created ticket - $id");
91 my $tick = RT::Ticket->new( RT->SystemUser );
93 ok ($tick->id, "loaded ticket #$id");
96 "RT mail sent back into RT",
100 my $txn = $tick->Transactions->First;
101 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
103 is( $msg->GetHeader('X-RT-Privacy'),
105 "RT's outgoing mail has crypto"
107 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
109 "RT's outgoing mail looks encrypted"
112 like($attachments[0]->Content, qr/Some content/, "RT's mail includes copy of ticket text");
113 like($attachments[0]->Content, qr/$RT::rtname/, "RT's mail includes this instance's name");
116 $m->get("$baseurl/Admin/Queues/Modify.html?id=$qid");
117 $m->form_with_fields('Sign', 'Encrypt');
118 $m->field(Encrypt => undef);
119 $m->field(Sign => 1);
122 RT::Test->clean_caught_mails;
124 $m->goto_create_ticket( $queue );
125 $m->form_name('TicketCreate');
126 $m->field('Requestors', 'recipient@example.com');
127 $m->field('Subject', 'Signing test');
128 $m->field('Content', 'Some other content');
129 ok(!$m->value('Encrypt', 2), "encrypt tick box is unchecked");
130 ok($m->value('Sign', 2), "sign tick box is checked");
132 is($m->status, 200, "request successful");
134 $m->get($baseurl); # ensure that the mail has been processed
136 @mail = RT::Test->fetch_caught_mails;
137 ok(@mail, "got some mail");
138 for my $mail (@mail) {
139 like $mail, qr/Some other content/, "outgoing mail was not encrypted";
140 like $mail, qr/-----BEGIN PGP SIGNATURE-----[\s\S]+-----END PGP SIGNATURE-----/, "data has some kind of signature";
142 my ($content_type, $mime_version) = get_headers($mail, "Content-Type", "MIME-Version");
143 my $body = strip_headers($mail);
146 Subject: More RT mail sent back into RT
147 From: general\@example.com
148 To: recipient\@example.com
155 my ($status, $id) = RT::Test->send_via_mailgate($mail);
156 is ($status >> 8, 0, "The mail gateway exited normally");
157 ok ($id, "got id of a newly created ticket - $id");
159 my $tick = RT::Ticket->new( RT->SystemUser );
161 ok ($tick->id, "loaded ticket #$id");
164 "More RT mail sent back into RT",
168 my $txn = $tick->Transactions->First;
169 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
171 is( $msg->GetHeader('X-RT-Privacy'),
173 "RT's outgoing mail has crypto"
175 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
177 "RT's outgoing mail looks unencrypted"
179 is( $msg->GetHeader('X-RT-Incoming-Signature'),
180 'general <general@example.com>',
181 "RT's outgoing mail looks signed"
184 like($attachments[0]->Content, qr/Some other content/, "RT's mail includes copy of ticket text");
185 like($attachments[0]->Content, qr/$RT::rtname/, "RT's mail includes this instance's name");
188 $m->get("$baseurl/Admin/Queues/Modify.html?id=$qid");
189 $m->form_with_fields('Sign', 'Encrypt');
190 $m->field(Encrypt => 1);
191 $m->field(Sign => 1);
194 RT::Test->clean_caught_mails;
197 $m->goto_create_ticket( $queue );
198 $m->form_name('TicketCreate');
199 $m->field('Requestors', 'recipient@example.com');
200 $m->field('Subject', 'Crypt+Sign test');
201 $m->field('Content', 'Some final? content');
202 ok($m->value('Encrypt', 2), "encrypt tick box is checked");
203 ok($m->value('Sign', 2), "sign tick box is checked");
205 is($m->status, 200, "request successful");
207 $m->get($baseurl); # ensure that the mail has been processed
209 @mail = RT::Test->fetch_caught_mails;
210 ok(@mail, "got some mail");
211 for my $mail (@mail) {
212 unlike $mail, qr/Some other content/, "outgoing mail was encrypted";
214 my ($content_type, $mime_version) = get_headers($mail, "Content-Type", "MIME-Version");
215 my $body = strip_headers($mail);
218 Subject: Final RT mail sent back into RT
219 From: general\@example.com
220 To: recipient\@example.com
227 my ($status, $id) = RT::Test->send_via_mailgate($mail);
228 is ($status >> 8, 0, "The mail gateway exited normally");
229 ok ($id, "got id of a newly created ticket - $id");
231 my $tick = RT::Ticket->new( RT->SystemUser );
233 ok ($tick->id, "loaded ticket #$id");
236 "Final RT mail sent back into RT",
240 my $txn = $tick->Transactions->First;
241 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
243 is( $msg->GetHeader('X-RT-Privacy'),
245 "RT's outgoing mail has crypto"
247 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
249 "RT's outgoing mail looks encrypted"
251 is( $msg->GetHeader('X-RT-Incoming-Signature'),
252 'general <general@example.com>',
253 "RT's outgoing mail looks signed"
256 like($attachments[0]->Content, qr/Some final\? content/, "RT's mail includes copy of ticket text");
257 like($attachments[0]->Content, qr/$RT::rtname/, "RT's mail includes this instance's name");
260 RT::Test->clean_caught_mails;
262 $m->goto_create_ticket( $queue );
263 $m->form_name('TicketCreate');
264 $m->field('Requestors', 'recipient@example.com');
265 $m->field('Subject', 'Test crypt-off on encrypted queue');
266 $m->field('Content', 'Thought you had me figured out didya');
267 $m->field(Encrypt => undef, 2); # turn off encryption
268 ok(!$m->value('Encrypt', 2), "encrypt tick box is now unchecked");
269 ok($m->value('Sign', 2), "sign tick box is still checked");
271 is($m->status, 200, "request successful");
273 $m->get($baseurl); # ensure that the mail has been processed
275 @mail = RT::Test->fetch_caught_mails;
276 ok(@mail, "got some mail");
277 for my $mail (@mail) {
278 like $mail, qr/Thought you had me figured out didya/, "outgoing mail was unencrypted";
280 my ($content_type, $mime_version) = get_headers($mail, "Content-Type", "MIME-Version");
281 my $body = strip_headers($mail);
284 Subject: Post-final! RT mail sent back into RT
285 From: general\@example.com
286 To: recipient\@example.com
293 my ($status, $id) = RT::Test->send_via_mailgate($mail);
294 is ($status >> 8, 0, "The mail gateway exited normally");
295 ok ($id, "got id of a newly created ticket - $id");
297 my $tick = RT::Ticket->new( RT->SystemUser );
299 ok ($tick->id, "loaded ticket #$id");
302 "Post-final! RT mail sent back into RT",
306 my $txn = $tick->Transactions->First;
307 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
309 is( $msg->GetHeader('X-RT-Privacy'),
311 "RT's outgoing mail has crypto"
313 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
315 "RT's outgoing mail looks unencrypted"
317 is( $msg->GetHeader('X-RT-Incoming-Signature'),
318 'general <general@example.com>',
319 "RT's outgoing mail looks signed"
322 like($attachments[0]->Content, qr/Thought you had me figured out didya/, "RT's mail includes copy of ticket text");
323 like($attachments[0]->Content, qr/$RT::rtname/, "RT's mail includes this instance's name");
328 open my $fh, "<", \$mail or die $!;
329 my $head = MIME::Head->read($fh);
332 my $hdr = "$_: " . $head->get($_);
343 $mail =~ s/.*?\n\n//s;
347 # now test the OwnerNameKey and RequestorsKey fields
349 my $nokey = RT::Test->load_or_create_user(Name => 'nokey', EmailAddress => 'nokey@example.com');
350 $nokey->PrincipalObj->GrantRight(Right => 'CreateTicket');
351 $nokey->PrincipalObj->GrantRight(Right => 'OwnTicket');
353 my $tick = RT::Ticket->new( RT->SystemUser );
355 $tick->Create(Subject => 'owner lacks pubkey', Queue => 'general',
358 qr/nokey\@example.com: skipped: public key not found/,
359 qr/Recipient 'nokey\@example.com' is unusable/,
361 ok(my $id = $tick->id, 'created ticket for owner-without-pubkey');
363 $tick = RT::Ticket->new( RT->SystemUser );
364 $tick->Create(Subject => 'owner has pubkey', Queue => 'general',
366 ok($id = $tick->id, 'created ticket for owner-with-pubkey');
368 my $mail = << "MAIL";
369 Subject: Nokey requestor
370 From: nokey\@example.com
371 To: general\@example.com
378 ($status, $id) = RT::Test->send_via_mailgate($mail);
380 qr/nokey\@example.com: skipped: public key not found/,
381 qr/Recipient 'nokey\@example.com' is unusable/,
384 is ($status >> 8, 0, "The mail gateway exited normally");
385 ok ($id, "got id of a newly created ticket - $id");
387 $tick = RT::Ticket->new( RT->SystemUser );
389 ok ($tick->id, "loaded ticket #$id");
397 my $key1 = "EC1E81E7DC3DB42788FB0E4E9FA662C06DE22FC2";
398 my $key2 = "75E156271DCCF02DDD4A7A8CDF651FA0632C4F50";
400 ok($user = RT::User->new(RT->SystemUser));
401 ok($user->Load('root'), "Loaded user 'root'");
402 is($user->PreferredKey, $key1, "preferred key is set correctly");
403 $m->get("$baseurl/Prefs/Other.html");
404 like($m->content, qr/Preferred key/, "preferred key option shows up in preference");
406 # XXX: mech doesn't let us see the current value of the select, apparently
407 like($m->content, qr/$key1/, "first key shows up in preferences");
408 like($m->content, qr/$key2/, "second key shows up in preferences");
409 like($m->content, qr/$key1.*?$key2/s, "first key shows up before the second");
411 $m->form_name('ModifyPreferences');
412 $m->select("PreferredKey" => $key2);
415 ok($user = RT::User->new(RT->SystemUser));
416 ok($user->Load('root'), "Loaded user 'root'");
417 is($user->PreferredKey, $key2, "preferred key is set correctly to the new value");
419 $m->get("$baseurl/Prefs/Other.html");
420 like($m->content, qr/Preferred key/, "preferred key option shows up in preference");
422 # XXX: mech doesn't let us see the current value of the select, apparently
423 like($m->content, qr/$key2/, "second key shows up in preferences");
424 like($m->content, qr/$key1/, "first key shows up in preferences");
425 like($m->content, qr/$key2.*?$key1/s, "second key (now preferred) shows up before the first");
429 # test that the new fields work
430 $m->get("$baseurl/Search/Simple.html?q=General");
431 my $content = $m->content;
432 $content =~ s/(/(/g;
433 $content =~ s/)/)/g;
434 $content =~ s/<(a|span)\b[^>]+>//g;
435 $content =~ s/<\/(a|span)>//g;
436 $content =~ s/</</g;
437 $content =~ s/>/>/g;
439 like($content, qr/OO-Nobody in particular-O/,
440 "original Owner untouched");
441 like($content, qr/OO-nokey-O/,
442 "original Owner untouched");
443 like($content, qr/OO-root \(Enoch Root\)-O/,
444 "original Owner untouched");
445 like($content, qr/OR-<recipient\@example\.com>-O/,
446 "original Requestors untouched");
447 like($content, qr/OR-nokey-O/,
448 "original Requestors untouched");
450 like($content, qr/KO-Nobody in particular \(no pubkey!\)-K/,
451 "KeyOwner issues no-pubkey warning for nobody");
452 like($content, qr/KO-nokey \(no pubkey!\)-K/,
453 "KeyOwner issues no-pubkey warning for root");
454 like($content, qr/KO-root \(Enoch Root\)-K/,
455 "KeyOwner does not issue no-pubkey warning for recipient");
456 like($content, qr/KR-<recipient\@example\.com>-K/,
457 "KeyRequestors does not issue no-pubkey warning for recipient\@example.com");
458 like($content, qr/KR-nokey \(no pubkey!\)-K/,
459 "KeyRequestors DOES issue no-pubkey warning for nokey\@example.com");
461 $m->next_warning_like(qr/public key not found/);
462 $m->next_warning_like(qr/public key not found/);
463 $m->no_leftover_warnings_ok;