4 use RT::Test::GnuPG tests => undef, gnupg_options => { passphrase => 'rt-test' };
5 use RT::Action::SendEmail;
7 my $queue = RT::Test->load_or_create_queue(
9 CorrespondAddress => 'rt-recipient@example.com',
10 CommentAddress => 'rt-recipient@example.com',
12 ok $queue && $queue->id, 'loaded or created queue';
14 my ($baseurl, $m) = RT::Test->started_ok;
15 ok $m->login, 'logged in';
17 diag "check that signing doesn't work if there is no key";
19 RT::Test->clean_caught_mails;
21 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
22 $m->form_name('TicketCreate');
23 $m->tick( Sign => 1 );
24 $m->field( Requestors => 'rt-test@example.com' );
25 $m->field( Content => 'Some content' );
28 'unable to sign outgoing email messages',
29 'problems with passphrase'
31 $m->warning_like(qr/signing failed: secret key not available/);
33 my @mail = RT::Test->fetch_caught_mails;
34 ok !@mail, 'there are no outgoing emails';
38 RT::Test->import_gnupg_key('rt-recipient@example.com');
39 RT::Test->trust_gnupg_key('rt-recipient@example.com');
40 my %res = RT::Crypt->GetKeysInfo( Key => 'rt-recipient@example.com' );
41 is $res{'info'}[0]{'TrustTerse'}, 'ultimate', 'ultimately trusted key';
44 diag "check that things don't work if there is no key";
46 RT::Test->clean_caught_mails;
48 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
49 $m->form_name('TicketCreate');
50 $m->tick( Encrypt => 1 );
51 $m->field( Requestors => 'rt-test@example.com' );
52 $m->field( Content => 'Some content' );
55 'You are going to encrypt outgoing email messages',
59 'There is no key suitable for encryption',
63 my $form = $m->form_name('TicketCreate');
64 ok !$form->find_input( 'UseKey-rt-test@example.com' ), 'no key selector';
66 my @mail = RT::Test->fetch_caught_mails;
67 ok !@mail, 'there are no outgoing emails';
69 $m->next_warning_like(qr/public key not found/) for 1 .. 4;
70 $m->no_leftover_warnings_ok;
73 diag "import first key of rt-test\@example.com";
76 RT::Test->import_gnupg_key('rt-test@example.com', 'secret');
77 my %res = RT::Crypt->GetKeysInfo( Key => 'rt-test@example.com' );
78 is $res{'info'}[0]{'TrustLevel'}, 0, 'is not trusted key';
79 $fpr1 = $res{'info'}[0]{'Fingerprint'};
82 diag "check that things still doesn't work if key is not trusted";
84 RT::Test->clean_caught_mails;
86 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
87 $m->form_name('TicketCreate');
88 $m->tick( Encrypt => 1 );
89 $m->field( Requestors => 'rt-test@example.com' );
90 $m->field( Content => 'Some content' );
93 'You are going to encrypt outgoing email messages',
97 'There is one suitable key, but trust level is not set',
101 my $form = $m->form_name('TicketCreate');
102 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
103 is scalar $input->possible_values, 1, 'one option';
105 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
107 $m->content_contains(
108 'You are going to encrypt outgoing email messages',
111 $m->content_contains(
112 'Selected key either is not trusted',
116 my @mail = RT::Test->fetch_caught_mails;
117 ok !@mail, 'there are no outgoing emails';
122 diag "import a second key of rt-test\@example.com";
125 RT::Test->import_gnupg_key('rt-test@example.com.2', 'secret');
126 my %res = RT::Crypt->GetKeysInfo( Key => 'rt-test@example.com' );
127 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
128 $fpr2 = $res{'info'}[2]{'Fingerprint'};
131 diag "check that things still doesn't work if two keys are not trusted";
133 RT::Test->clean_caught_mails;
135 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
136 $m->form_name('TicketCreate');
137 $m->tick( Encrypt => 1 );
138 $m->field( Requestors => 'rt-test@example.com' );
139 $m->field( Content => 'Some content' );
141 $m->content_contains(
142 'You are going to encrypt outgoing email messages',
145 $m->content_contains(
146 'There are several keys suitable for encryption',
150 my $form = $m->form_name('TicketCreate');
151 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
152 is scalar $input->possible_values, 2, 'two options';
154 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
156 $m->content_contains(
157 'You are going to encrypt outgoing email messages',
160 $m->content_contains(
161 'Selected key either is not trusted',
165 my @mail = RT::Test->fetch_caught_mails;
166 ok !@mail, 'there are no outgoing emails';
172 RT::Test->lsign_gnupg_key( $fpr1 );
173 my %res = RT::Crypt->GetKeysInfo( Key => 'rt-test@example.com' );
174 ok $res{'info'}[0]{'TrustLevel'} > 0, 'trusted key';
175 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
178 diag "check that we see key selector even if only one key is trusted but there are more keys";
180 RT::Test->clean_caught_mails;
182 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
183 $m->form_name('TicketCreate');
184 $m->tick( Encrypt => 1 );
185 $m->field( Requestors => 'rt-test@example.com' );
186 $m->field( Content => 'Some content' );
188 $m->content_contains(
189 'You are going to encrypt outgoing email messages',
192 $m->content_contains(
193 'There are several keys suitable for encryption',
197 my $form = $m->form_name('TicketCreate');
198 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
199 is scalar $input->possible_values, 2, 'two options';
201 my @mail = RT::Test->fetch_caught_mails;
202 ok !@mail, 'there are no outgoing emails';
207 diag "check that key selector works and we can select trusted key";
209 RT::Test->clean_caught_mails;
211 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
212 $m->form_name('TicketCreate');
213 $m->tick( Encrypt => 1 );
214 $m->field( Requestors => 'rt-test@example.com' );
215 $m->field( Content => 'Some content' );
217 $m->content_contains(
218 'You are going to encrypt outgoing email messages',
221 $m->content_contains(
222 'There are several keys suitable for encryption',
226 my $form = $m->form_name('TicketCreate');
227 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
228 is scalar $input->possible_values, 2, 'two options';
230 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
232 $m->content_like( qr/Ticket \d+ created in queue/i, 'ticket created' );
234 my @mail = RT::Test->fetch_caught_mails;
235 ok @mail, 'there are some emails';
236 check_text_emails( { Encrypt => 1 }, @mail );
241 diag "check encrypting of attachments";
242 for my $encrypt (0, 1) {
243 RT::Test->clean_caught_mails;
245 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
246 $m->form_name('TicketCreate');
247 $m->tick( Encrypt => 1 ) if $encrypt;
248 $m->field( Requestors => '' );
249 $m->field( Cc => 'rt-test@example.com' );
250 $m->field( Content => 'Some content' );
251 $m->field( Attach => $0 );
255 $m->content_contains(
256 'You are going to encrypt outgoing email messages',
259 $m->content_contains(
260 'There are several keys suitable for encryption',
264 my $form = $m->form_name('TicketCreate');
265 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
266 is scalar $input->possible_values, 2, 'two options';
268 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
272 $m->content_like( qr/Ticket \d+ created in queue/i, 'ticket created' );
274 my @mail = RT::Test->fetch_caught_mails;
275 ok @mail, 'there are some emails';
276 check_text_emails( { Encrypt => $encrypt, Attachment => "Attachment content" }, @mail );