From cd5b9e686657ebf9b296015f137a82b976dcfd91 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Wed, 11 Dec 2024 15:04:07 +0100 Subject: [PATCH] Extend the SVCB tests to also test with lmdb backend. --- regression-tests.auth-py/test_SVCB.py | 156 ++++++++++++++++++++++++-- 1 file changed, 147 insertions(+), 9 deletions(-) diff --git a/regression-tests.auth-py/test_SVCB.py b/regression-tests.auth-py/test_SVCB.py index 7bb10ac4ce..12f35c4b67 100644 --- a/regression-tests.auth-py/test_SVCB.py +++ b/regression-tests.auth-py/test_SVCB.py @@ -1,10 +1,23 @@ from authtests import AuthTest import dns +import os +import subprocess +class SVCBRecordsBase(AuthTest): + # Copied from AuthTest, without the bind-config and bind-dnssec fields. + _config_template_default = """ +module-dir={PDNS_MODULE_DIR} +daemon=no +socket-dir={confdir} +cache-ttl=0 +negquery-cache-ttl=0 +query-cache-ttl=0 +log-dns-queries=yes +log-dns-details=yes +loglevel=9 +distributor-threads=1""" -class TestSVCBRecords(AuthTest): _config_template = """ -launch=bind svc-autohints """ @@ -39,7 +52,7 @@ auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80 """, } - def testWithoutAlias(self): + def impl_testWithoutAlias(self): query = dns.message.make_query('www.example.org', 'HTTPS') res = self.sendUDPQuery(query) expected_ans = dns.rrset.from_text( @@ -50,7 +63,7 @@ auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80 self.assertRRsetInAnswer(res, expected_ans) self.assertEqual(len(res.additional), 2) - def testWithAlias(self): + def impl_testWithAlias(self): """ Ensure additional processing happens for HTTPS AliasMode """ @@ -70,7 +83,7 @@ auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80 self.assertRRsetInAdditional(res, expected_addl) self.assertEqual(len(res.additional), 3) - def testWithMissingA(self): + def impl_testWithMissingA(self): """ Ensure PowerDNS removes the ipv4hint if there's no A record """ @@ -84,7 +97,7 @@ auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80 self.assertRRsetInAnswer(res, expected_ans) self.assertEqual(len(res.additional), 1) - def testWithMissingAAAA(self): + def impl_testWithMissingAAAA(self): """ Ensure PowerDNS removes the ipv6hint if there's no AAAA record """ @@ -98,7 +111,7 @@ auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80 self.assertRRsetInAnswer(res, expected_ans) self.assertEqual(len(res.additional), 1) - def testNoAuto(self): + def impl_testNoAuto(self): """ Ensure we send the actual hints, not generated ones """ @@ -113,7 +126,7 @@ auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80 self.assertRRsetInAnswer(res, expected_ans) self.assertEqual(len(res.additional), 2) - def testAutoA(self): + def impl_testAutoA(self): """ Ensure we send a generated A hint, but keep the existing AAAA hint """ @@ -128,7 +141,7 @@ auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80 self.assertRRsetInAnswer(res, expected_ans) self.assertEqual(len(res.additional), 2) - def testAutoAAAA(self): + def impl_testAutoAAAA(self): """ Ensure we send a generated AAAA hint, but keep the existing A hint """ @@ -142,3 +155,128 @@ auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80 print(res) self.assertRRsetInAnswer(res, expected_ans) self.assertEqual(len(res.additional), 2) + +class TestSVCBRecordsBind(SVCBRecordsBase): + _config_template_default = ( + SVCBRecordsBase._config_template_default + + """ +bind-config={confdir}/named.conf +bind-dnssec-db={bind_dnssec_db} +""" + ) + + _config_template = ( + SVCBRecordsBase._config_template + + """ +launch=bind +""" + ) + + def testWithoutAlias(self): + self.impl_testWithoutAlias() + + def testWithAlias(self): + """ + Ensure additional processing happens for HTTPS AliasMode + """ + self.impl_testWithAlias() + + def testWithMissingA(self): + """ + Ensure PowerDNS removes the ipv4hint if there's no A record + """ + self.impl_testWithMissingA() + + def testWithMissingAAAA(self): + """ + Ensure PowerDNS removes the ipv6hint if there's no AAAA record + """ + self.impl_testWithMissingAAAA() + + def testNoAuto(self): + """ + Ensure we send the actual hints, not generated ones + """ + self.impl_testNoAuto() + + def testAutoA(self): + """ + Ensure we send a generated A hint, but keep the existing AAAA hint + """ + self.impl_testAutoA() + + def testAutoAAAA(self): + """ + Ensure we send a generated AAAA hint, but keep the existing A hint + """ + self.impl_testAutoAAAA() + +class TestSVCBRecordsLMDB(SVCBRecordsBase): + _config_template = ( + SVCBRecordsBase._config_template + + """ +launch=lmdb +""" + ) + + @classmethod + def generateAllAuthConfig(cls, confdir): + # This is very similar to AuthTest.generateAllAuthConfig, + # but for lmdb backend, we ignore auth keys but need to load-zone + # into lmdb storage. + cls.generateAuthConfig(confdir) + + for zonename, zonecontent in cls._zones.items(): + cls.generateAuthZone(confdir, + zonename, + zonecontent) + pdnsutilCmd = [os.environ['PDNSUTIL'], + '--config-dir=%s' % confdir, + 'load-zone', + zonename, + os.path.join(confdir, '%s.zone' % zonename)] + + print(' '.join(pdnsutilCmd)) + try: + subprocess.check_output(pdnsutilCmd, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + raise AssertionError('%s failed (%d): %s' % (pdnsutilCmd, e.returncode, e.output)) + + def testWithoutAlias(self): + self.impl_testWithoutAlias() + + def testWithAlias(self): + """ + Ensure additional processing happens for HTTPS AliasMode + """ + self.impl_testWithAlias() + + def testWithMissingA(self): + """ + Ensure PowerDNS removes the ipv4hint if there's no A record + """ + self.impl_testWithMissingA() + + def testWithMissingAAAA(self): + """ + Ensure PowerDNS removes the ipv6hint if there's no AAAA record + """ + self.impl_testWithMissingAAAA() + + def testNoAuto(self): + """ + Ensure we send the actual hints, not generated ones + """ + self.impl_testNoAuto() + + def testAutoA(self): + """ + Ensure we send a generated A hint, but keep the existing AAAA hint + """ + self.impl_testAutoA() + + def testAutoAAAA(self): + """ + Ensure we send a generated AAAA hint, but keep the existing A hint + """ + self.impl_testAutoAAAA() -- 2.47.2