aboutsummaryrefslogtreecommitdiffstats
path: root/t/utils
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-09-20 16:19:37 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-09-20 16:19:37 +0100
commit1c5c614af7a0265bd296ef67c0d342b27898185c (patch)
tree26e1199c1010e8d88c87e4821c7f82c3494db5d0 /t/utils
parent33be8df8f21f6ec5cee9c4675847b8e26f72f96b (diff)
Some tests for the Util modules.
Diffstat (limited to 't/utils')
-rw-r--r--t/utils/email.t34
1 files changed, 34 insertions, 0 deletions
diff --git a/t/utils/email.t b/t/utils/email.t
new file mode 100644
index 000000000..23814c1d7
--- /dev/null
+++ b/t/utils/email.t
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::MockModule;
+
+use Utils::Email;
+
+my $resolver = Test::MockModule->new('Net::DNS::Resolver');
+$resolver->mock('send', sub {
+ my ($self, $domain, $type) = @_;
+ my @rrs;
+ is $type, 'TXT';
+ if ($domain eq '_dmarc.yahoo.com') {
+ @rrs = (
+ Net::DNS::RR->new(name => '_dmarc.yahoo.com', type => 'TXT', txtdata => 'p=reject'),
+ Net::DNS::RR->new(name => '_dmarc.yahoo.com', type => 'A'),
+ );
+ } elsif ($domain eq 'cname.example.com') {
+ @rrs = Net::DNS::RR->new(name => 'cname.example.com', type => 'TXT', txtdata => 'p=none');
+ } else {
+ @rrs = Net::DNS::RR->new(name => '_dmarc.example.net', type => 'CNAME', cname => 'cname.example.com');
+ }
+ my $pkt = Net::DNS::Packet->new;
+ push @{$pkt->{answer}}, @rrs;
+ return $pkt;
+});
+
+is Utils::Email::test_dmarc('BAD'), undef;
+is Utils::Email::test_dmarc('test@yahoo.com'), 1;
+is Utils::Email::test_dmarc('test@example.net'), undef;
+
+done_testing();