5 use RT::Test::GnuPG tests => 86, gnupg_options => { passphrase => 'rt-test' };
7 use RT::Action::SendEmail;
9 my $queue = RT::Test->load_or_create_queue(
11 CorrespondAddress => 'rt-recipient@example.com',
12 CommentAddress => 'rt-recipient@example.com',
14 ok $queue && $queue->id, 'loaded or created queue';
16 my ($baseurl, $m) = RT::Test->started_ok;
17 ok $m->login, 'logged in';
22 my $ticket = RT::Ticket->new( RT->SystemUser );
23 ($tid) = $ticket->Create(
27 ok $tid, 'ticket created';
30 diag "check that signing doesn't work if there is no key";
32 RT::Test->clean_caught_mails;
34 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
35 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
36 $m->form_name('TicketUpdate');
37 $m->tick( Sign => 1 );
38 $m->field( UpdateCc => 'rt-test@example.com' );
39 $m->field( UpdateContent => 'Some content' );
40 $m->click('SubmitTicket');
42 'unable to sign outgoing email messages',
43 'problems with passphrase'
46 my @mail = RT::Test->fetch_caught_mails;
47 ok !@mail, 'there are no outgoing emails';
49 $m->next_warning_like(qr/secret key not available/);
50 $m->no_leftover_warnings_ok;
54 RT::Test->import_gnupg_key('rt-recipient@example.com');
55 RT::Test->trust_gnupg_key('rt-recipient@example.com');
56 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-recipient@example.com');
57 is $res{'info'}[0]{'TrustTerse'}, 'ultimate', 'ultimately trusted key';
60 diag "check that things don't work if there is no key";
62 RT::Test->clean_caught_mails;
64 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
65 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
66 $m->form_name('TicketUpdate');
67 $m->tick( Encrypt => 1 );
68 $m->field( UpdateCc => 'rt-test@example.com' );
69 $m->field( UpdateContent => 'Some content' );
70 $m->click('SubmitTicket');
72 'You are going to encrypt outgoing email messages',
76 'There is no key suitable for encryption',
80 my $form = $m->form_name('TicketUpdate');
81 ok !$form->find_input( 'UseKey-rt-test@example.com' ), 'no key selector';
83 my @mail = RT::Test->fetch_caught_mails;
84 ok !@mail, 'there are no outgoing emails';
86 $m->next_warning_like(qr/public key not found/) for 1 .. 2;
87 $m->no_leftover_warnings_ok;
91 diag "import first key of rt-test\@example.com";
94 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
95 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
96 is $res{'info'}[0]{'TrustLevel'}, 0, 'is not trusted key';
97 $fpr1 = $res{'info'}[0]{'Fingerprint'};
100 diag "check that things still doesn't work if key is not trusted";
102 RT::Test->clean_caught_mails;
104 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
105 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
106 $m->form_name('TicketUpdate');
107 $m->tick( Encrypt => 1 );
108 $m->field( UpdateCc => 'rt-test@example.com' );
109 $m->field( UpdateContent => 'Some content' );
110 $m->click('SubmitTicket');
111 $m->content_contains(
112 'You are going to encrypt outgoing email messages',
115 $m->content_contains(
116 'There is one suitable key, but trust level is not set',
120 my $form = $m->form_name('TicketUpdate');
121 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
122 is scalar $input->possible_values, 1, 'one option';
124 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
125 $m->click('SubmitTicket');
126 $m->content_contains(
127 'You are going to encrypt outgoing email messages',
130 $m->content_contains(
131 'Selected key either is not trusted',
135 my @mail = RT::Test->fetch_caught_mails;
136 ok !@mail, 'there are no outgoing emails';
141 diag "import a second key of rt-test\@example.com";
144 RT::Test->import_gnupg_key('rt-test@example.com.2', 'public');
145 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
146 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
147 $fpr2 = $res{'info'}[2]{'Fingerprint'};
150 diag "check that things still doesn't work if two keys are not trusted";
152 RT::Test->clean_caught_mails;
154 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
155 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
156 $m->form_name('TicketUpdate');
157 $m->tick( Encrypt => 1 );
158 $m->field( UpdateCc => 'rt-test@example.com' );
159 $m->field( UpdateContent => 'Some content' );
160 $m->click('SubmitTicket');
161 $m->content_contains(
162 'You are going to encrypt outgoing email messages',
165 $m->content_contains(
166 'There are several keys suitable for encryption',
170 my $form = $m->form_name('TicketUpdate');
171 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
172 is scalar $input->possible_values, 2, 'two options';
174 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
175 $m->click('SubmitTicket');
176 $m->content_contains(
177 'You are going to encrypt outgoing email messages',
180 $m->content_contains(
181 'Selected key either is not trusted',
185 my @mail = RT::Test->fetch_caught_mails;
186 ok !@mail, 'there are no outgoing emails';
192 RT::Test->lsign_gnupg_key( $fpr1 );
193 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
194 ok $res{'info'}[0]{'TrustLevel'} > 0, 'trusted key';
195 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
198 diag "check that we see key selector even if only one key is trusted but there are more keys";
200 RT::Test->clean_caught_mails;
202 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
203 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
204 $m->form_name('TicketUpdate');
205 $m->tick( Encrypt => 1 );
206 $m->field( UpdateCc => 'rt-test@example.com' );
207 $m->field( UpdateContent => 'Some content' );
208 $m->click('SubmitTicket');
209 $m->content_contains(
210 'You are going to encrypt outgoing email messages',
213 $m->content_contains(
214 'There are several keys suitable for encryption',
218 my $form = $m->form_name('TicketUpdate');
219 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
220 is scalar $input->possible_values, 2, 'two options';
222 my @mail = RT::Test->fetch_caught_mails;
223 ok !@mail, 'there are no outgoing emails';
228 diag "check that key selector works and we can select trusted key";
230 RT::Test->clean_caught_mails;
232 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
233 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
234 $m->form_name('TicketUpdate');
235 $m->tick( Encrypt => 1 );
236 $m->field( UpdateCc => 'rt-test@example.com' );
237 $m->field( UpdateContent => 'Some content' );
238 $m->click('SubmitTicket');
239 $m->content_contains(
240 'You are going to encrypt outgoing email messages',
243 $m->content_contains(
244 'There are several keys suitable for encryption',
248 my $form = $m->form_name('TicketUpdate');
249 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
250 is scalar $input->possible_values, 2, 'two options';
252 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
253 $m->click('SubmitTicket');
254 $m->content_contains('Message recorded', 'Message recorded' );
256 my @mail = RT::Test->fetch_caught_mails;
257 ok @mail, 'there are some emails';
258 check_text_emails( { Encrypt => 1 }, @mail );
263 diag "check encrypting of attachments";
265 RT::Test->clean_caught_mails;
267 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
268 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
269 $m->form_name('TicketUpdate');
270 $m->tick( Encrypt => 1 );
271 $m->field( UpdateCc => 'rt-test@example.com' );
272 $m->field( UpdateContent => 'Some content' );
273 $m->field( Attach => $0 );
274 $m->click('SubmitTicket');
275 $m->content_contains(
276 'You are going to encrypt outgoing email messages',
279 $m->content_contains(
280 'There are several keys suitable for encryption',
284 my $form = $m->form_name('TicketUpdate');
285 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
286 is scalar $input->possible_values, 2, 'two options';
288 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
289 $m->click('SubmitTicket');
290 $m->content_contains('Message recorded', 'Message recorded' );
292 my @mail = RT::Test->fetch_caught_mails;
293 ok @mail, 'there are some emails';
294 check_text_emails( { Encrypt => 1, Attachment => 1 }, @mail );