diff options
author | Marc van der Wal <marc.vanderwal@afnic.fr> | 2022-10-06 14:09:44 +0200 |
---|---|---|
committer | Marc van der Wal <marc.vanderwal@afnic.fr> | 2022-10-12 15:11:36 +0200 |
commit | ef0a666ee5b71ce029c61fc683bfbfeadd7d9f02 (patch) | |
tree | 167031f5c125e1d7f58dcee3d27de45d4e176afc /t | |
parent | b545a9fc10a70dc5370ea04950d4bb5fbe390f60 (diff) |
Improve access to text data in TXT records
So far, there has been no real elegant way of accessing the data in DNS
TXT records.
The only existing method, txtdata(), is implemented in XS code and has
several issues. Firstly, it only returns the first string of the TXT
record. Secondly, it returns that string in presentation format, that
is, it returns a string which itself has surrounding quotes and
contains decimal escapes for non-printable characters.
This incorrect implementation is replaced with one in pure
Perl. Normally, the only correct abstraction for TXT resource records is
a list of strings. But for some use cases, such as SPF, DKIM and DMARC,
the TXT record data ought to be treated as a single long string, which
is the concatenation of all the strings in the TXT resource record data,
without adding any spaces between consecutive strings.
To my knowledge, there is no need to access the actual list of strings
in the resource record data. This function could easily be made
context-sensitive (e.g. by returning the list of strings in list
context) if need be.
This commit is also an excellent opportunity to rewrite the unit test
for TXT resource records. The previous version needed Internet
connectivity, but this new version can be run offline.
Diffstat (limited to 't')
-rw-r--r-- | t/rr.t | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -77,18 +77,18 @@ subtest 'AAAA' => sub { }; subtest 'TXT' => sub { - SKIP: { - skip 'no network', 1 unless $ENV{TEST_WITH_NETWORK}; - - my $se = Zonemaster::LDNS->new( '192.36.144.107' ); - my $pt = $se->query( 'se', 'TXT' ); - plan skip_all => 'No response, cannot test' if not $pt; - - foreach my $rr ( $pt->answer ) { - isa_ok( $rr, 'Zonemaster::LDNS::RR::TXT' ); - like( $rr->txtdata, qr/^"SE zone update: / ); - } + my @data = ( + q{txt.test. 3600 IN TXT "Handling TXT RRs can be challenging"}, + q{txt.test. 3600 IN TXT "because " "the data can " "be spl" "it up like " "this!"} + ); + my @rrs = map { Zonemaster::LDNS::RR->new($_) } @data; + + foreach my $rr ( @rrs ) { + isa_ok( $rr, 'Zonemaster::LDNS::RR::TXT' ); } + + is( $rrs[0]->txtdata(), q{Handling TXT RRs can be challenging} ); + is( $rrs[1]->txtdata(), q{because the data can be split up like this!} ); }; subtest 'DNSKEY' => sub { |