X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Ft%2Fmail%2Fgnupg-reverification.t;fp=rt%2Ft%2Fmail%2Fgnupg-reverification.t;h=96a37a080a212c9423910e30255d901c7d1100e9;hb=33beebf4cb42eba3e1dd868ad5e0af102de961da;hp=f116d93800ac733bfc6e01aa714208c6bcf81fea;hpb=7ac86daf67b0a95153b736d5811f9050363f6553;p=freeside.git diff --git a/rt/t/mail/gnupg-reverification.t b/rt/t/mail/gnupg-reverification.t index f116d9380..96a37a080 100644 --- a/rt/t/mail/gnupg-reverification.t +++ b/rt/t/mail/gnupg-reverification.t @@ -2,43 +2,16 @@ use strict; use warnings; -use RT::Test tests => 120; +use RT::Test::GnuPG tests => 216, gnupg_options => { passphrase => 'rt-test' }; -plan skip_all => 'GnuPG required.' - unless eval 'use GnuPG::Interface; 1'; -plan skip_all => 'gpg executable is required.' - unless RT::Test->find_executable('gpg'); - - -use File::Temp qw(tempdir); -my $homedir = tempdir( CLEANUP => 1 ); - -RT->Config->Set( 'GnuPG', - Enable => 1, - OutgoingMessagesFormat => 'RFC' ); - -RT->Config->Set( 'GnuPGOptions', - homedir => $homedir, - passphrase => 'rt-test', - 'no-permission-warning' => undef); - -RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::GnuPG' ); - - -diag "load Everyone group" if $ENV{'TEST_VERBOSE'}; +diag "load Everyone group"; my $everyone; { - $everyone = RT::Group->new( $RT::SystemUser ); + $everyone = RT::Group->new( RT->SystemUser ); $everyone->LoadSystemInternalGroup('Everyone'); ok $everyone->id, "loaded 'everyone' group"; } -RT::Test->set_rights( - Principal => $everyone, - Right => ['CreateTicket'], -); - - my ($baseurl, $m) = RT::Test->started_ok; ok $m->login, 'we get log in'; @@ -50,7 +23,7 @@ my $emaildatadir = RT::Test::get_relocatable_dir(File::Spec->updir(), qw(data gnupg emails)); my @files = glob("$emaildatadir/*-signed-*"); foreach my $file ( @files ) { - diag "testing $file" if $ENV{'TEST_VERBOSE'}; + diag "testing $file"; my ($eid) = ($file =~ m{(\d+)[^/\\]+$}); ok $eid, 'figured id of a file'; @@ -58,35 +31,61 @@ foreach my $file ( @files ) { my $email_content = RT::Test->file_content( $file ); ok $email_content, "$eid: got content of email"; - my ($status, $id) = RT::Test->send_via_mailgate( $email_content ); + my $warnings; + my ($status, $id); + + { + # We don't use Test::Warn here because we get multi-line + # warnings, which Test::Warn only records the first line of. + local $SIG{__WARN__} = sub { + $warnings .= "@_"; + }; + + ($status, $id) = RT::Test->send_via_mailgate( $email_content ); + } + is $status >> 8, 0, "$eid: the mail gateway exited normally"; ok $id, "$eid: got id of a newly created ticket - $id"; - my $ticket = RT::Ticket->new( $RT::SystemUser ); + like($warnings, qr/Had a problem during decrypting and verifying/); + like($warnings, qr/public key not found/); + + my $ticket = RT::Ticket->new( RT->SystemUser ); $ticket->Load( $id ); ok $ticket->id, "$eid: loaded ticket #$id"; is $ticket->Subject, "Test Email ID:$eid", "$eid: correct subject"; $m->goto_ticket( $id ); - $m->content_like( - qr/Not possible to check the signature, the reason is missing public key/is, + $m->content_contains( + "Not possible to check the signature, the reason is missing public key", "$eid: signature is not verified", ); $m->content_like(qr/This is .*ID:$eid/ims, "$eid: content is there and message is decrypted"); + $m->next_warning_like(qr/public key not found/); + + # some mails contain multiple signatures + if ($eid == 5 || $eid == 17 || $eid == 18) { + $m->next_warning_like(qr/public key not found/); + } + + $m->no_leftover_warnings_ok; + push @ticket_ids, $id; } -diag "import key into keyring" if $ENV{'TEST_VERBOSE'}; +diag "import key into keyring"; RT::Test->import_gnupg_key('rt-test@example.com', 'public'); foreach my $id ( @ticket_ids ) { - diag "testing ticket #$id" if $ENV{'TEST_VERBOSE'}; + diag "testing ticket #$id"; $m->goto_ticket( $id ); - $m->content_like( - qr/The signature is good/is, + $m->content_contains( + "The signature is good", "signature is re-verified and now good", ); + + $m->no_warnings_ok; }