]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add some SVCB tests
authorPieter Lexis <pieter.lexis@powerdns.com>
Fri, 12 Feb 2021 12:34:31 +0000 (13:34 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Mon, 29 Mar 2021 17:10:32 +0000 (19:10 +0200)
regression-tests.auth-py/authtests.py
regression-tests.auth-py/test_SVCB.py [new file with mode: 0644]

index 14a51f6919ee02ab18c8a4d58c39ec47e9be2c62..7c8564f7064be05c4cf9f9908e0efc107ebdc748 100644 (file)
@@ -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 (file)
index 0000000..7ab4569
--- /dev/null
@@ -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)