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}
--- /dev/null
+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