7 passphrase => 'recipient',
8 'trust-model' => 'always',
12 use RT::Action::SendEmail;
14 RT->Config->Set( CommentAddress => 'general@example.com');
15 RT->Config->Set( CorrespondAddress => 'general@example.com');
16 RT->Config->Set( DefaultSearchResultFormat => qq{
17 '<B><A HREF="__WebPath__/Ticket/Display.html?id=__id__">__id__</a></B>/TITLE:#',
18 '<B><A HREF="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a></B>/TITLE:Subject',
20 'OR-__Requestors__-O',
21 'KO-__KeyOwnerName__-K',
22 'KR-__KeyRequestors__-K',
26 RT::Test->import_gnupg_key('recipient@example.com', 'public');
27 RT::Test->import_gnupg_key('recipient@example.com', 'secret');
28 RT::Test->import_gnupg_key('general@example.com', 'public');
29 RT::Test->import_gnupg_key('general@example.com', 'secret');
30 RT::Test->import_gnupg_key('general@example.com.2', 'public');
31 RT::Test->import_gnupg_key('general@example.com.2', 'secret');
33 ok(my $user = RT::User->new(RT->SystemUser));
34 ok($user->Load('root'), "Loaded user 'root'");
35 $user->SetEmailAddress('recipient@example.com');
37 my $queue = RT::Test->load_or_create_queue(
39 CorrespondAddress => 'general@example.com',
41 ok $queue && $queue->id, 'loaded or created queue';
44 my ($baseurl, $m) = RT::Test->started_ok;
45 ok $m->login, 'logged in';
47 $m->get_ok("/Admin/Queues/Modify.html?id=$qid");
48 $m->form_with_fields('Sign', 'Encrypt');
49 $m->field(Encrypt => 1);
52 RT::Test->clean_caught_mails;
54 $m->goto_create_ticket( $queue );
55 $m->form_name('TicketCreate');
56 $m->field('Subject', 'Encryption test');
57 $m->field('Content', 'Some content');
58 ok($m->value('Encrypt', 2), "encrypt tick box is checked");
59 ok(!$m->value('Sign', 2), "sign tick box is unchecked");
61 is($m->status, 200, "request successful");
63 $m->get($baseurl); # ensure that the mail has been processed
65 my @mail = RT::Test->fetch_caught_mails;
66 ok(@mail, "got some mail");
68 $user->SetEmailAddress('general@example.com');
69 for my $mail (@mail) {
70 unlike $mail, qr/Some content/, "outgoing mail was encrypted";
72 my ($content_type) = $mail =~ /^(Content-Type: .*)/m;
73 my ($mime_version) = $mail =~ /^(MIME-Version: .*)/m;
74 my $body = strip_headers($mail);
77 Subject: RT mail sent back into RT
78 From: general\@example.com
79 To: recipient\@example.com
86 my ($status, $id) = RT::Test->send_via_mailgate($mail);
87 is ($status >> 8, 0, "The mail gateway exited normally");
88 ok ($id, "got id of a newly created ticket - $id");
90 my $tick = RT::Ticket->new( RT->SystemUser );
92 ok ($tick->id, "loaded ticket #$id");
95 "RT mail sent back into RT",
99 my $txn = $tick->Transactions->First;
100 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
102 is( $msg->GetHeader('X-RT-Privacy'),
104 "RT's outgoing mail has crypto"
106 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
108 "RT's outgoing mail looks encrypted"
111 like($attachments[0]->Content, qr/Some content/, "RT's mail includes copy of ticket text");
112 like($attachments[0]->Content, qr/$RT::rtname/, "RT's mail includes this instance's name");
115 $m->get("$baseurl/Admin/Queues/Modify.html?id=$qid");
116 $m->form_with_fields('Sign', 'Encrypt');
117 $m->field(Encrypt => undef);
118 $m->field(Sign => 1);
121 RT::Test->clean_caught_mails;
123 $m->goto_create_ticket( $queue );
124 $m->form_name('TicketCreate');
125 $m->field('Subject', 'Signing test');
126 $m->field('Content', 'Some other content');
127 ok(!$m->value('Encrypt', 2), "encrypt tick box is unchecked");
128 ok($m->value('Sign', 2), "sign tick box is checked");
130 is($m->status, 200, "request successful");
132 $m->get($baseurl); # ensure that the mail has been processed
134 @mail = RT::Test->fetch_caught_mails;
135 ok(@mail, "got some mail");
136 for my $mail (@mail) {
137 like $mail, qr/Some other content/, "outgoing mail was not encrypted";
138 like $mail, qr/-----BEGIN PGP SIGNATURE-----[\s\S]+-----END PGP SIGNATURE-----/, "data has some kind of signature";
140 my ($content_type) = $mail =~ /^(Content-Type: .*)/m;
141 my ($mime_version) = $mail =~ /^(MIME-Version: .*)/m;
142 my $body = strip_headers($mail);
145 Subject: More RT mail sent back into RT
146 From: general\@example.com
147 To: recipient\@example.com
154 my ($status, $id) = RT::Test->send_via_mailgate($mail);
155 is ($status >> 8, 0, "The mail gateway exited normally");
156 ok ($id, "got id of a newly created ticket - $id");
158 my $tick = RT::Ticket->new( RT->SystemUser );
160 ok ($tick->id, "loaded ticket #$id");
163 "More RT mail sent back into RT",
167 my $txn = $tick->Transactions->First;
168 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
170 is( $msg->GetHeader('X-RT-Privacy'),
172 "RT's outgoing mail has crypto"
174 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
176 "RT's outgoing mail looks unencrypted"
178 is( $msg->GetHeader('X-RT-Incoming-Signature'),
179 'general <general@example.com>',
180 "RT's outgoing mail looks signed"
183 like($attachments[0]->Content, qr/Some other content/, "RT's mail includes copy of ticket text");
184 like($attachments[0]->Content, qr/$RT::rtname/, "RT's mail includes this instance's name");
187 $m->get("$baseurl/Admin/Queues/Modify.html?id=$qid");
188 $m->form_with_fields('Sign', 'Encrypt');
189 $m->field(Encrypt => 1);
190 $m->field(Sign => 1);
193 RT::Test->clean_caught_mails;
196 $m->goto_create_ticket( $queue );
197 $m->form_name('TicketCreate');
198 $m->field('Subject', 'Crypt+Sign test');
199 $m->field('Content', 'Some final? content');
200 ok($m->value('Encrypt', 2), "encrypt tick box is checked");
201 ok($m->value('Sign', 2), "sign tick box is checked");
203 is($m->status, 200, "request successful");
205 $m->get($baseurl); # ensure that the mail has been processed
207 @mail = RT::Test->fetch_caught_mails;
208 ok(@mail, "got some mail");
209 for my $mail (@mail) {
210 unlike $mail, qr/Some other content/, "outgoing mail was encrypted";
212 my ($content_type) = $mail =~ /^(Content-Type: .*)/m;
213 my ($mime_version) = $mail =~ /^(MIME-Version: .*)/m;
214 my $body = strip_headers($mail);
217 Subject: Final RT mail sent back into RT
218 From: general\@example.com
219 To: recipient\@example.com
226 my ($status, $id) = RT::Test->send_via_mailgate($mail);
227 is ($status >> 8, 0, "The mail gateway exited normally");
228 ok ($id, "got id of a newly created ticket - $id");
230 my $tick = RT::Ticket->new( RT->SystemUser );
232 ok ($tick->id, "loaded ticket #$id");
235 "Final RT mail sent back into RT",
239 my $txn = $tick->Transactions->First;
240 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
242 is( $msg->GetHeader('X-RT-Privacy'),
244 "RT's outgoing mail has crypto"
246 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
248 "RT's outgoing mail looks encrypted"
250 is( $msg->GetHeader('X-RT-Incoming-Signature'),
251 'general <general@example.com>',
252 "RT's outgoing mail looks signed"
255 like($attachments[0]->Content, qr/Some final\? content/, "RT's mail includes copy of ticket text");
256 like($attachments[0]->Content, qr/$RT::rtname/, "RT's mail includes this instance's name");
259 RT::Test->clean_caught_mails;
261 $m->goto_create_ticket( $queue );
262 $m->form_name('TicketCreate');
263 $m->field('Subject', 'Test crypt-off on encrypted queue');
264 $m->field('Content', 'Thought you had me figured out didya');
265 $m->field(Encrypt => undef, 2); # turn off encryption
266 ok(!$m->value('Encrypt', 2), "encrypt tick box is now unchecked");
267 ok($m->value('Sign', 2), "sign tick box is still checked");
269 is($m->status, 200, "request successful");
271 $m->get($baseurl); # ensure that the mail has been processed
273 @mail = RT::Test->fetch_caught_mails;
274 ok(@mail, "got some mail");
275 for my $mail (@mail) {
276 like $mail, qr/Thought you had me figured out didya/, "outgoing mail was unencrypted";
278 my ($content_type) = $mail =~ /^(Content-Type: .*)/m;
279 my ($mime_version) = $mail =~ /^(MIME-Version: .*)/m;
280 my $body = strip_headers($mail);
283 Subject: Post-final! RT mail sent back into RT
284 From: general\@example.com
285 To: recipient\@example.com
292 my ($status, $id) = RT::Test->send_via_mailgate($mail);
293 is ($status >> 8, 0, "The mail gateway exited normally");
294 ok ($id, "got id of a newly created ticket - $id");
296 my $tick = RT::Ticket->new( RT->SystemUser );
298 ok ($tick->id, "loaded ticket #$id");
301 "Post-final! RT mail sent back into RT",
305 my $txn = $tick->Transactions->First;
306 my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
308 is( $msg->GetHeader('X-RT-Privacy'),
310 "RT's outgoing mail has crypto"
312 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
314 "RT's outgoing mail looks unencrypted"
316 is( $msg->GetHeader('X-RT-Incoming-Signature'),
317 'general <general@example.com>',
318 "RT's outgoing mail looks signed"
321 like($attachments[0]->Content, qr/Thought you had me figured out didya/, "RT's mail includes copy of ticket text");
322 like($attachments[0]->Content, qr/$RT::rtname/, "RT's mail includes this instance's name");
328 $mail =~ s/.*?\n\n//s;
332 # now test the OwnerNameKey and RequestorsKey fields
334 my $nokey = RT::Test->load_or_create_user(Name => 'nokey', EmailAddress => 'nokey@example.com');
335 $nokey->PrincipalObj->GrantRight(Right => 'CreateTicket');
336 $nokey->PrincipalObj->GrantRight(Right => 'OwnTicket');
338 my $tick = RT::Ticket->new( RT->SystemUser );
339 $tick->Create(Subject => 'owner lacks pubkey', Queue => 'general',
341 ok(my $id = $tick->id, 'created ticket for owner-without-pubkey');
343 $tick = RT::Ticket->new( RT->SystemUser );
344 $tick->Create(Subject => 'owner has pubkey', Queue => 'general',
346 ok($id = $tick->id, 'created ticket for owner-with-pubkey');
348 my $mail = << "MAIL";
349 Subject: Nokey requestor
350 From: nokey\@example.com
351 To: general\@example.com
358 ($status, $id) = RT::Test->send_via_mailgate($mail);
360 qr/nokey\@example.com: skipped: public key not found/,
361 qr/Recipient 'nokey\@example.com' is unusable/,
364 is ($status >> 8, 0, "The mail gateway exited normally");
365 ok ($id, "got id of a newly created ticket - $id");
367 $tick = RT::Ticket->new( RT->SystemUser );
369 ok ($tick->id, "loaded ticket #$id");
377 my $key1 = "EC1E81E7DC3DB42788FB0E4E9FA662C06DE22FC2";
378 my $key2 = "75E156271DCCF02DDD4A7A8CDF651FA0632C4F50";
380 ok($user = RT::User->new(RT->SystemUser));
381 ok($user->Load('root'), "Loaded user 'root'");
382 is($user->PreferredKey, $key1, "preferred key is set correctly");
383 $m->get("$baseurl/Prefs/Other.html");
384 like($m->content, qr/Preferred key/, "preferred key option shows up in preference");
386 # XXX: mech doesn't let us see the current value of the select, apparently
387 like($m->content, qr/$key1/, "first key shows up in preferences");
388 like($m->content, qr/$key2/, "second key shows up in preferences");
389 like($m->content, qr/$key1.*?$key2/s, "first key shows up before the second");
391 $m->form_name('ModifyPreferences');
392 $m->select("PreferredKey" => $key2);
395 ok($user = RT::User->new(RT->SystemUser));
396 ok($user->Load('root'), "Loaded user 'root'");
397 is($user->PreferredKey, $key2, "preferred key is set correctly to the new value");
399 $m->get("$baseurl/Prefs/Other.html");
400 like($m->content, qr/Preferred key/, "preferred key option shows up in preference");
402 # XXX: mech doesn't let us see the current value of the select, apparently
403 like($m->content, qr/$key2/, "second key shows up in preferences");
404 like($m->content, qr/$key1/, "first key shows up in preferences");
405 like($m->content, qr/$key2.*?$key1/s, "second key (now preferred) shows up before the first");
409 # test that the new fields work
410 $m->get("$baseurl/Search/Simple.html?q=General");
411 my $content = $m->content;
412 $content =~ s/(/(/g;
413 $content =~ s/)/)/g;
415 like($content, qr/OO-Nobody-O/, "original OwnerName untouched");
416 like($content, qr/OO-nokey-O/, "original OwnerName untouched");
417 like($content, qr/OO-root-O/, "original OwnerName untouched");
419 like($content, qr/OR-recipient\@example.com-O/, "original Requestors untouched");
420 like($content, qr/OR-nokey\@example.com-O/, "original Requestors untouched");
422 like($content, qr/KO-root-K/, "KeyOwnerName does not issue no-pubkey warning for recipient");
423 like($content, qr/KO-nokey \(no pubkey!\)-K/, "KeyOwnerName issues no-pubkey warning for root");
424 like($content, qr/KO-Nobody \(no pubkey!\)-K/, "KeyOwnerName issues no-pubkey warning for nobody");
426 like($content, qr/KR-recipient\@example.com-K/, "KeyRequestors does not issue no-pubkey warning for recipient\@example.com");
428 like($content, qr/KR-general\@example.com-K/, "KeyRequestors does not issue no-pubkey warning for general\@example.com");
429 like($content, qr/KR-nokey\@example.com \(no pubkey!\)-K/, "KeyRequestors DOES issue no-pubkey warning for nokey\@example.com");
431 $m->next_warning_like(qr/public key not found/);
432 $m->next_warning_like(qr/public key not found/);
433 $m->no_leftover_warnings_ok;