1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
use strict;
use warnings;
use RT::Test::SMIME tests => undef;
my $test = 'RT::Test::SMIME';
use IPC::Run3 'run3';
use RT::Interface::Email;
my ($url, $m) = RT::Test->started_ok;
ok $m->login, "logged in";
my $queue = RT::Test->load_or_create_queue(
Name => 'General',
CorrespondAddress => 'sender@example.com',
CommentAddress => '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 $user;
{
$user = RT::User->new($RT::SystemUser);
ok($user->LoadByEmail('root@localhost'), "Loaded user 'root'");
ok($user->Load('root'), "Loaded user 'root'");
is($user->EmailAddress, 'root@localhost');
RT::Test::SMIME->import_key( 'root@example.com.crt' => $user );
}
RT::Test->clean_caught_mails;
{
my $mail = <<END;
From: root\@localhost
To: rt\@example.com
Subject: This is a test of new ticket creation as an unknown user
Blah!
Foob!
END
my ($status, $id) = RT::Test->send_via_mailgate(
$mail, queue => $queue->Name,
);
is $status >> 8, 0, "successfuly executed mailgate";
my $ticket = RT::Ticket->new($RT::SystemUser);
$ticket->Load( $id );
ok ($ticket->id, "found ticket ". $ticket->id);
}
{
my @mails = RT::Test->fetch_caught_mails;
is scalar @mails, 1, "autoreply";
my ($buf, $err);
local $@;
ok(eval {
run3([
qw(openssl smime -decrypt -passin pass:123456),
'-inkey', $test->key_path('root@example.com.key'),
'-recip', $test->key_path('root@example.com.crt')
], \$mails[0], \$buf, \$err )
}, 'can decrypt'
);
diag $@ if $@;
diag $err if $err;
diag "Error code: $?" if $?;
like($buf, qr'This message has been automatically generated in response');
}
undef $m;
done_testing;
|