Skip to content

Commit

Permalink
Merge pull request #213 from fastmailops/no-network-tests
Browse files Browse the repository at this point in the history
Apply no-network-tests from openSUSE
  • Loading branch information
marcbradshaw authored Aug 28, 2023
2 parents 6581ae2 + 6d936e9 commit c296644
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
Net::IDN::Encode
CGI
XML::Validator::Schema
Net::DNS::Resolver::Mock
sudo: false

- run: perl Makefile.PL
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
XML::Validator::Schema
Test::Exception
Devel::Cover::Report::Coveralls
Net::DNS::Resolver::Mock
sudo: false

- run: perl Makefile.PL
Expand Down
2 changes: 1 addition & 1 deletion .test/install-deps.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

DMARC_DEPS="Regexp::Common Config::Tiny File::ShareDir Net::DNS::Resolver DBD::SQLite DBD::Pg DBD::mysql Net::IP Socket6 Email::MIME Net::SMTPS XML::LibXML Email::Sender DBIx::Simple HTTP::Tiny Test::File::ShareDir Test::Output Net::IDN::Encode CGI XML::Validator::Schema"
DMARC_DEPS="Regexp::Common Config::Tiny File::ShareDir Net::DNS::Resolver DBD::SQLite DBD::Pg DBD::mysql Net::IP Socket6 Email::MIME Net::SMTPS XML::LibXML Email::Sender DBIx::Simple HTTP::Tiny Test::File::ShareDir Test::Output Net::IDN::Encode CGI XML::Validator::Schema Net::DNS::Resolver::Mock"

for _d in $DMARC_DEPS; do
cpanm --quiet --notest "$_d" || exit
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

