qpsmtpd/t/plugin_tests/dmarc

46 lines
1.2 KiB
Plaintext
Raw Normal View History

2013-04-20 22:30:06 +02:00
#!perl -w
use strict;
2015-01-21 19:09:37 +01:00
use English qw/-no_match_vars/;
2013-04-20 22:30:06 +02:00
use POSIX qw(strftime);
use Qpsmtpd::Address;
use Qpsmtpd::Constants;
2015-01-21 19:09:37 +01:00
my $remote_ip = '66.128.51.165';
2013-04-20 22:30:06 +02:00
my $test_email = 'matt@tnpi.net';
sub register_tests {
my $self = shift;
2015-01-21 19:09:37 +01:00
eval 'use Mail::DMARC';
if ($EVAL_ERROR) {
warn 'unable to load Mail::DMARC';
return;
}
2015-01-21 19:09:37 +01:00
$self->register_test('_check_dmarc');
}
2013-04-20 22:30:06 +02:00
2015-01-21 19:09:37 +01:00
sub _check_dmarc {
2013-04-20 22:30:06 +02:00
my $self = shift;
2015-01-21 19:09:37 +01:00
$self->qp->connection->remote_ip($remote_ip);
my $t = $self->qp->transaction;
$t->header(Mail::Header->new(Modify => 0, MailFrom => "COERCE"));
$t->sender(Qpsmtpd::Address->new( "<$test_email>" ));
$t->header->add('Date', strftime "%a %b %e %H:%M:%S %Y", localtime time);
$t->body_write( "test message body " );
2013-04-20 22:30:06 +02:00
2015-01-21 19:09:37 +01:00
# no From header, reject as invalid message
my ($rc, $msg) = $self->check_dmarc($t);
cmp_ok($rc, '==', DENY, "no From header, $msg");
2013-04-20 22:30:06 +02:00
2015-01-21 19:09:37 +01:00
$t->header->add('From', "<$test_email>");
($rc, $msg) = $self->check_dmarc($t);
cmp_ok($rc, '==', DENY, "$msg");
cmp_ok($msg, 'eq', 'failed DMARC policy', 'check_dmarc, no SPF');
2013-04-20 22:30:06 +02:00
2015-01-21 19:09:37 +01:00
#warn $self->qp->connection->notes('authentication_results');
}