summaryrefslogtreecommitdiff
path: root/rt/t/crypt
diff options
context:
space:
mode:
Diffstat (limited to 'rt/t/crypt')
-rw-r--r--rt/t/crypt/gnupg/attachments-in-db.t49
-rw-r--r--rt/t/crypt/no-signer-address.t42
-rw-r--r--rt/t/crypt/smime/attachments-in-db.t45
-rw-r--r--rt/t/crypt/smime/bad-recipients.t58
-rw-r--r--rt/t/crypt/smime/status-string.t26
5 files changed, 220 insertions, 0 deletions
diff --git a/rt/t/crypt/gnupg/attachments-in-db.t b/rt/t/crypt/gnupg/attachments-in-db.t
new file mode 100644
index 0000000..1a377c3
--- /dev/null
+++ b/rt/t/crypt/gnupg/attachments-in-db.t
@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+
+use RT::Test::GnuPG
+ tests => 12,
+ gnupg_options => {
+ passphrase => 'recipient',
+ 'trust-model' => 'always',
+ }
+;
+
+RT->Config->Get('Crypt')->{'AllowEncryptDataInDB'} = 1;
+
+RT::Test->import_gnupg_key('general@example.com', 'public');
+RT::Test->import_gnupg_key('general@example.com', 'secret');
+my $queue = RT::Test->load_or_create_queue(
+ Name => 'General',
+ CorrespondAddress => 'general@example.com',
+);
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+ my $ticket = RT::Test->create_ticket(
+ Queue => $queue->id,
+ Subject => 'test',
+ Content => 'test',
+ );
+
+ my $txn = $ticket->Transactions->First;
+ ok $txn && $txn->id, 'found first transaction';
+ is $txn->Type, 'Create', 'it is Create transaction';
+
+ my $attach = $txn->Attachments->First;
+ ok $attach && $attach->id, 'found attachment';
+ is $attach->Content, 'test', 'correct content';
+
+ my ($status, $msg) = $attach->Encrypt;
+ ok $status, 'encrypted attachment';
+
+ isnt $attach->Content, 'test', 'correct content';
+
+ ($status, $msg) = $attach->Decrypt;
+ ok $status, 'decrypted attachment';
+
+ is $attach->Content, 'test', 'correct content';
+}
+
+
+
diff --git a/rt/t/crypt/no-signer-address.t b/rt/t/crypt/no-signer-address.t
new file mode 100644
index 0000000..31ba5eb
--- /dev/null
+++ b/rt/t/crypt/no-signer-address.t
@@ -0,0 +1,42 @@
+use strict;
+use warnings;
+
+use RT::Test::GnuPG
+ tests => undef,
+ gnupg_options => {
+ passphrase => 'rt-test',
+ 'trust-model' => 'always',
+ }
+;
+
+my $queue;
+{
+ $queue = RT::Test->load_or_create_queue(
+ Name => 'Regression',
+ SignAuto => 1,
+ );
+ ok $queue && $queue->id, 'loaded or created queue';
+ ok !$queue->CorrespondAddress, 'address not set';
+}
+
+# We don't use Test::Warn here, because it apparently only captures up
+# to the first newline -- and the meat of this message is on the fourth
+# line.
+my @warnings;
+local $SIG{__WARN__} = sub {
+ push @warnings, "@_";
+};
+
+my $ticket = RT::Ticket->new( RT->SystemUser );
+my ($status, undef, $msg) = $ticket->Create(
+ Queue => $queue->id,
+ Subject => 'test',
+ Requestor => 'root@localhost',
+);
+ok( $status, "created ticket" ) or diag "error: $msg";
+
+is( scalar @warnings, 1, "Got a warning" );
+like( $warnings[0], qr{signing failed: secret key not available},
+ "Found warning of no secret key");
+
+done_testing;
diff --git a/rt/t/crypt/smime/attachments-in-db.t b/rt/t/crypt/smime/attachments-in-db.t
new file mode 100644
index 0000000..5230938
--- /dev/null
+++ b/rt/t/crypt/smime/attachments-in-db.t
@@ -0,0 +1,45 @@
+use strict;
+use warnings;
+
+use RT::Test::SMIME tests => undef;
+
+use IPC::Run3 'run3';
+use String::ShellQuote 'shell_quote';
+use RT::Tickets;
+
+RT->Config->Get('Crypt')->{'AllowEncryptDataInDB'} = 1;
+
+RT::Test::SMIME->import_key('sender@example.com');
+my $queue = RT::Test->load_or_create_queue(
+ Name => 'General',
+ CorrespondAddress => 'sender@example.com',
+);
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+ my $ticket = RT::Test->create_ticket(
+ Queue => $queue->id,
+ Subject => 'test',
+ Content => 'test',
+ );
+
+ my $txn = $ticket->Transactions->First;
+ ok $txn && $txn->id, 'found first transaction';
+ is $txn->Type, 'Create', 'it is Create transaction';
+
+ my $attach = $txn->Attachments->First;
+ ok $attach && $attach->id, 'found attachment';
+ is $attach->Content, 'test', 'correct content';
+
+ my ($status, $msg) = $attach->Encrypt;
+ ok $status, 'encrypted attachment' or diag "error: $msg";
+
+ isnt $attach->Content, 'test', 'correct content';
+
+ ($status, $msg) = $attach->Decrypt;
+ ok $status, 'decrypted attachment' or diag "error: $msg";
+
+ is $attach->Content, 'test', 'correct content';
+}
+
+done_testing;
diff --git a/rt/t/crypt/smime/bad-recipients.t b/rt/t/crypt/smime/bad-recipients.t
new file mode 100644
index 0000000..1dc097a
--- /dev/null
+++ b/rt/t/crypt/smime/bad-recipients.t
@@ -0,0 +1,58 @@
+use strict;
+use warnings;
+
+use RT::Test::SMIME tests => undef;
+
+use RT::Tickets;
+
+RT::Test::SMIME->import_key('sender@example.com');
+my $queue = RT::Test->load_or_create_queue(
+ Name => 'General',
+ CorrespondAddress => 'sender@example.com',
+);
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+ my ($status, $msg) = $queue->SetEncrypt(1);
+ ok $status, "turn on encyption by default"
+ or diag "error: $msg";
+}
+
+my $root;
+{
+ $root = RT::User->new($RT::SystemUser);
+ ok($root->LoadByEmail('root@localhost'), "Loaded user 'root'");
+ ok($root->Load('root'), "Loaded user 'root'");
+ is($root->EmailAddress, 'root@localhost');
+
+ RT::Test::SMIME->import_key( 'root@example.com.crt' => $root );
+}
+
+my $bad_user;
+{
+ $bad_user = RT::Test->load_or_create_user(
+ Name => 'bad_user',
+ EmailAddress => 'baduser@example.com',
+ );
+ ok $bad_user && $bad_user->id, 'created a user without key';
+}
+
+RT::Test->clean_caught_mails;
+
+use Test::Warn;
+
+warnings_like {
+ my $ticket = RT::Ticket->new(RT->SystemUser);
+ my ($status, undef, $msg) = $ticket->Create( Queue => $queue->id, Requestor => [$root->id, $bad_user->id] );
+ ok $status, "created a ticket" or diag "error: $msg";
+
+ my @mails = RT::Test->fetch_caught_mails;
+ is scalar @mails, 3, "autoreply, to bad user, to RT owner";
+
+ like $mails[0], qr{To: baduser\@example\.com}, "notification to bad user";
+ like $mails[1], qr{To: root}, "notification to RT owner";
+ like $mails[1], qr{Recipient 'baduser\@example\.com' is unusable, the reason is 'Key not found'},
+ "notification to owner has error";
+} [qr{Recipient 'baduser\@example\.com' is unusable, the reason is 'Key not found'}];
+
+done_testing;
diff --git a/rt/t/crypt/smime/status-string.t b/rt/t/crypt/smime/status-string.t
new file mode 100644
index 0000000..9317229
--- /dev/null
+++ b/rt/t/crypt/smime/status-string.t
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+
+use RT::Test tests => 2;
+
+require RT::Crypt::SMIME;
+note "simple round trip";
+{
+ my %data = (Foo => 'bar', Baz => 'zoo');
+ is_deeply(
+ [ RT::Crypt::SMIME->ParseStatus( RT::Crypt::SMIME->FormatStatus( \%data, \%data ) ) ],
+ [ \%data, \%data ],
+ );
+}
+
+note "status appendability";
+{
+ my %data = (Foo => 'bar', Baz => 'zoo');
+ is_deeply(
+ [ RT::Crypt::SMIME->ParseStatus(
+ RT::Crypt::SMIME->FormatStatus( \%data )
+ . RT::Crypt::SMIME->FormatStatus( \%data )
+ ) ],
+ [ \%data, \%data ],
+ );
+}