Skip to content

Commit

Permalink
restore dmarc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Jan 16, 2025
1 parent bde9b43 commit e985c0a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions t/plugin_tests/dmarc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!perl -w

use strict;
use English qw/-no_match_vars/;
use POSIX qw(strftime);

use Qpsmtpd::Address;
use Qpsmtpd::Constants;

my $remote_ip = '66.128.51.165';
my $test_email = '[email protected]';

sub register_tests {
my $self = shift;

eval 'use Mail::DMARC';
if ($EVAL_ERROR) {
warn 'unable to load Mail::DMARC';
return;
}

$self->register_test('_check_dmarc');
}

sub _check_dmarc {
my $self = shift;

$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 " );

# no From header, reject as invalid message
my ($rc, $msg) = $self->check_dmarc($t);
cmp_ok($rc, '==', DENY, "no From header, $msg");


$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');

#warn $self->qp->connection->notes('authentication_results');
}
2 changes: 1 addition & 1 deletion t/plugin_tests/helo
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sub test_invalid_localhost {
my $self = shift;

my ($err, $why);
foreach my $ip ( '', '192.0.99.5' ) {
foreach my $ip ( undef, '', '192.0.99.5' ) {
$self->qp->connection->remote_ip(undef);
($err, $why) = $self->invalid_localhost('localhost');
ok($err, "host: localhost, remote ip ($ip)");

Check failure on line 59 in t/plugin_tests/helo

View workflow job for this annotation

GitHub Actions / test (5.16)

Use of uninitialized value $ip in concatenation (.) or string

Check failure on line 59 in t/plugin_tests/helo

View workflow job for this annotation

GitHub Actions / test (5.26)

Use of uninitialized value $ip in concatenation (.) or string

Check failure on line 59 in t/plugin_tests/helo

View workflow job for this annotation

GitHub Actions / test (5.38)

Use of uninitialized value $ip in concatenation (.) or string

Check failure on line 59 in t/plugin_tests/helo

View workflow job for this annotation

GitHub Actions / test (5.16)

Use of uninitialized value $ip in concatenation (.) or string

Check failure on line 59 in t/plugin_tests/helo

View workflow job for this annotation

GitHub Actions / test (5.26)

Use of uninitialized value $ip in concatenation (.) or string

Check failure on line 59 in t/plugin_tests/helo

View workflow job for this annotation

GitHub Actions / test (5.38)

Use of uninitialized value $ip in concatenation (.) or string
Expand Down

0 comments on commit e985c0a

Please sign in to comment.