4 use RT::Test::GnuPG tests => 88, gnupg_options => { passphrase => 'rt-test' };
6 use RT::Action::SendEmail;
8 my $queue = RT::Test->load_or_create_queue(
10 CorrespondAddress => 'rt-recipient@example.com',
11 CommentAddress => 'rt-recipient@example.com',
13 ok $queue && $queue->id, 'loaded or created queue';
15 my ($baseurl, $m) = RT::Test->started_ok;
16 ok $m->login, 'logged in';
21 my $ticket = RT::Ticket->new( RT->SystemUser );
22 ($tid) = $ticket->Create(
26 ok $tid, 'ticket created';
29 diag "check that signing doesn't work if there is no key";
31 RT::Test->clean_caught_mails;
33 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
34 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
35 $m->form_name('TicketUpdate');
36 $m->tick( Sign => 1 );
37 $m->field( UpdateCc => 'rt-test@example.com' );
38 $m->field( UpdateContent => 'Some content' );
39 $m->click('SubmitTicket');
41 'unable to sign outgoing email messages',
42 'problems with passphrase'
45 my @mail = RT::Test->fetch_caught_mails;
46 ok !@mail, 'there are no outgoing emails';
48 $m->next_warning_like(qr/secret key not available/);
49 $m->no_leftover_warnings_ok;
53 RT::Test->import_gnupg_key('rt-recipient@example.com');
54 RT::Test->trust_gnupg_key('rt-recipient@example.com');
55 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-recipient@example.com');
56 is $res{'info'}[0]{'TrustTerse'}, 'ultimate', 'ultimately trusted key';
59 diag "check that things don't work if there is no key";
61 RT::Test->clean_caught_mails;
63 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
64 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
65 $m->form_name('TicketUpdate');
66 $m->tick( Encrypt => 1 );
67 $m->field( UpdateCc => 'rt-test@example.com' );
68 $m->field( UpdateContent => 'Some content' );
69 $m->click('SubmitTicket');
71 'You are going to encrypt outgoing email messages',
75 'There is no key suitable for encryption',
79 my $form = $m->form_name('TicketUpdate');
80 ok !$form->find_input( 'UseKey-rt-test@example.com' ), 'no key selector';
82 my @mail = RT::Test->fetch_caught_mails;
83 ok !@mail, 'there are no outgoing emails';
86 $m->next_warning_like(qr/public key not found/);
87 $m->next_warning_like(qr/above error may result from an unconfigured RT\/GPG/);
89 $m->no_leftover_warnings_ok;
93 diag "import first key of rt-test\@example.com";
96 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
97 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
98 is $res{'info'}[0]{'TrustLevel'}, 0, 'is not trusted key';
99 $fpr1 = $res{'info'}[0]{'Fingerprint'};
102 diag "check that things still doesn't work if key is not trusted";
104 RT::Test->clean_caught_mails;
106 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
107 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
108 $m->form_name('TicketUpdate');
109 $m->tick( Encrypt => 1 );
110 $m->field( UpdateCc => 'rt-test@example.com' );
111 $m->field( UpdateContent => 'Some content' );
112 $m->click('SubmitTicket');
113 $m->content_contains(
114 'You are going to encrypt outgoing email messages',
117 $m->content_contains(
118 'There is one suitable key, but trust level is not set',
122 my $form = $m->form_name('TicketUpdate');
123 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
124 is scalar $input->possible_values, 1, 'one option';
126 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
127 $m->click('SubmitTicket');
128 $m->content_contains(
129 'You are going to encrypt outgoing email messages',
132 $m->content_contains(
133 'Selected key either is not trusted',
137 my @mail = RT::Test->fetch_caught_mails;
138 ok !@mail, 'there are no outgoing emails';
143 diag "import a second key of rt-test\@example.com";
146 RT::Test->import_gnupg_key('rt-test@example.com.2', 'public');
147 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
148 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
149 $fpr2 = $res{'info'}[2]{'Fingerprint'};
152 diag "check that things still doesn't work if two keys are not trusted";
154 RT::Test->clean_caught_mails;
156 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
157 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
158 $m->form_name('TicketUpdate');
159 $m->tick( Encrypt => 1 );
160 $m->field( UpdateCc => 'rt-test@example.com' );
161 $m->field( UpdateContent => 'Some content' );
162 $m->click('SubmitTicket');
163 $m->content_contains(
164 'You are going to encrypt outgoing email messages',
167 $m->content_contains(
168 'There are several keys suitable for encryption',
172 my $form = $m->form_name('TicketUpdate');
173 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
174 is scalar $input->possible_values, 2, 'two options';
176 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
177 $m->click('SubmitTicket');
178 $m->content_contains(
179 'You are going to encrypt outgoing email messages',
182 $m->content_contains(
183 'Selected key either is not trusted',
187 my @mail = RT::Test->fetch_caught_mails;
188 ok !@mail, 'there are no outgoing emails';
194 RT::Test->lsign_gnupg_key( $fpr1 );
195 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
196 ok $res{'info'}[0]{'TrustLevel'} > 0, 'trusted key';
197 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
200 diag "check that we see key selector even if only one key is trusted but there are more keys";
202 RT::Test->clean_caught_mails;
204 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
205 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
206 $m->form_name('TicketUpdate');
207 $m->tick( Encrypt => 1 );
208 $m->field( UpdateCc => 'rt-test@example.com' );
209 $m->field( UpdateContent => 'Some content' );
210 $m->click('SubmitTicket');
211 $m->content_contains(
212 'You are going to encrypt outgoing email messages',
215 $m->content_contains(
216 'There are several keys suitable for encryption',
220 my $form = $m->form_name('TicketUpdate');
221 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
222 is scalar $input->possible_values, 2, 'two options';
224 my @mail = RT::Test->fetch_caught_mails;
225 ok !@mail, 'there are no outgoing emails';
230 diag "check that key selector works and we can select trusted key";
232 RT::Test->clean_caught_mails;
234 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
235 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
236 $m->form_name('TicketUpdate');
237 $m->tick( Encrypt => 1 );
238 $m->field( UpdateCc => 'rt-test@example.com' );
239 $m->field( UpdateContent => 'Some content' );
240 $m->click('SubmitTicket');
241 $m->content_contains(
242 'You are going to encrypt outgoing email messages',
245 $m->content_contains(
246 'There are several keys suitable for encryption',
250 my $form = $m->form_name('TicketUpdate');
251 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
252 is scalar $input->possible_values, 2, 'two options';
254 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
255 $m->click('SubmitTicket');
256 $m->content_contains('Message recorded', 'Message recorded' );
258 my @mail = RT::Test->fetch_caught_mails;
259 ok @mail, 'there are some emails';
260 check_text_emails( { Encrypt => 1 }, @mail );
265 diag "check encrypting of attachments";
267 RT::Test->clean_caught_mails;
269 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
270 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
271 $m->form_name('TicketUpdate');
272 $m->tick( Encrypt => 1 );
273 $m->field( UpdateCc => 'rt-test@example.com' );
274 $m->field( UpdateContent => 'Some content' );
275 $m->field( Attach => $0 );
276 $m->click('SubmitTicket');
277 $m->content_contains(
278 'You are going to encrypt outgoing email messages',
281 $m->content_contains(
282 'There are several keys suitable for encryption',
286 my $form = $m->form_name('TicketUpdate');
287 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
288 is scalar $input->possible_values, 2, 'two options';
290 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
291 $m->click('SubmitTicket');
292 $m->content_contains('Message recorded', 'Message recorded' );
294 my @mail = RT::Test->fetch_caught_mails;
295 ok @mail, 'there are some emails';
296 check_text_emails( { Encrypt => 1, Attachment => 1 }, @mail );