default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / rt / t / mail / gnupg-reverification.t
1 use strict;
2 use warnings;
3
4 use RT::Test::GnuPG tests => undef, gnupg_options => { passphrase => 'rt-test' };
5
6 diag "load Everyone group";
7 my $everyone;
8 {
9     $everyone = RT::Group->new( RT->SystemUser );
10     $everyone->LoadSystemInternalGroup('Everyone');
11     ok $everyone->id, "loaded 'everyone' group";
12 }
13
14 my ($baseurl, $m) = RT::Test->started_ok;
15 ok $m->login, 'we get log in';
16
17 RT::Test->import_gnupg_key('rt-recipient@example.com');
18
19 my @ticket_ids;
20
21 my $emaildatadir = RT::Test::get_relocatable_dir(File::Spec->updir(),
22     qw(data gnupg emails));
23 my @files = glob("$emaildatadir/*-signed-*");
24 foreach my $file ( @files ) {
25     diag "testing $file";
26
27     my ($eid) = ($file =~ m{(\d+)[^/\\]+$});
28     ok $eid, 'figured id of a file';
29
30     my $email_content = RT::Test->file_content( $file );
31     ok $email_content, "$eid: got content of email";
32
33     my $warnings;
34     my ($status, $id);
35
36     {
37         # We don't use Test::Warn here because we get multi-line
38         # warnings, which Test::Warn only records the first line of.
39         local $SIG{__WARN__} = sub {
40             $warnings .= "@_";
41         };
42
43         ($status, $id) = RT::Test->send_via_mailgate( $email_content );
44     }
45
46     is $status >> 8, 0, "$eid: the mail gateway exited normally";
47     ok $id, "$eid: got id of a newly created ticket - $id";
48
49     like($warnings, qr/Public key '0xD328035D84881F1B' is not available/);
50
51     my $ticket = RT::Ticket->new( RT->SystemUser );
52     $ticket->Load( $id );
53     ok $ticket->id, "$eid: loaded ticket #$id";
54     is $ticket->Subject, "Test Email ID:$eid", "$eid: correct subject";
55
56     $m->goto_ticket( $id );
57     $m->content_contains(
58         "Not possible to check the signature, the reason is missing public key",
59         "$eid: signature is not verified",
60     );
61     $m->content_like(qr/This is .*ID:$eid/ims, "$eid: content is there and message is decrypted");
62
63     $m->next_warning_like(qr/public key not found/);
64
65     # some mails contain multiple signatures
66     if ($eid == 5 || $eid == 17 || $eid == 18) {
67         $m->next_warning_like(qr/public key not found/);
68     }
69
70     $m->no_leftover_warnings_ok;
71
72     push @ticket_ids, $id;
73 }
74
75 diag "import key into keyring";
76 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
77
78 foreach my $id ( @ticket_ids ) {
79     diag "testing ticket #$id";
80
81     $m->goto_ticket( $id );
82     $m->content_contains(
83         "The signature is good",
84         "signature is re-verified and now good",
85     );
86
87     $m->no_warnings_ok;
88 }
89
90 undef $m;
91 done_testing;