4 use RT::Test::GnuPG tests => undef, 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->GetKeysInfo( Key => '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';
85 $m->next_warning_like(qr/public key not found/) for 1 .. 2;
86 $m->no_leftover_warnings_ok;
90 diag "import first key of rt-test\@example.com";
93 RT::Test->import_gnupg_key('rt-test@example.com', 'secret');
94 my %res = RT::Crypt->GetKeysInfo( Key => 'rt-test@example.com' );
95 is $res{'info'}[0]{'TrustLevel'}, 0, 'is not trusted key';
96 $fpr1 = $res{'info'}[0]{'Fingerprint'};
99 diag "check that things still doesn't work if key is not trusted";
101 RT::Test->clean_caught_mails;
103 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
104 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
105 $m->form_name('TicketUpdate');
106 $m->tick( Encrypt => 1 );
107 $m->field( UpdateCc => 'rt-test@example.com' );
108 $m->field( UpdateContent => 'Some content' );
109 $m->click('SubmitTicket');
110 $m->content_contains(
111 'You are going to encrypt outgoing email messages',
114 $m->content_contains(
115 'There is one suitable key, but trust level is not set',
119 my $form = $m->form_name('TicketUpdate');
120 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
121 is scalar $input->possible_values, 1, 'one option';
123 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
124 $m->click('SubmitTicket');
125 $m->content_contains(
126 'You are going to encrypt outgoing email messages',
129 $m->content_contains(
130 'Selected key either is not trusted',
134 my @mail = RT::Test->fetch_caught_mails;
135 ok !@mail, 'there are no outgoing emails';
140 diag "import a second key of rt-test\@example.com";
143 RT::Test->import_gnupg_key('rt-test@example.com.2', 'secret');
144 my %res = RT::Crypt->GetKeysInfo( Key => 'rt-test@example.com' );
145 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
146 $fpr2 = $res{'info'}[2]{'Fingerprint'};
149 diag "check that things still doesn't work if two keys are not trusted";
151 RT::Test->clean_caught_mails;
153 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
154 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
155 $m->form_name('TicketUpdate');
156 $m->tick( Encrypt => 1 );
157 $m->field( UpdateCc => 'rt-test@example.com' );
158 $m->field( UpdateContent => 'Some content' );
159 $m->click('SubmitTicket');
160 $m->content_contains(
161 'You are going to encrypt outgoing email messages',
164 $m->content_contains(
165 'There are several keys suitable for encryption',
169 my $form = $m->form_name('TicketUpdate');
170 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
171 is scalar $input->possible_values, 2, 'two options';
173 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
174 $m->click('SubmitTicket');
175 $m->content_contains(
176 'You are going to encrypt outgoing email messages',
179 $m->content_contains(
180 'Selected key either is not trusted',
184 my @mail = RT::Test->fetch_caught_mails;
185 ok !@mail, 'there are no outgoing emails';
191 RT::Test->lsign_gnupg_key( $fpr1 );
192 my %res = RT::Crypt->GetKeysInfo( Key => 'rt-test@example.com' );
193 ok $res{'info'}[0]{'TrustLevel'} > 0, 'trusted key';
194 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
197 diag "check that we see key selector even if only one key is trusted but there are more keys";
199 RT::Test->clean_caught_mails;
201 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
202 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
203 $m->form_name('TicketUpdate');
204 $m->tick( Encrypt => 1 );
205 $m->field( UpdateCc => 'rt-test@example.com' );
206 $m->field( UpdateContent => 'Some content' );
207 $m->click('SubmitTicket');
208 $m->content_contains(
209 'You are going to encrypt outgoing email messages',
212 $m->content_contains(
213 'There are several keys suitable for encryption',
217 my $form = $m->form_name('TicketUpdate');
218 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
219 is scalar $input->possible_values, 2, 'two options';
221 my @mail = RT::Test->fetch_caught_mails;
222 ok !@mail, 'there are no outgoing emails';
227 diag "check that key selector works and we can select trusted key";
229 RT::Test->clean_caught_mails;
231 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
232 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
233 $m->form_name('TicketUpdate');
234 $m->tick( Encrypt => 1 );
235 $m->field( UpdateCc => 'rt-test@example.com' );
236 $m->field( UpdateContent => 'Some content' );
237 $m->click('SubmitTicket');
238 $m->content_contains(
239 'You are going to encrypt outgoing email messages',
242 $m->content_contains(
243 'There are several keys suitable for encryption',
247 my $form = $m->form_name('TicketUpdate');
248 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
249 is scalar $input->possible_values, 2, 'two options';
251 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
252 $m->click('SubmitTicket');
253 $m->content_contains('Correspondence added', 'Correspondence added' );
255 my @mail = RT::Test->fetch_caught_mails;
256 ok @mail, 'there are some emails';
257 check_text_emails( { Encrypt => 1 }, @mail );
262 diag "check encrypting of attachments";
263 for my $encrypt (0, 1) {
264 RT::Test->clean_caught_mails;
266 ok $m->goto_ticket( $tid ), "UI -> ticket #$tid";
267 $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' );
268 $m->form_name('TicketUpdate');
269 $m->tick( Encrypt => 1 ) if $encrypt;
270 $m->field( UpdateCc => 'rt-test@example.com' );
271 $m->field( UpdateContent => 'Some content' );
272 $m->field( Attach => $0 );
273 $m->click('SubmitTicket');
276 $m->content_contains(
277 'You are going to encrypt outgoing email messages',
280 $m->content_contains(
281 'There are several keys suitable for encryption',
285 my $form = $m->form_name('TicketUpdate');
286 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
287 is scalar $input->possible_values, 2, 'two options';
289 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
290 $m->click('SubmitTicket');
293 $m->content_contains('Correspondence added', 'Correspondence added' );
295 my @mail = RT::Test->fetch_caught_mails;
296 ok @mail, 'there are some emails';
297 check_text_emails( { Encrypt => $encrypt, Attachment => "Attachment content" }, @mail );