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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
use strict;
use warnings;
use Data::Dumper;
use Test::More;
use IO::Compress::Gzip;
use lib 'lib';
use Mail::DMARC::Policy;
use Mail::DMARC::Report::Aggregate;
use Mail::DMARC::Report::Aggregate::Record;
my $mod = 'Mail::DMARC::Report::Send::SMTP';
use_ok($mod);
my $smtp = $mod->new;
isa_ok( $smtp, $mod );
$smtp->config('t/mail-dmarc.ini');
open my $REP, '<', 'share/rua-schema.xsd'
or die "unable to open: $!";
my $report = join( '', <$REP> );
close $REP;
my $zipped;
IO::Compress::Gzip::gzip( \$report, \$zipped ) or die "unable to compress";
my $agg = Mail::DMARC::Report::Aggregate->new;
my $pol = Mail::DMARC::Policy->new;
$pol->domain('they.com');
$agg->policy_published( $pol );
$agg->metadata->begin( time - 10000 );
$agg->metadata->end( time - 100 );
$agg->metadata->report_id( '2013.06.01.6789' );
test_get_subject();
test_get_domain_mx();
test_get_smtp_hosts();
test_human_summary();
test_get_filename();
test_get_timestamp_rfc2822();
test_get_helo_hostname();
test_assemble_message();
done_testing();
exit;
sub test_get_subject {
my $subject = $smtp->get_subject( \$agg );
ok( $subject, "get_subject, $subject" );
};
sub test_get_helo_hostname {
my $helo = $smtp->get_helo_hostname();
ok( $helo, "get_helo_hostname, $helo" );
};
sub test_get_timestamp_rfc2822 {
my $r = $smtp->get_timestamp_rfc2822();
ok( $r, "get_timestamp_rfc2822, $r");
};
sub test_get_domain_mx {
my %tests = (
'tnpi.net' => [ { 'pref' => 10, 'addr' => 'mail.theartfarm.com' } ],
);
foreach my $dom ( keys %tests ) {
my $r = $smtp->get_domain_mx( $dom );
if (!$r || $r eq 'Does not exist') {
print "it appears your DNS is not working.\n";
next;
}
ok( $r, "get_domain_mx, $dom");
is_deeply( $r, $tests{$dom}, "get_domain_mx, $dom, deeply");
# print Dumper($r);
};
};
sub test_human_summary {
my $record = Mail::DMARC::Report::Aggregate::Record->new(
auth_results => { spf => [] },
identifiers => {
header_from => 'they.com',
},
row => {
source_ip => '192.2.0.1',
policy_evaluated => {
disposition=>'none',
dkim => 'pass',
spf => 'fail'
}
}
);
$agg->record( $record );
$record->row->policy_evaluated->dkim('fail');
$record->row->policy_evaluated->spf('pass');
$agg->record( $record );
$record->row->policy_evaluated->dkim('fail');
$record->row->policy_evaluated->spf('fail');
$agg->record( $record );
my $sum = $smtp->human_summary( \$agg );
ok( $sum, 'human_summary' );
# print $sum;
}
sub test_get_filename {
my $name = $smtp->get_filename(\$agg);
ok( $name, "get_filename, $name");
};
sub test_assemble_message {
my $mess = $smtp->assemble_message_object( \$agg, 'matt@example.com', $zipped )->as_string;
ok( $mess, "assemble_message_object" );
#warn print $mess;
}
sub test_get_smtp_hosts {
my $initial_smarthost = $smtp->config->{smtp}{smarthost};
$smtp->config->{smtp}{smarthost} = undef;
my $tnpi_expected = [ 'mail.theartfarm.com', 'tnpi.net' ];
my @hosts = $smtp->get_smtp_hosts('tnpi.net');
is_deeply( \@hosts, $tnpi_expected, "get_smtp_hosts, tnpi.net");
# print Dumper(\@hosts);
$smtp->config->{smtp}{smarthost} = $initial_smarthost;
}
|