summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorMarc van der Wal <marc.vanderwal@afnic.fr>2022-10-06 14:39:33 +0200
committerMarc van der Wal <marc.vanderwal@afnic.fr>2022-10-12 15:50:22 +0200
commit8b8dd0ba1af6330cdd6dff46df02c0e6984a0761 (patch)
tree6b06ef892998c0bd4eb37f11218fd0398652f434 /t
parentef0a666ee5b71ce029c61fc683bfbfeadd7d9f02 (diff)
Improve access to data in SPF records
SPF resource records are, in essence, TXT resource records with a different type identifier. The only real difference between SPF and TXT resource records lies in their uses: TXT is more generic, where SPF was meant for publishing Sender Policy Framework policies before being deprecated. The Zonemaster::LDNS::RR::SPF module suffered from the same problem as its TXT counterpart, i.e. the spfdata() method only returns the first string, in presentation format. For parsing actual SPF policies, however, the behavior of the spfdata() method is both not very useful as well as incorrect: RFC 7208 states that the SPF policy is the concatenation of *all* strings in a single TXT (or SPF) resource record. So like with the txtdata() method in the TXT package, we entirely replace the spfdata() method with a correct and pure-Perl variant.
Diffstat (limited to 't')
-rw-r--r--t/rr.t17
1 files changed, 13 insertions, 4 deletions
diff --git a/t/rr.t b/t/rr.t
index a442386..fdd2bc8 100644
--- a/t/rr.t
+++ b/t/rr.t
@@ -220,10 +220,19 @@ subtest 'SRV' => sub {
};
subtest 'SPF' => sub {
- my $spf = Zonemaster::LDNS::RR->new(
- 'frobbit.se. 1127 IN SPF "v=spf1 ip4:85.30.129.185/24 mx:mail.frobbit.se ip6:2a02:80:3ffe::0/64 ~all"' );
- isa_ok( $spf, 'Zonemaster::LDNS::RR::SPF' );
- is( $spf->spfdata, '"v=spf1 ip4:85.30.129.185/24 mx:mail.frobbit.se ip6:2a02:80:3ffe::0/64 ~all"' );
+ my @data = (
+ q{frobbit.se. 1127 IN SPF "v=spf1 ip4:85.30.129.185/24 mx:mail.frobbit.se ip6:2a02:80:3ffe::0/64 ~all"},
+ q{spf.example. 3600 IN SPF "v=spf1 " "ip4:192.0.2.25/24 " "mx:mail.spf.example " "ip6:2001:db8::25/64 -all"}
+ );
+
+ my @rr = map { Zonemaster::LDNS::RR->new($_) } @data;
+ for my $spf (@rr) {
+ isa_ok( $spf, 'Zonemaster::LDNS::RR::SPF' );
+ }
+
+ is( $rr[0]->spfdata(), 'v=spf1 ip4:85.30.129.185/24 mx:mail.frobbit.se ip6:2a02:80:3ffe::0/64 ~all' );
+ is( $rr[1]->spfdata(), 'v=spf1 ip4:192.0.2.25/24 mx:mail.spf.example ip6:2001:db8::25/64 -all' );
+
};
done_testing;