4 use RT::Test::GnuPG tests => 83, 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::GnuPG::GetKeysInfo('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';
70 $m->next_warning_like(qr/public key not found/) ;
71 $m->next_warning_like(qr/above error may result from an unconfigured RT\/GPG/);
74 $m->no_leftover_warnings_ok;
77 diag "import first key of rt-test\@example.com";
80 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
81 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
82 is $res{'info'}[0]{'TrustLevel'}, 0, 'is not trusted key';
83 $fpr1 = $res{'info'}[0]{'Fingerprint'};
86 diag "check that things still doesn't work if key is not trusted";
88 RT::Test->clean_caught_mails;
90 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
91 $m->form_name('TicketCreate');
92 $m->tick( Encrypt => 1 );
93 $m->field( Requestors => 'rt-test@example.com' );
94 $m->field( Content => 'Some content' );
97 'You are going to encrypt outgoing email messages',
100 $m->content_contains(
101 'There is one suitable key, but trust level is not set',
105 my $form = $m->form_name('TicketCreate');
106 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
107 is scalar $input->possible_values, 1, 'one option';
109 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
111 $m->content_contains(
112 'You are going to encrypt outgoing email messages',
115 $m->content_contains(
116 'Selected key either is not trusted',
120 my @mail = RT::Test->fetch_caught_mails;
121 ok !@mail, 'there are no outgoing emails';
126 diag "import a second key of rt-test\@example.com";
129 RT::Test->import_gnupg_key('rt-test@example.com.2', 'public');
130 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
131 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
132 $fpr2 = $res{'info'}[2]{'Fingerprint'};
135 diag "check that things still doesn't work if two keys are not trusted";
137 RT::Test->clean_caught_mails;
139 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
140 $m->form_name('TicketCreate');
141 $m->tick( Encrypt => 1 );
142 $m->field( Requestors => 'rt-test@example.com' );
143 $m->field( Content => 'Some content' );
145 $m->content_contains(
146 'You are going to encrypt outgoing email messages',
149 $m->content_contains(
150 'There are several keys suitable for encryption',
154 my $form = $m->form_name('TicketCreate');
155 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
156 is scalar $input->possible_values, 2, 'two options';
158 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
160 $m->content_contains(
161 'You are going to encrypt outgoing email messages',
164 $m->content_contains(
165 'Selected key either is not trusted',
169 my @mail = RT::Test->fetch_caught_mails;
170 ok !@mail, 'there are no outgoing emails';
176 RT::Test->lsign_gnupg_key( $fpr1 );
177 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
178 ok $res{'info'}[0]{'TrustLevel'} > 0, 'trusted key';
179 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
182 diag "check that we see key selector even if only one key is trusted but there are more keys";
184 RT::Test->clean_caught_mails;
186 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
187 $m->form_name('TicketCreate');
188 $m->tick( Encrypt => 1 );
189 $m->field( Requestors => 'rt-test@example.com' );
190 $m->field( Content => 'Some content' );
192 $m->content_contains(
193 'You are going to encrypt outgoing email messages',
196 $m->content_contains(
197 'There are several keys suitable for encryption',
201 my $form = $m->form_name('TicketCreate');
202 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
203 is scalar $input->possible_values, 2, 'two options';
205 my @mail = RT::Test->fetch_caught_mails;
206 ok !@mail, 'there are no outgoing emails';
211 diag "check that key selector works and we can select trusted key";
213 RT::Test->clean_caught_mails;
215 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
216 $m->form_name('TicketCreate');
217 $m->tick( Encrypt => 1 );
218 $m->field( Requestors => 'rt-test@example.com' );
219 $m->field( Content => 'Some content' );
221 $m->content_contains(
222 'You are going to encrypt outgoing email messages',
225 $m->content_contains(
226 'There are several keys suitable for encryption',
230 my $form = $m->form_name('TicketCreate');
231 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
232 is scalar $input->possible_values, 2, 'two options';
234 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
236 $m->content_like( qr/Ticket \d+ created in queue/i, 'ticket created' );
238 my @mail = RT::Test->fetch_caught_mails;
239 ok @mail, 'there are some emails';
240 check_text_emails( { Encrypt => 1 }, @mail );
245 diag "check encrypting of attachments";
247 RT::Test->clean_caught_mails;
249 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
250 $m->form_name('TicketCreate');
251 $m->tick( Encrypt => 1 );
252 $m->field( Requestors => 'rt-test@example.com' );
253 $m->field( Content => 'Some content' );
254 $m->field( Attach => $0 );
256 $m->content_contains(
257 'You are going to encrypt outgoing email messages',
260 $m->content_contains(
261 'There are several keys suitable for encryption',
265 my $form = $m->form_name('TicketCreate');
266 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
267 is scalar $input->possible_values, 2, 'two options';
269 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
271 $m->content_like( qr/Ticket \d+ created in queue/i, 'ticket created' );
273 my @mail = RT::Test->fetch_caught_mails;
274 ok @mail, 'there are some emails';
275 check_text_emails( { Encrypt => 1, Attachment => 1 }, @mail );