| 1 |
#!perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
use Data::Dumper; |
| 5 |
use POSIX qw(strftime); |
| 6 |
|
| 7 |
use Qpsmtpd::Address; |
| 8 |
use Qpsmtpd::Constants; |
| 9 |
|
| 10 |
my $test_email = '[email protected]'; |
| 11 |
|
| 12 |
sub register_tests { |
| 13 |
my $self = shift; |
| 14 |
|
| 15 |
# TODO: test against newer DMARC plugin that uses Mail::DMARC |
| 16 |
} |
| 17 |
|
| 18 |
sub setup_test_headers { |
| 19 |
my $self = shift; |
| 20 |
|
| 21 |
my $transaction = $self->qp->transaction; |
| 22 |
my $address = Qpsmtpd::Address->new( "<$test_email>" ); |
| 23 |
my $header = Mail::Header->new(Modify => 0, MailFrom => "COERCE"); |
| 24 |
my $now = strftime "%a %b %e %H:%M:%S %Y", localtime time; |
| 25 |
|
| 26 |
$transaction->sender($address); |
| 27 |
$transaction->header($header); |
| 28 |
$transaction->header->add('From', "<$test_email>"); |
| 29 |
$transaction->header->add('Date', $now ); |
| 30 |
$transaction->body_write( "test message body " ); |
| 31 |
|
| 32 |
$self->qp->connection->relay_client(0); |
| 33 |
}; |
| 34 |
|
| 35 |
sub test_fetch_dmarc_record { |
| 36 |
my $self = shift; |
| 37 |
|
| 38 |
foreach ( qw/ tnpi.net nictool.com / ) { |
| 39 |
my @matches = $self->fetch_dmarc_record($_); |
| 40 |
#warn Data::Dumper::Dumper(\@matches); |
| 41 |
cmp_ok( scalar @matches, '==', 1, 'fetch_dmarc_record'); |
| 42 |
}; |
| 43 |
foreach ( qw/ example.com / ) { |
| 44 |
my @matches = $self->fetch_dmarc_record($_); |
| 45 |
cmp_ok( scalar @matches, '==', 0, 'fetch_dmarc_record'); |
| 46 |
}; |
| 47 |
}; |
| 48 |
|
| 49 |
sub test_get_organizational_domain { |
| 50 |
my $self = shift; |
| 51 |
|
| 52 |
$self->setup_test_headers(); |
| 53 |
my $transaction = $self->qp->transaction; |
| 54 |
|
| 55 |
cmp_ok( $self->get_organizational_domain('test.www.tnpi.net'), 'eq', 'tnpi.net' ); |
| 56 |
cmp_ok( $self->get_organizational_domain('www.example.co.uk'), 'eq', 'example.co.uk' ); |
| 57 |
cmp_ok( $self->get_organizational_domain('plus.google.com'), 'eq', 'google.com' ); |
| 58 |
}; |
| 59 |
|
| 60 |
sub test_discover_policy { |
| 61 |
my $self = shift; |
| 62 |
|
| 63 |
$self->setup_test_headers(); |
| 64 |
|
| 65 |
ok( $self->discover_policy( 'tnpi.net' ), 'discover_policy' ); |
| 66 |
}; |