language: perl
perl:
- "5.38"
- "5.28"
- "5.22"
# perlbrew (used by Travis to install perl versions) no longer supports these
Expand Down
3 changes: 2 additions & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ my $module_build_args = {
"Test::Exception" => 0,
"Test::File::ShareDir" => 0,
"Test::More" => 0,
"Test::Output" => 0
"Test::Output" => 0,
"Net::DNS::Resolver::Mock" => 0
},
"develop_requires" => {
"Test::Pod" => "1.41"
Expand Down
3 changes: 2 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ my %META = (
"Test::Exception" => 0,
"Test::File::ShareDir" => 0,
"Test::More" => 0,
"Test::Output" => 0
"Test::Output" => 0,
"Net::DNS::Resolver::Mock" => 0
}
},
"runtime" => {
Expand Down
3 changes: 3 additions & 0 deletions lib/Mail/DMARC/HTTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ sub return_json_error {

sub serve_validator {
my $cgi = shift || CGI->new(); # passed in $cgi for testing
my $resolver = shift; # passed in $resolver for testing
my $json = JSON->new->utf8;

print $cgi->header("application/json");
Expand All @@ -105,6 +106,8 @@ sub serve_validator {
eval { $dmpp = Mail::DMARC::PurePerl->new( %$input ) };
if ($@) { return return_json_error($@); }

$dmpp->set_resolver($resolver) if $resolver;

eval { $res = $dmpp->validate(); };
if ($@) { return return_json_error($@); }

Expand Down
4 changes: 4 additions & 0 deletions t/03.Base.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Data::Dumper;
use Net::DNS::Resolver::Mock;
use Test::More;

use Test::File::ShareDir
Expand All @@ -28,6 +29,9 @@ eval { $base->config('t/mail-dmarc.ini'); };
chomp $@;
ok( !$@, "alternate config file" );

my $resolver = new Net::DNS::Resolver::Mock();
$base->set_resolver($resolver);

__any_inet_to();
__is_public_suffix();
__has_dns_rr();
Expand Down
13 changes: 13 additions & 0 deletions t/04.PurePerl.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Data::Dumper;
use Net::DNS::Resolver::Mock;
use Test::More;
use URI;

Expand All @@ -11,6 +12,16 @@ use Test::File::ShareDir
use lib 'lib';
use_ok('Mail::DMARC::PurePerl');

my $resolver = new Net::DNS::Resolver::Mock();
$resolver->zonefile_parse(join("\n",
'_dmarc.mail-dmarc.tnpi.net. 600 TXT "v=DMARC1; p=reject; rua=mailto:invalid@theartfarm.com; ruf=mailto:invalid@theartfarm.com; pct=90"',
'_dmarc.tnpi.net. 600 TXT "v=DMARC1; p=reject; rua=mailto:dmarc-feedback@theartfarm.com; ruf=mailto:dmarc-feedback@theartfarm.com; pct=100" ',
'tnpi.net. 600 MX 10 mail.theartfarm.com.',
'tnpi.net._report._dmarc.theartfarm.com. 600 TXT "v=DMARC1"',
'cadillac.net._report._dmarc.theartfarm.com. 600 TXT "v=DMARC1"',
'mail-dmarc.tnpi.net._report._dmarc.theartfarm.com. 600 TXT "v=DMARC1; rua=mailto:invalid-test@theartfarm.com;"',
''));

my @test_policy = (
'v', 'DMARC1', # Section 6.2, Formal Definition
'p', 'reject', # the v(ersion) and request(p) are ordered
Expand All @@ -27,6 +38,7 @@ my $test_rec = join( '; ',

my $dmarc = Mail::DMARC::PurePerl->new;
$dmarc->config('t/mail-dmarc.ini');
$dmarc->set_resolver($resolver);

isa_ok( $dmarc, 'Mail::DMARC::PurePerl' );

Expand Down Expand Up @@ -374,6 +386,7 @@ sub test_validate {
);

$dmarc = Mail::DMARC::PurePerl->new(%sample_dmarc);
$dmarc->set_resolver($resolver);
eval { $dmarc->validate(); };
#print Dumper($dmarc->result);
ok($dmarc->is_spf_aligned(), "validate, one-shot, is_spf_aligned, yes" );
Expand Down
9 changes: 9 additions & 0 deletions t/06.Result.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Data::Dumper;
use Net::DNS::Resolver::Mock;
use Test::More;

use Test::File::ShareDir
Expand All @@ -11,8 +12,16 @@ use lib 'lib';
use_ok('Mail::DMARC::PurePerl');
use_ok('Mail::DMARC::Result');

my $resolver = new Net::DNS::Resolver::Mock();
$resolver->zonefile_parse(join("\n",
'tnpi.net. 600 A 66.128.51.170',
'_dmarc.tnpi.net. 600 TXT "v=DMARC1; p=reject; rua=mailto:dmarc-feedback@theartfarm.com; ruf=mailto:dmarc-feedback@theartfarm.com; pct=100"',
'nodmarcrecord.blogspot.com. 600 A 142.251.37.1',
''));

my $pp = Mail::DMARC::PurePerl->new;
my $result = Mail::DMARC::Result->new;
$pp->set_resolver($resolver);

isa_ok( $result, 'Mail::DMARC::Result' );

Expand Down
20 changes: 14 additions & 6 deletions t/09.HTTP.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Data::Dumper;
use Net::DNS::Resolver::Mock;
use Test::More;

use Test::File::ShareDir
Expand All @@ -17,35 +18,42 @@ foreach my $req ( 'CGI', 'DBD::SQLite 1.31', 'JSON', 'Net::Server::HTTP' ) {
}
};

my $resolver = new Net::DNS::Resolver::Mock();
$resolver->zonefile_parse(join("\n",
'tnpi.net. 600 A 66.128.51.170',
'_dmarc.tnpi.net. 600 TXT "v=DMARC1; p=reject; rua=mailto:dmarc-feedback@theartfarm.com; ruf=mailto:dmarc-feedback@theartfarm.com; pct=100"',
#'tnpi.net. 600 MX 10 mail.theartfarm.com.',
''));

my $mod = 'Mail::DMARC::HTTP';
use_ok($mod);
my $http = $mod->new;
isa_ok( $http, $mod );

my $cgi = CGI->new();
my $r = Mail::DMARC::HTTP::serve_validator($cgi);
my $r = Mail::DMARC::HTTP::serve_validator($cgi, $resolver);
ok($r eq 'missing POST data', "serve_validator, missing POST data");

$cgi->param('POSTDATA', 'foo');
$r = Mail::DMARC::HTTP::serve_validator($cgi);
$r = Mail::DMARC::HTTP::serve_validator($cgi, $resolver);
like($r, qr/expected/, "serve_validator, invalid JSON");

$cgi->param('POSTDATA', '{"foo":"bar"}');
$r = Mail::DMARC::HTTP::serve_validator($cgi);
$r = Mail::DMARC::HTTP::serve_validator($cgi, $resolver);
like($r, qr/no header_from/, "serve_validator, missing header_from");

$cgi->param('POSTDATA', '{"header_from":"tnpi.net"}');
$r = Mail::DMARC::HTTP::serve_validator($cgi);
$r = Mail::DMARC::HTTP::serve_validator($cgi, $resolver);
like($r, qr/"spf":""/, "serve_validator, missing SPF");
like($r, qr/"dkim":"fail"/, "serve_validator, missing DKIM");

$cgi->param('POSTDATA', '{"header_from":"tnpi.net","spf":[{"domain":"tnpi.net","scope":"mfrom","result":"pass"}]}');
$r = Mail::DMARC::HTTP::serve_validator($cgi);
$r = Mail::DMARC::HTTP::serve_validator($cgi, $resolver);
like($r, qr/"spf":"pass"/, "serve_validator, pass SPF");
like($r, qr/"dkim":"fail"/, "serve_validator, missing DKIM");

$cgi->param('POSTDATA', '{"header_from":"tnpi.net","dkim":[{"domain":"tnpi.net","selector":"mar2013","result":"pass"}]}');
$r = Mail::DMARC::HTTP::serve_validator($cgi);
$r = Mail::DMARC::HTTP::serve_validator($cgi, $resolver);
like($r, qr/"spf":""/, "serve_validator, missing SPF");
like($r, qr/"dkim":"pass"/, "serve_validator, pass DKIM");

Expand Down
12 changes: 12 additions & 0 deletions t/11.Report.Store.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Data::Dumper;
use Net::DNS::Resolver::Mock;
use Test::More;

use Test::File::ShareDir
Expand All @@ -15,8 +16,19 @@ if ($@) {
exit;
}

my $resolver = new Net::DNS::Resolver::Mock();
$resolver->zonefile_parse(join("\n",
'tnpi.net. 600 A 66.128.51.170',
'tnpi.net. 600 MX 10 mail.theartfarm.com.',
'_dmarc.mail-dmarc.tnpi.net. 600 TXT "v=DMARC1; p=reject; rua=mailto:invalid@theartfarm.com; ruf=mailto:invalid@theartfarm.com; pct=90"',
'_dmarc.tnpi.net. 600 TXT "v=DMARC1; p=reject; rua=mailto:dmarc-feedback@theartfarm.com; ruf=mailto:dmarc-feedback@theartfarm.com; pct=100"',
'mail-dmarc.tnpi.net. 600 TXT "test zone for Mail::DMARC perl module"',
'mail-dmarc.tnpi.net._report._dmarc.theartfarm.com. 600 TXT "v=DMARC1; rua=mailto:invalid-test@theartfarm.com;"',
''));

use_ok('Mail::DMARC::PurePerl');
my $dmarc = Mail::DMARC::PurePerl->new();
$dmarc->set_resolver($resolver);
isa_ok( $dmarc, 'Mail::DMARC::PurePerl' );

isa_ok( $dmarc->report, 'Mail::DMARC::Report' );
Expand Down
12 changes: 12 additions & 0 deletions t/17.Report.Aggregate.Schema.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Data::Dumper;
use Net::DNS::Resolver::Mock;
use Test::Exception;
use Test::More;
use Test::File::ShareDir -share => { -dist => { 'Mail-DMARC' => 'share' } };
Expand All @@ -28,7 +29,18 @@ if ($@) {
exit;
}

my $resolver = new Net::DNS::Resolver::Mock();
$resolver->zonefile_parse(join("\n",
'tnpi.net. 600 A 66.128.51.170',
'tnpi.net. 600 MX 10 mail.theartfarm.com.',
'_dmarc.mail-dmarc.tnpi.net. 600 TXT "v=DMARC1; p=reject; rua=mailto:invalid@theartfarm.com; ruf=mailto:invalid@theartfarm.com; pct=90"',
'_dmarc.tnpi.net. 600 TXT "v=DMARC1; p=reject; rua=mailto:dmarc-feedback@theartfarm.com; ruf=mailto:dmarc-feedback@theartfarm.com; pct=100"',
'mail-dmarc.tnpi.net. 600 TXT "test zone for Mail::DMARC perl module"',
'mail-dmarc.tnpi.net._report._dmarc.theartfarm.com. 600 TXT "v=DMARC1; rua=mailto:invalid-test@theartfarm.com;"',
''));

my $dmarc = Mail::DMARC::PurePerl->new();
$dmarc->set_resolver($resolver);
my $store = $dmarc->report->store;

$store->config('t/mail-dmarc.ini');
Expand Down
7 changes: 7 additions & 0 deletions t/22.Report.Send.SMTP.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Data::Dumper;
use Net::DNS::Resolver::Mock;
use Test::More;

use IO::Compress::Gzip;
Expand All @@ -11,9 +12,15 @@ use Mail::DMARC::Policy;
use Mail::DMARC::Report::Aggregate;
use Mail::DMARC::Report::Aggregate::Record;

my $resolver = new Net::DNS::Resolver::Mock();
$resolver->zonefile_parse(join("\n",
'tnpi.net. 600 MX 10 mail.theartfarm.com.',
''));

my $mod = 'Mail::DMARC::Report::Send::SMTP';
use_ok($mod);
my $smtp = $mod->new;
$smtp->set_resolver($resolver);
isa_ok( $smtp, $mod );
$smtp->config('t/mail-dmarc.ini');

Expand Down
7 changes: 7 additions & 0 deletions t/26.Report.Sender.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Test::More;
use Net::DNS::Resolver::Mock;

$ENV{MAIL_DMARC_CONFIG_FILE} = 't/mail-dmarc.ini';

Expand All @@ -14,6 +15,11 @@ use Mail::DMARC::Test::Transport;
use Email::Sender::Transport::Failable;
use Email::Sender::Transport::Test;

my $resolver = new Net::DNS::Resolver::Mock();
$resolver->zonefile_parse(join("\n",
'fastmaildmarc.com. 600 MX 10 in1-smtp.messagingengine.com.',
'_dmarc.fastmaildmarc.com. 600 TXT "v=DMARC1; p=reject; rua=mailto:rua@fastmaildmarc.com"',
''));

# We test both method and object type callbacks
foreach my $callback_type ( qw{ method object fail fallback } ) {
Expand All @@ -22,6 +28,7 @@ foreach my $callback_type ( qw{ method object fail fallback } ) {
unlink 't/reports-test.sqlite' if -e 't/reports-test.sqlite'; # Clear test database for each run

my $dmarc = Mail::DMARC::PurePerl->new;
$dmarc->set_resolver($resolver);

$dmarc->set_fake_time( time-86400);
$dmarc->init();
Expand Down

0 comments on commit c296644

Please sign in to comment.