RT 4.0.13
[freeside.git] / rt / t / mail / gnupg-special.t
1 use strict;
2 use warnings;
3
4 use RT::Test::GnuPG tests => 25, gnupg_options => { passphrase => 'rt-test' };
5
6 use Digest::MD5 qw(md5_hex);
7
8 RT::Test->import_gnupg_key('rt-recipient@example.com');
9 RT::Test->import_gnupg_key('rt-test@example.com', 'public');
10
11 my ($baseurl, $m) = RT::Test->started_ok;
12
13 ok( $m->login, 'we did log in' );
14
15 # configure key for General queue
16 {
17     $m->get( $baseurl.'/Admin/Queues/');
18     $m->follow_link_ok( {text => 'General'} );
19     $m->submit_form(
20         form_number => 3,
21         fields      => { CorrespondAddress => 'rt-recipient@example.com' },
22     );
23     $m->content_like(qr/rt-recipient\@example.com.* - never/, 'has key info.');
24 }
25
26 ok(my $user = RT::User->new(RT->SystemUser));
27 ok($user->Load('root'), "Loaded user 'root'");
28 $user->SetEmailAddress('recipient@example.com');
29
30 {
31     my $id = send_via_mailgate('quoted_inline_signature.txt');
32
33     my $tick = RT::Ticket->new( RT->SystemUser );
34     $tick->Load( $id );
35     ok ($tick->id, "loaded ticket #$id");
36
37     my $txn = $tick->Transactions->First;
38     my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef};
39
40     is( $msg->GetHeader('X-RT-Privacy'),
41         undef,
42         "no privacy is set as this ticket is not encrypted"
43     );
44
45     my @mail = RT::Test->fetch_caught_mails;
46     is(scalar @mail, 1, "autoreply only");
47 }
48
49 {
50     my $id = send_via_mailgate('binary-asc-attach-marked-plain-text.txt');
51
52     my $tick = RT::Ticket->new( $RT::SystemUser );
53     $tick->Load( $id );
54     ok ($tick->id, "loaded ticket #$id");
55
56     my $txn = $tick->Transactions->First;
57     my ($msg, @attachs) = @{$txn->Attachments->ItemsArrayRef};
58
59     is (scalar @attachs, 3, 'text, attachment and original');
60     my $bin = $attachs[1];
61     is(
62         (split /;/, $bin->GetHeader('Content-Type'))[0],
63         'application/octet-stream',
64         'binary attachment'
65     );
66     is(md5_hex($bin->Content), '1e35f1aa90c98ca2bab85c26ae3e1ba7', "correct png");
67 }
68
69 {
70     my $id = send_via_mailgate('inline-binary-attachment-with-wrap.txt');
71
72     my $tick = RT::Ticket->new( $RT::SystemUser );
73     $tick->Load( $id );
74     ok ($tick->id, "loaded ticket #$id");
75
76     my $txn = $tick->Transactions->First;
77     my ($msg, @attachs) = @{$txn->Attachments->ItemsArrayRef};
78
79     is (scalar @attachs, 3, 'text, attachment and original');
80     my $bin = $attachs[1];
81     is(
82         (split /;/, $bin->GetHeader('Content-Type'))[0],
83         'application/octet-stream',
84         'binary attachment'
85     );
86     is(md5_hex($bin->Content), '1e35f1aa90c98ca2bab85c26ae3e1ba7', "correct png");
87 }
88
89 sub send_via_mailgate {
90     my $fname = shift;
91     my $emaildatadir = RT::Test::get_relocatable_dir(File::Spec->updir(),
92         qw(data gnupg emails special));
93     my $file = File::Spec->catfile( $emaildatadir, $fname );
94     my $mail = RT::Test->file_content($file);
95
96     my ($status, $id) = RT::Test->send_via_mailgate($mail);
97     is ($status >> 8, 0, "the mail gateway exited normally");
98     ok ($id, "got id of a newly created ticket - $id");
99     return $id;
100 }
101