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