From: Peter van Dijk Date: Tue, 15 Aug 2017 15:44:19 +0000 (+0200) Subject: add sortlist test X-Git-Tag: dnsdist-1.2.0~8^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2fed5be30a4b26efda4922501e888a6562d0eab7;p=pdns add sortlist test --- diff --git a/regression-tests.recursor-dnssec/recursortests.py b/regression-tests.recursor-dnssec/recursortests.py index e5d6cb327..e1192d925 100644 --- a/regression-tests.recursor-dnssec/recursortests.py +++ b/regression-tests.recursor-dnssec/recursortests.py @@ -102,6 +102,12 @@ ns1.ecs-echo.example. 3600 IN A {prefix}.21 islandofsecurity.example. 3600 IN NS ns1.islandofsecurity.example. ns1.islandofsecurity.example. 3600 IN A {prefix}.9 + +sortcname.example. 3600 IN CNAME sort +sort.example. 3600 IN A 17.38.42.80 +sort.example. 3600 IN A 192.168.0.1 +sort.example. 3600 IN A 17.238.240.5 +sort.example. 3600 IN MX 25 mx """, 'secure.example': """ secure.example. 3600 IN SOA {soa} diff --git a/regression-tests.recursor-dnssec/test_Sortlist.py b/regression-tests.recursor-dnssec/test_Sortlist.py new file mode 100644 index 000000000..79fbe43fb --- /dev/null +++ b/regression-tests.recursor-dnssec/test_Sortlist.py @@ -0,0 +1,41 @@ +import dns +from recursortests import RecursorTest + + +class testSortlist(RecursorTest): + _confdir = 'Sortlist' + + _config_template = """dnssec=off""" + _lua_config_file = """addSortList("0.0.0.0/0", + {"17.238.240.0/24", "17.138.149.200", + {"17.218.242.254", "17.218.252.254"}, + "17.38.42.80", + "17.208.240.100" })""" + + def testSortlist(self): + msg = dns.message.make_query("sortcname.example.", dns.rdatatype.ANY) + msg.flags = dns.flags.from_text('RD') + + res = self.sendUDPQuery(msg, fwparams=dict(one_rr_per_rrset=True)) + + self.assertMessageHasFlags(res, ['QR', 'RA', 'RD'], ['DO']) + self.assertRcodeEqual(res, dns.rcode.NOERROR) + + indexCNAME = -1 + indexMX = -1 + recordsA = [] + + for i, ans in enumerate(res.answer): + if ans.rdtype == dns.rdatatype.CNAME: + self.assertEqual(indexCNAME, -1) + indexCNAME = i + elif ans.rdtype == dns.rdatatype.MX: + self.assertEqual(indexMX, -1) + indexMX = i + elif ans.rdtype == dns.rdatatype.A: + recordsA.append(str(ans).split()[-1]) + + self.assertEqual(indexCNAME, 0) + self.assertGreater(indexMX, 0) + + self.assertEqual(recordsA, ['17.238.240.5', '17.38.42.80', '192.168.0.1']) \ No newline at end of file