2013-04-20 22:30:06 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use POSIX qw(strftime);
|
|
|
|
|
|
|
|
use Qpsmtpd::Address;
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
|
|
|
|
my $test_email = 'matt@tnpi.net';
|
|
|
|
|
|
|
|
sub register_tests {
|
|
|
|
my $self = shift;
|
|
|
|
|
2013-12-18 06:09:10 +01:00
|
|
|
# TODO: test against newer DMARC plugin that uses Mail::DMARC
|
2013-04-20 22:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub setup_test_headers {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $transaction = $self->qp->transaction;
|
|
|
|
my $address = Qpsmtpd::Address->new( "<$test_email>" );
|
|
|
|
my $header = Mail::Header->new(Modify => 0, MailFrom => "COERCE");
|
|
|
|
my $now = strftime "%a %b %e %H:%M:%S %Y", localtime time;
|
|
|
|
|
|
|
|
$transaction->sender($address);
|
|
|
|
$transaction->header($header);
|
|
|
|
$transaction->header->add('From', "<$test_email>");
|
|
|
|
$transaction->header->add('Date', $now );
|
|
|
|
$transaction->body_write( "test message body " );
|
|
|
|
|
|
|
|
$self->qp->connection->relay_client(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
sub test_fetch_dmarc_record {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
foreach ( qw/ tnpi.net nictool.com / ) {
|
|
|
|
my @matches = $self->fetch_dmarc_record($_);
|
|
|
|
cmp_ok( scalar @matches, '==', 1, 'fetch_dmarc_record');
|
|
|
|
};
|
|
|
|
foreach ( qw/ example.com / ) {
|
|
|
|
my @matches = $self->fetch_dmarc_record($_);
|
|
|
|
cmp_ok( scalar @matches, '==', 0, 'fetch_dmarc_record');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
sub test_get_organizational_domain {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->setup_test_headers();
|
|
|
|
my $transaction = $self->qp->transaction;
|
|
|
|
|
|
|
|
cmp_ok( $self->get_organizational_domain('test.www.tnpi.net'), 'eq', 'tnpi.net' );
|
2013-04-24 22:33:57 +02:00
|
|
|
cmp_ok( $self->get_organizational_domain('www.example.co.uk'), 'eq', 'example.co.uk' );
|
|
|
|
cmp_ok( $self->get_organizational_domain('plus.google.com'), 'eq', 'google.com' );
|
2013-04-20 22:30:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
sub test_discover_policy {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->setup_test_headers();
|
|
|
|
|
2013-04-20 23:53:03 +02:00
|
|
|
ok( $self->discover_policy( 'tnpi.net' ), 'discover_policy' );
|
2013-04-20 22:30:06 +02:00
|
|
|
};
|