From: Pieter Lexis Date: Fri, 12 Feb 2021 12:34:31 +0000 (+0100) Subject: Add some SVCB tests X-Git-Tag: dnsdist-1.6.0-rc1~33^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e69049f6a2e7cb69021b2a5da140b8595a83b15;p=thirdparty%2Fpdns.git Add some SVCB tests --- diff --git a/regression-tests.auth-py/authtests.py b/regression-tests.auth-py/authtests.py index 14a51f6919..7c8564f706 100644 --- a/regression-tests.auth-py/authtests.py +++ b/regression-tests.auth-py/authtests.py @@ -420,6 +420,30 @@ options { if not found : raise AssertionError("RRset not found in answer\n\n%s" % ret) + def assertRRsetInAdditional(self, msg, rrset): + """Asserts the rrset (without comparing TTL) exists in the + additional section of msg + + @param msg: the dns.message.Message to check + @param rrset: a dns.rrset.RRset object""" + + ret = '' + if not isinstance(msg, dns.message.Message): + raise TypeError("msg is not a dns.message.Message") + + if not isinstance(rrset, dns.rrset.RRset): + raise TypeError("rrset is not a dns.rrset.RRset") + + found = False + for ans in msg.additional: + ret += "%s\n" % ans.to_text() + if ans.match(rrset.name, rrset.rdclass, rrset.rdtype, 0, None): + self.assertEqual(ans, rrset, "'%s' != '%s'" % (ans.to_text(), rrset.to_text())) + found = True + + if not found : + raise AssertionError("RRset not found in answer\n\n%s" % ret) + def sortRRsets(self, rrsets): """Sorts RRsets in a more useful way than dnspython's default behaviour diff --git a/regression-tests.auth-py/test_SVCB.py b/regression-tests.auth-py/test_SVCB.py new file mode 100644 index 0000000000..7ab4569725 --- /dev/null +++ b/regression-tests.auth-py/test_SVCB.py @@ -0,0 +1,86 @@ +from authtests import AuthTest +import dns + + +class TestSVCBRecords(AuthTest): + _config_template = """ +launch=bind +""" + + _zones = { + 'example.org': """ +example.org. 3600 IN SOA {soa} +example.org. 3600 IN NS ns1.example.org. +example.org. 3600 IN NS ns2.example.org. + +example.org. 3600 IN HTTPS 0 www.example.org. +www.example.org. 3600 IN HTTPS 1 . ipv4hint=auto ipv6hint=auto +www.example.org. 3600 IN A 192.0.2.80 +www.example.org. 3600 IN AAAA 2001:db8::80 + +no-a.example.org. 3600 IN HTTPS 1 . ipv4hint=auto ipv6hint=auto +no-a.example.org. 3600 IN AAAA 2001:db8::81 + +no-aaaa.example.org. 3600 IN HTTPS 1 . ipv4hint=auto ipv6hint=auto +no-aaaa.example.org. 3600 IN A 192.0.2.81 + """, + } + + def testWithoutAlias(self): + query = dns.message.make_query('www.example.org', 'HTTPS') + res = self.sendUDPQuery(query) + expected_ans = dns.rrset.from_text( + 'www.example.org.', 3600, dns.rdataclass.IN, 'HTTPS', + '1 . ipv4hint="192.0.2.80" ipv6hint="2001:db8::80"' + ) + self.assertRcodeEqual(res, dns.rcode.NOERROR) + self.assertRRsetInAnswer(res, expected_ans) + self.assertEqual(len(res.additional), 2) + + def testWithAlias(self): + """ + Ensure additional processing happens for HTTPS AliasMode + """ + query = dns.message.make_query('example.org', 'HTTPS') + res = self.sendUDPQuery(query) + expected_addl = dns.rrset.from_text( + 'www.example.org.', 3600, dns.rdataclass.IN, 'HTTPS', + '1 . ipv4hint="192.0.2.80" ipv6hint="2001:db8::80"' + ) + expected_ans = dns.rrset.from_text( + 'example.org.', 3600, dns.rdataclass.IN, 'HTTPS', + '0 www.example.org' + ) + print(res.answer) + self.assertRcodeEqual(res, dns.rcode.NOERROR) + self.assertRRsetInAnswer(res, expected_ans) + self.assertRRsetInAdditional(res, expected_addl) + self.assertEqual(len(res.additional), 3) + + def testWithMissingA(self): + """ + Ensure PowerDNS removes the ipv4hint if there's no A record + """ + query = dns.message.make_query('no-a.example.org', 'HTTPS') + res = self.sendUDPQuery(query) + expected_ans = dns.rrset.from_text( + 'no-a.example.org.', 3600, dns.rdataclass.IN, 'HTTPS', + '1 . ipv6hint="2001:db8::81"' + ) + self.assertRcodeEqual(res, dns.rcode.NOERROR) + self.assertRRsetInAnswer(res, expected_ans) + self.assertEqual(len(res.additional), 1) + + def testWithMissingAAAA(self): + """ + Ensure PowerDNS removes the ipv6hint if there's no AAAA record + """ + query = dns.message.make_query('no-aaaa.example.org', 'HTTPS') + res = self.sendUDPQuery(query) + expected_ans = dns.rrset.from_text( + 'no-aaaa.example.org.', 3600, dns.rdataclass.IN, 'HTTPS', + '1 . ipv4hint="192.0.2.81"' + ) + self.assertRcodeEqual(res, dns.rcode.NOERROR) + self.assertRRsetInAnswer(res, expected_ans) + self.assertEqual(len(res.additional), 1)