summaryrefslogtreecommitdiff
path: root/rt/t/crypt/smime/bad-recipients.t
blob: 1dc097adec1c412ee3570cec4288e54c504b237b (plain)
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
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;