aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/author-no-tabs.t4
-rw-r--r--t/author-pod-coverage.t3
-rw-r--r--t/tests/sietima/role/nospoof.t41
-rw-r--r--t/tests/sietima/role/nospoof/dmarc.t69
4 files changed, 116 insertions, 1 deletions
diff --git a/t/author-no-tabs.t b/t/author-no-tabs.t
index 169b4c9..7898f4b 100644
--- a/t/author-no-tabs.t
+++ b/t/author-no-tabs.t
@@ -27,6 +27,8 @@ my @files = (
'lib/Sietima/Role/Headers.pm',
'lib/Sietima/Role/ManualSubscription.pm',
'lib/Sietima/Role/NoMail.pm',
+ 'lib/Sietima/Role/NoSpoof.pm',
+ 'lib/Sietima/Role/NoSpoof/DMARC.pm',
'lib/Sietima/Role/ReplyTo.pm',
'lib/Sietima/Role/SubjectTag.pm',
'lib/Sietima/Role/SubscriberOnly.pm',
@@ -51,6 +53,8 @@ my @files = (
't/tests/sietima/role/headers.t',
't/tests/sietima/role/manualsubscription.t',
't/tests/sietima/role/nomail.t',
+ 't/tests/sietima/role/nospoof.t',
+ 't/tests/sietima/role/nospoof/dmarc.t',
't/tests/sietima/role/replyto.t',
't/tests/sietima/role/subject-tag.t',
't/tests/sietima/role/subscriberonly/drop.t',
diff --git a/t/author-pod-coverage.t b/t/author-pod-coverage.t
index 243340f..09473df 100644
--- a/t/author-pod-coverage.t
+++ b/t/author-pod-coverage.t
@@ -8,7 +8,8 @@ BEGIN {
}
# This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests.
-
+use strict;
+use warnings;
use Test::Pod::Coverage 1.08;
use Pod::Coverage::TrustPod;
diff --git a/t/tests/sietima/role/nospoof.t b/t/tests/sietima/role/nospoof.t
new file mode 100644
index 0000000..b0ec622
--- /dev/null
+++ b/t/tests/sietima/role/nospoof.t
@@ -0,0 +1,41 @@
+#!perl
+use lib 't/lib';
+use Test::Sietima;
+
+my $s = make_sietima(
+ with_traits => ['NoSpoof'],
+ subscribers => [
+ 'one@users.example.com',
+ 'two@users.example.com',
+ ],
+);
+
+my $return_path = $s->return_path;
+my $return_path_address = $return_path->address;
+my $return_path_host = $return_path->host;
+
+test_sending(
+ sietima => $s,
+ mail => {
+ from => 'a user <one@users.example.com>',
+ },
+ mails => [
+ object {
+ call [ header_str => 'from' ] => qq{"a user" <$return_path_address>};
+ },
+ ],
+);
+
+test_sending(
+ sietima => $s,
+ mail => {
+ from => qq{a user <one\@$return_path_host>},
+ },
+ mails => [
+ object {
+ call [ header_str => 'from' ] => qq{"a user" <one\@$return_path_host>};
+ },
+ ],
+);
+
+done_testing;
diff --git a/t/tests/sietima/role/nospoof/dmarc.t b/t/tests/sietima/role/nospoof/dmarc.t
new file mode 100644
index 0000000..620268b
--- /dev/null
+++ b/t/tests/sietima/role/nospoof/dmarc.t
@@ -0,0 +1,69 @@
+#!perl
+use lib 't/lib';
+use Test::Sietima;
+use Net::DNS::Resolver::Mock;
+
+my $resolver = Net::DNS::Resolver::Mock->new();
+
+my $s = make_sietima(
+ with_traits => ['NoSpoof::DMARC'],
+ subscribers => [
+ 'one@users.example.com',
+ ],
+ dmarc_resolver => $resolver,
+);
+
+sub test_rewriting($from) {
+ subtest "$from should rewrite" => sub {
+ test_sending(
+ sietima => $s,
+ mail => {
+ from => "a user <$from>",
+ },
+ mails => [
+ object {
+ call [ header_str => 'from' ] => '"a user" <'.$s->return_path->address.'>';
+ call [ header_str => 'original-from' ] => qq{"a user" <$from>};
+ },
+ ],
+ );
+ }
+}
+
+sub test_no_rewriting($from) {
+ subtest "$from should not rewrite" => sub {
+ test_sending(
+ sietima => $s,
+ mail => {
+ from => "a user <$from>",
+ },
+ mails => [
+ object {
+ call [ header_str => 'sender' ] => $s->return_path->address;
+ call [ header_str => 'from' ] => qq{"a user" <$from>};
+ },
+ ],
+ );
+ }
+}
+
+$resolver->zonefile_parse(<<'EOZ');
+_dmarc.none-none-pol.com 3600 TXT "v=DMARC1; p=none; sp=none; rua=mailto:foo@example.com"
+_dmarc.none-q-pol.com 3600 TXT "v=DMARC1; p=none; sp=quarantine; rua=mailto:foo@example.com"
+_dmarc.q-q-pol.com 3600 TXT "v=DMARC1; p=quarantine; sp=quarantine; rua=mailto:foo@example.com"
+EOZ
+
+test_no_rewriting 'foo@none-none-pol.com';
+test_no_rewriting 'foo@sub.none-none-pol.com';
+
+test_no_rewriting 'foo@none-q-pol.com';
+test_rewriting 'foo@sub.none-q-pol.com';
+
+test_rewriting 'foo@q-q-pol.com';
+test_rewriting 'foo@sub.q-q-pol.com';
+
+test_no_rewriting 'foo@example.com';
+
+test_no_rewriting 'foo@' . $s->post_address->host;
+
+done_testing;