4 use RT::Test::SMIME tests => undef, actual_server => 1, config => 'Set( %Crypt, RejectOnUnencrypted => 1 );';
5 my $test = 'RT::Test::SMIME';
8 use String::ShellQuote 'shell_quote';
11 my ($url, $m) = RT::Test->started_ok;
12 ok $m->login, "logged in";
14 # configure key for General queue
15 RT::Test::SMIME->import_key('sender@example.com');
16 my $queue = RT::Test->load_or_create_queue(
18 CorrespondAddress => 'sender@example.com',
19 CommentAddress => 'sender@example.com',
21 ok $queue && $queue->id, 'loaded or created queue';
23 my $user = RT::Test->load_or_create_user(
24 Name => 'root@example.com',
25 EmailAddress => 'root@example.com',
27 RT::Test::SMIME->import_key('root@example.com.crt', $user);
28 RT::Test->add_rights( Principal => $user, Right => 'SuperUser', Object => RT->System );
30 my $mail = RT::Test->open_mailgate_ok($url);
34 Subject: This is a test of new ticket creation as root
39 RT::Test->close_mailgate_ok($mail);
42 ok(!RT::Test->last_ticket, 'A ticket was not created');
43 my ($mail) = RT::Test->fetch_caught_mails;
46 qr/^Subject: RT requires that all incoming mail be encrypted/m,
47 'rejected mail that is not encrypted'
49 my ($warning) = $m->get_warnings;
50 like($warning, qr/rejected because the message is unencrypted/);
54 # test for encrypted mail
58 qw(openssl smime -encrypt -des3),
59 -from => 'root@example.com',
60 -to => 'sender@example.com',
61 -subject => "Encrypted message for queue",
62 $test->key_path('sender@example.com.crt' ),
64 \"Subject: test\n\norzzzzzz",
69 my ($status, $tid) = RT::Test->send_via_mailgate( $buf );
70 is ($status >> 8, 0, "The mail gateway exited normally");
72 my $tick = RT::Ticket->new( $RT::SystemUser );
74 is( $tick->Subject, 'Encrypted message for queue',
78 my $txn = $tick->Transactions->First;
79 my ($msg, $attach, $orig) = @{$txn->Attachments->ItemsArrayRef};
80 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
82 'recorded incoming mail that is encrypted'
84 is( $msg->GetHeader('X-RT-Privacy'),
86 'recorded incoming mail that is encrypted'
88 like( $attach->Content, qr'orz');
90 is( $orig->GetHeader('Content-Type'), 'application/x-rt-original-message');
100 RT->Config->Get('SMIME')->{'OpenSSL'},
101 qw( smime -sign -nodetach -passin pass:123456),
102 -signer => $test->key_path('root@example.com.crt' ),
103 -inkey => $test->key_path('root@example.com.key' ),
107 qw(openssl smime -encrypt -des3),
108 -from => 'root@example.com',
109 -to => 'sender@example.com',
110 -subject => "Encrypted and signed message for queue",
111 $test->key_path('sender@example.com.crt' ),
113 \"Subject: test\n\norzzzzzz",
118 my ($status, $tid) = RT::Test->send_via_mailgate( $buf );
120 my $tick = RT::Ticket->new( $RT::SystemUser );
122 ok( $tick->Id, "found ticket " . $tick->Id );
123 is( $tick->Subject, 'Encrypted and signed message for queue',
127 my $txn = $tick->Transactions->First;
128 my ($msg, $attach, $orig) = @{$txn->Attachments->ItemsArrayRef};
129 is( $msg->GetHeader('X-RT-Incoming-Encryption'),
131 'recorded incoming mail that is encrypted'
133 like( $attach->Content, qr'orzzzz');