From 48b106210b578e78115e1def114ec2192db7c557 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Mon, 30 Nov 2015 13:38:25 +0100 Subject: [PATCH] Add negative caching with dotted cnames test --- .../negcache-tests-dotted-cname/command | 21 ++++++++++++ .../negcache-tests-dotted-cname/description | 5 +++ .../example.com.zone | 14 ++++++++ .../expected_result | 7 ++++ .../negcache-tests-dotted-cname/named.conf | 9 ++++++ .../negcache-tests-dotted-cname/pipe.py | 32 +++++++++++++++++++ 6 files changed, 88 insertions(+) create mode 100755 regression-tests.nobackend/negcache-tests-dotted-cname/command create mode 100644 regression-tests.nobackend/negcache-tests-dotted-cname/description create mode 100644 regression-tests.nobackend/negcache-tests-dotted-cname/example.com.zone create mode 100644 regression-tests.nobackend/negcache-tests-dotted-cname/expected_result create mode 100644 regression-tests.nobackend/negcache-tests-dotted-cname/named.conf create mode 100755 regression-tests.nobackend/negcache-tests-dotted-cname/pipe.py diff --git a/regression-tests.nobackend/negcache-tests-dotted-cname/command b/regression-tests.nobackend/negcache-tests-dotted-cname/command new file mode 100755 index 000000000..ea8ac11fb --- /dev/null +++ b/regression-tests.nobackend/negcache-tests-dotted-cname/command @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e +set -x + +port=5501 +rm -f pdns*.pid + +$PDNS --daemon=no --local-port=$port --socket-dir=./ \ + --no-shuffle --launch=bind,pipe --bind-config=negcache-tests-dotted-cname/named.conf \ + --pipe-command=negcache-tests-dotted-cname/pipe.py \ + --send-root-referral --cache-ttl=60 --no-config --module-dir=../regression-tests/modules & + +sleep 3 + +$SDIG 127.0.0.1 5501 cname.example2.com A | LC_ALL=C sort + +# check if we didn't neg-cache .com +$SDIG 127.0.0.1 5501 www.example.com A | LC_ALL=C sort + +kill $(cat pdns*.pid) +rm pdns*.pid diff --git a/regression-tests.nobackend/negcache-tests-dotted-cname/description b/regression-tests.nobackend/negcache-tests-dotted-cname/description new file mode 100644 index 000000000..353c8b7c0 --- /dev/null +++ b/regression-tests.nobackend/negcache-tests-dotted-cname/description @@ -0,0 +1,5 @@ +This test the correct workings of DNSName in combination with negative caching. +In the pre-DNSName era, it was possible for a pipe-backend to return a CNAME +with a dot on the end. When trying to look up the target of the CNAME, PowerDNS +would negatively cache _all_ names down to that name (i.e. ., com., powerdns. +for www.powerdns.com) and send out wrong answers for all domains after that. diff --git a/regression-tests.nobackend/negcache-tests-dotted-cname/example.com.zone b/regression-tests.nobackend/negcache-tests-dotted-cname/example.com.zone new file mode 100644 index 000000000..8dfa2f64f --- /dev/null +++ b/regression-tests.nobackend/negcache-tests-dotted-cname/example.com.zone @@ -0,0 +1,14 @@ +$TTL 120 +$ORIGIN example.com. +@ 100000 IN SOA ns1.example.com. ahu.example.com. ( + 2000081501 + 8H ; refresh + 2H ; retry + 1W ; expire + 1D ; default_ttl + ) + +@ IN NS ns1.example.com. +@ IN NS ns2.example.com. + +www IN A 127.0.0.1 diff --git a/regression-tests.nobackend/negcache-tests-dotted-cname/expected_result b/regression-tests.nobackend/negcache-tests-dotted-cname/expected_result new file mode 100644 index 000000000..b0a962af8 --- /dev/null +++ b/regression-tests.nobackend/negcache-tests-dotted-cname/expected_result @@ -0,0 +1,7 @@ +0 cname.example2.com. IN CNAME 3600 www.example.com. +0 www.example.com. IN A 120 127.0.0.1 +Rcode: 0 (No Error), RD: 0, QR: 1, TC: 0, AA: 1, opcode: 0 +Reply to question for qname='cname.example2.com.', qtype=A +0 www.example.com. IN A 120 127.0.0.1 +Rcode: 0 (No Error), RD: 0, QR: 1, TC: 0, AA: 1, opcode: 0 +Reply to question for qname='www.example.com.', qtype=A diff --git a/regression-tests.nobackend/negcache-tests-dotted-cname/named.conf b/regression-tests.nobackend/negcache-tests-dotted-cname/named.conf new file mode 100644 index 000000000..da863379c --- /dev/null +++ b/regression-tests.nobackend/negcache-tests-dotted-cname/named.conf @@ -0,0 +1,9 @@ +options { + directory "negcache-tests-dotted-cname"; + version "Meow!Meow!"; +}; + +zone "example.com" { + type master; + file "example.com.zone"; +}; diff --git a/regression-tests.nobackend/negcache-tests-dotted-cname/pipe.py b/regression-tests.nobackend/negcache-tests-dotted-cname/pipe.py new file mode 100755 index 000000000..c12cdd4bf --- /dev/null +++ b/regression-tests.nobackend/negcache-tests-dotted-cname/pipe.py @@ -0,0 +1,32 @@ +#!/usr/bin/python2 -u + +import sys + +line = sys.stdin.readline() +# TOLO +print 'OK\tTest backend firing up' + +while True: + line = sys.stdin.readline() + items = line.split('\t') + sys.stderr.write(line) + if len(items) < 6: + print 'LOG\tGot an unparsable line' + print 'LOG\t%s' % line + print 'END' + continue + + what, qname, qclass, qtype, id, ip = items + + if qtype in ['SOA', 'ANY'] and qname == 'example2.com': + print 'DATA\t%s\t%s\tSOA\t300\t-1\tns1.example.com ahu.example.com 2008080300 1800 3600 604800 3600' % (qname, qclass) + + if qtype in ['NS', 'ANY'] and qname == 'example2.com': + print 'DATA\t%s\t%s\tNS\t3600\t-1\tns1.example.com' % (qname, qclass) + print 'DATA\t%s\t%s\tNS\t3600\t-1\tns2.example.com' % (qname, qclass) + + if qtype in ['A', 'ANY'] and qname.endswith('example2.com'): + # We were asked a specific record + print 'DATA\t%s\t%s\tCNAME\t3600\t-1\twww.example.com.' % (qname, qclass) + + print 'END' -- 2.40.0