]> granicus.if.org Git - pdns/commitdiff
add sortlist test
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 15 Aug 2017 15:44:19 +0000 (17:44 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 15 Aug 2017 15:44:19 +0000 (17:44 +0200)
regression-tests.recursor-dnssec/recursortests.py
regression-tests.recursor-dnssec/test_Sortlist.py [new file with mode: 0644]

index e5d6cb32703b67cc1bdc9576355e58b5d1d247de..e1192d92594a49a93a05145a8adc45019b06c4d9 100644 (file)
@@ -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 (file)
index 0000000..79fbe43
--- /dev/null
@@ -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