5 use RT::Test::GnuPG tests => 79, 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';
18 diag "check that signing doesn't work if there is no key";
20 RT::Test->clean_caught_mails;
22 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
23 $m->form_name('TicketCreate');
24 $m->tick( Sign => 1 );
25 $m->field( Requestors => 'rt-test@example.com' );
26 $m->field( Content => 'Some content' );
29 'unable to sign outgoing email messages',
30 'problems with passphrase'
32 $m->warning_like(qr/signing failed: secret key not available/);
34 my @mail = RT::Test->fetch_caught_mails;
35 ok !@mail, 'there are no outgoing emails';
39 RT::Test->import_gnupg_key('rt-recipient@example.com');
40 RT::Test->trust_gnupg_key('rt-recipient@example.com');
41 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-recipient@example.com');
42 is $res{'info'}[0]{'TrustTerse'}, 'ultimate', 'ultimately trusted key';
45 diag "check that things don't work if there is no key";
47 RT::Test->clean_caught_mails;
49 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
50 $m->form_name('TicketCreate');
51 $m->tick( Encrypt => 1 );
52 $m->field( Requestors => 'rt-test@example.com' );
53 $m->field( Content => 'Some content' );
56 'You are going to encrypt outgoing email messages',
60 'There is no key suitable for encryption',
64 my $form = $m->form_name('TicketCreate');
65 ok !$form->find_input( 'UseKey-rt-test@example.com' ), 'no key selector';
67 my @mail = RT::Test->fetch_caught_mails;
68 ok !@mail, 'there are no outgoing emails';
70 $m->next_warning_like(qr/public key not found/) for 1 .. 4;
71 $m->no_leftover_warnings_ok;
74 diag "import first key of rt-test\@example.com";
77 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
78 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
79 is $res{'info'}[0]{'TrustLevel'}, 0, 'is not trusted key';
80 $fpr1 = $res{'info'}[0]{'Fingerprint'};
83 diag "check that things still doesn't work if key is not trusted";
85 RT::Test->clean_caught_mails;
87 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
88 $m->form_name('TicketCreate');
89 $m->tick( Encrypt => 1 );
90 $m->field( Requestors => 'rt-test@example.com' );
91 $m->field( Content => 'Some content' );
94 'You are going to encrypt outgoing email messages',
98 'There is one suitable key, but trust level is not set',
102 my $form = $m->form_name('TicketCreate');
103 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
104 is scalar $input->possible_values, 1, 'one option';
106 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
108 $m->content_contains(
109 'You are going to encrypt outgoing email messages',
112 $m->content_contains(
113 'Selected key either is not trusted',
117 my @mail = RT::Test->fetch_caught_mails;
118 ok !@mail, 'there are no outgoing emails';
123 diag "import a second key of rt-test\@example.com";
126 RT::Test->import_gnupg_key('rt-test@example.com.2', 'public');
127 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
128 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
129 $fpr2 = $res{'info'}[2]{'Fingerprint'};
132 diag "check that things still doesn't work if two keys are not trusted";
134 RT::Test->clean_caught_mails;
136 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
137 $m->form_name('TicketCreate');
138 $m->tick( Encrypt => 1 );
139 $m->field( Requestors => 'rt-test@example.com' );
140 $m->field( Content => 'Some content' );
142 $m->content_contains(
143 'You are going to encrypt outgoing email messages',
146 $m->content_contains(
147 'There are several keys suitable for encryption',
151 my $form = $m->form_name('TicketCreate');
152 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
153 is scalar $input->possible_values, 2, 'two options';
155 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
157 $m->content_contains(
158 'You are going to encrypt outgoing email messages',
161 $m->content_contains(
162 'Selected key either is not trusted',
166 my @mail = RT::Test->fetch_caught_mails;
167 ok !@mail, 'there are no outgoing emails';
173 RT::Test->lsign_gnupg_key( $fpr1 );
174 my %res = RT::Crypt::GnuPG::GetKeysInfo('rt-test@example.com');
175 ok $res{'info'}[0]{'TrustLevel'} > 0, 'trusted key';
176 is $res{'info'}[1]{'TrustLevel'}, 0, 'is not trusted key';
179 diag "check that we see key selector even if only one key is trusted but there are more keys";
181 RT::Test->clean_caught_mails;
183 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
184 $m->form_name('TicketCreate');
185 $m->tick( Encrypt => 1 );
186 $m->field( Requestors => 'rt-test@example.com' );
187 $m->field( Content => 'Some content' );
189 $m->content_contains(
190 'You are going to encrypt outgoing email messages',
193 $m->content_contains(
194 'There are several keys suitable for encryption',
198 my $form = $m->form_name('TicketCreate');
199 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
200 is scalar $input->possible_values, 2, 'two options';
202 my @mail = RT::Test->fetch_caught_mails;
203 ok !@mail, 'there are no outgoing emails';
208 diag "check that key selector works and we can select trusted key";
210 RT::Test->clean_caught_mails;
212 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
213 $m->form_name('TicketCreate');
214 $m->tick( Encrypt => 1 );
215 $m->field( Requestors => 'rt-test@example.com' );
216 $m->field( Content => 'Some content' );
218 $m->content_contains(
219 'You are going to encrypt outgoing email messages',
222 $m->content_contains(
223 'There are several keys suitable for encryption',
227 my $form = $m->form_name('TicketCreate');
228 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
229 is scalar $input->possible_values, 2, 'two options';
231 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
233 $m->content_like( qr/Ticket \d+ created in queue/i, 'ticket created' );
235 my @mail = RT::Test->fetch_caught_mails;
236 ok @mail, 'there are some emails';
237 check_text_emails( { Encrypt => 1 }, @mail );
242 diag "check encrypting of attachments";
244 RT::Test->clean_caught_mails;
246 ok $m->goto_create_ticket( $queue ), "UI -> create ticket";
247 $m->form_name('TicketCreate');
248 $m->tick( Encrypt => 1 );
249 $m->field( Requestors => 'rt-test@example.com' );
250 $m->field( Content => 'Some content' );
251 $m->field( Attach => $0 );
253 $m->content_contains(
254 'You are going to encrypt outgoing email messages',
257 $m->content_contains(
258 'There are several keys suitable for encryption',
262 my $form = $m->form_name('TicketCreate');
263 ok my $input = $form->find_input( 'UseKey-rt-test@example.com' ), 'found key selector';
264 is scalar $input->possible_values, 2, 'two options';
266 $m->select( 'UseKey-rt-test@example.com' => $fpr1 );
268 $m->content_like( qr/Ticket \d+ created in queue/i, 'ticket created' );
270 my @mail = RT::Test->fetch_caught_mails;
271 ok @mail, 'there are some emails';
272 check_text_emails( { Encrypt => 1, Attachment => 1 }, @mail );