]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth-py tests: allow backend choice, add lmdb testing 15567/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 9 May 2025 18:05:13 +0000 (20:05 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 22 May 2025 08:30:00 +0000 (10:30 +0200)
15 files changed:
regression-tests.auth-py/authtests.py
regression-tests.auth-py/test_ALIAS.py
regression-tests.auth-py/test_AnyBind.py
regression-tests.auth-py/test_Carbon.py
regression-tests.auth-py/test_Cookies.py
regression-tests.auth-py/test_DirectDNSKEYSignature.py
regression-tests.auth-py/test_GSSTSIG.py
regression-tests.auth-py/test_IXFR.py
regression-tests.auth-py/test_LuaRecords.py
regression-tests.auth-py/test_LuaRecordsLMDB.py
regression-tests.auth-py/test_ProxyProtocol.py
regression-tests.auth-py/test_ResolveAcrossZones.py
regression-tests.auth-py/test_SVCB.py
regression-tests.auth-py/test_XFRIncomplete.py
tasks.py

index 9e9e9c999e65c356b1c2be8473b8ea03b2c29745..03c08fb33efbf8cc0c8a91058cc07ecd18c0f143 100644 (file)
@@ -24,13 +24,20 @@ class AuthTest(AssertEqualDNSMessageMixin, unittest.TestCase):
     _confdir = 'auth'
     _authPort = 5300
 
+    _backend = os.getenv("AUTH_BACKEND", "bind")
+
+    _backend_configs = dict(
+        bind="""
+bind-config={confdir}/named.conf
+bind-dnssec-db={bind_dnssec_db}
+""",    lmdb="",
+        gsqlite3="")
+
     _config_params = []
 
     _config_template_default = """
 module-dir={PDNS_MODULE_DIR}
 daemon=no
-bind-config={confdir}/named.conf
-bind-dnssec-db={bind_dnssec_db}
 socket-dir={confdir}
 cache-ttl=0
 negquery-cache-ttl=0
@@ -117,25 +124,33 @@ options {
         params = tuple([getattr(cls, param) for param in cls._config_params])
 
         with open(os.path.join(confdir, 'pdns.conf'), 'w') as pdnsconf:
-            pdnsconf.write(cls._config_template_default.format(
-                confdir=confdir, prefix=cls._PREFIX,
-                bind_dnssec_db=bind_dnssec_db,
-                PDNS_MODULE_DIR=cls._PDNS_MODULE_DIR,
-            ))
-            pdnsconf.write(cls._config_template % params)
+            args = dict(backend=cls._backend,
+                        confdir=confdir,
+                        prefix=cls._PREFIX,
+                        bind_dnssec_db=bind_dnssec_db,
+                        PDNS_MODULE_DIR=cls._PDNS_MODULE_DIR
+                        )
 
-        os.system("sqlite3 ./configs/auth/powerdns.sqlite < ../modules/gsqlite3backend/schema.sqlite3.sql")
+            pdnsconf.write((cls._config_template_default + cls._backend_configs[cls._backend]).format(**args))
+            pdnsconf.write(cls._config_template.format(**args) % params)
 
-        pdnsutilCmd = [os.environ['PDNSUTIL'],
-                       '--config-dir=%s' % confdir,
-                       'create-bind-db',
-                       bind_dnssec_db]
+        if cls._backend == 'gsqlite3':
+            os.system("sqlite3 ./configs/auth/powerdns.sqlite < ../modules/gsqlite3backend/schema.sqlite3.sql")
 
-        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))
+        if cls._backend == 'lmdb':
+            os.system("rm -f pdns.lmdb*")
+
+        if cls._backend == 'bind':
+            pdnsutilCmd = [os.environ['PDNSUTIL'],
+                           '--config-dir=%s' % confdir,
+                           'create-bind-db',
+                           bind_dnssec_db]
+
+            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))
 
     @classmethod
     def secureZone(cls, confdir, zonename, key=None):
@@ -167,14 +182,40 @@ options {
     @classmethod
     def generateAllAuthConfig(cls, confdir):
         cls.generateAuthConfig(confdir)
-        cls.generateAuthNamedConf(confdir, cls._zones.keys())
-
-        for zonename, zonecontent in cls._zones.items():
-            cls.generateAuthZone(confdir,
-                                 zonename,
-                                 zonecontent)
-            if cls._zone_keys.get(zonename, None):
-                cls.secureZone(confdir, zonename, cls._zone_keys.get(zonename))
+
+        if cls._backend == 'bind':
+            cls.generateAuthNamedConf(confdir, cls._zones.keys())
+
+            for zonename, zonecontent in cls._zones.items():
+                cls.generateAuthZone(confdir,
+                                     zonename,
+                                     zonecontent)
+                if cls._zone_keys.get(zonename, None):
+                    cls.secureZone(confdir, zonename, cls._zone_keys.get(zonename))
+        elif cls._backend == 'lmdb':
+            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))
+                if cls._zone_keys.get(zonename, None):
+                    cls.secureZone(confdir, zonename, cls._zone_keys.get(zonename))
+        elif cls._backend == 'gsqlite3':
+            # this is not a supported config from the user, but some of the test_*.py files use gsqlite3
+            return
+        else:
+            raise RuntimeError("unknown backend " + cls._backend + " specified")
+
 
     @classmethod
     def waitForTCPSocket(cls, ipaddress, port):
index 8cd7f4f3deb7e67c96bb57fb52c8d6c56dbf9bfc..441ffa49e4026c14ed60d26d6bb30265635c69d0 100644 (file)
@@ -20,7 +20,7 @@ class TestALIAS(AuthTest):
 expand-alias=yes
 resolver=%s.1:5301
 any-to-tcp=no
-launch=bind
+launch={backend}
 edns-subnet-processing=yes
 """
 
index e0b6c4c8a5a572c07690c7809a8e3c75d6c11ddf..1b85f3ebeb59d188d446860ade4d573ab3e2f6a7 100644 (file)
@@ -8,7 +8,7 @@ from authtests import AuthTest
 
 class TestBindAny(AuthTest):
     _config_template = """
-launch=bind
+launch={backend}
 """
 
     _zones = {
index 6718b15ad5ca3c8ddc9ca75d98d1a99cf8f4cbe3..41b53cf67f97d17d9770c03fca69536668f82fce 100644 (file)
@@ -19,7 +19,7 @@ class TestCarbon(AuthTest):
     _carbonQueue2 = Queue()
     _carbonCounters = {}
     _config_template = """
-    launch=bind
+    launch={backend}
     carbon-namespace=%s
     carbon-instance=%s
     carbon-interval=%s
index ba67da89782858ddd29f85305bd30a19326f68f1..ac85c3312b0eac2fa943ef57ed1c9497e2e0f83e 100644 (file)
@@ -6,7 +6,7 @@ from authtests import AuthTest
 
 class TestEdnsCookies(AuthTest):
     _config_template = """
-launch=bind
+launch={backend}
 edns-cookie-secret=aabbccddeeff11223344556677889900
 """
 
index bb63eda2a6046dc8ed5ec06474cb4844b23e7075..b11a641ab5afefdb0ebd1f35bb766ab542af5b8e 100644 (file)
@@ -7,7 +7,7 @@ from authtests import AuthTest
 
 class TestDirectDNSKEYSignature(AuthTest):
     _config_template = """
-    launch=bind
+    launch={backend}
     direct-dnskey=yes
     direct-dnskey-signature=yes
     """
index d7da3f45dd38a60953c6ba4c2134dd1b449e5774..78e6d3b1ef40bf518ab9e2a24f68c4bd64b4a907 100644 (file)
@@ -7,6 +7,8 @@ from authtests import AuthTest
 
 
 class GSSTSIGBase(AuthTest):
+    _backend = 'gsqlite3'
+
     _config_template_default = """
 module-dir={PDNS_MODULE_DIR}
 daemon=no
index 6247dc04b72eae1c30aa6d43e687b640c1267efe..daaef1ca1d676518c6e40a9cc7963b16b8cdf6da 100644 (file)
@@ -59,8 +59,10 @@ xfrServerPort = 4244
 xfrServer = AXFRServer(xfrServerPort, zones)
 
 class TestIXFR(AuthTest):
+    _backend = 'gsqlite3'
+
     _config_template = """
-launch=gsqlite3 bind
+launch=gsqlite3
 gsqlite3-database=configs/auth/powerdns.sqlite
 gsqlite3-dnssec
 secondary
index a8df4b25c9560cd1b6a93792ac79b7ff7846b160..6ea2ef1622842fd1bf2416269c8961be9f2f9837 100644 (file)
@@ -42,7 +42,7 @@ class BaseLuaTest(AuthTest):
     _config_template = """
 geoip-database-files=../modules/geoipbackend/regression-tests/GeoLiteCity.mmdb
 edns-subnet-processing=yes
-launch=bind geoip
+launch={backend} geoip
 any-to-tcp=no
 enable-lua-records
 lua-records-insert-whitespace=yes
@@ -1245,7 +1245,7 @@ class TestLuaRecordsShared(TestLuaRecords):
     _config_template = """
 geoip-database-files=../modules/geoipbackend/regression-tests/GeoLiteCity.mmdb
 edns-subnet-processing=yes
-launch=bind geoip
+launch={backend} geoip
 any-to-tcp=no
 enable-lua-records=shared
 lua-records-insert-whitespace=yes
@@ -1268,7 +1268,7 @@ class TestLuaRecordsNoWhiteSpace(TestLuaRecords):
     _config_template = """
 geoip-database-files=../modules/geoipbackend/regression-tests/GeoLiteCity.mmdb
 edns-subnet-processing=yes
-launch=bind geoip
+launch={backend} geoip
 any-to-tcp=no
 enable-lua-records
 lua-records-insert-whitespace=no
@@ -1284,7 +1284,7 @@ class TestLuaRecordsSlowTimeouts(BaseLuaTest):
     _config_template = """
 geoip-database-files=../modules/geoipbackend/regression-tests/GeoLiteCity.mmdb
 edns-subnet-processing=yes
-launch=bind geoip
+launch={backend} geoip
 any-to-tcp=no
 enable-lua-records
 lua-records-insert-whitespace=yes
@@ -1412,7 +1412,7 @@ class TestLuaRecordsExecLimit(BaseLuaTest):
     _config_template = """
 geoip-database-files=../modules/geoipbackend/regression-tests/GeoLiteCity.mmdb
 edns-subnet-processing=yes
-launch=bind geoip
+launch={backend} geoip
 any-to-tcp=no
 enable-lua-records
 lua-records-insert-whitespace=yes
index 942dd3d94630a50e2895929e84d11ec09a9bbe59..633704da4735aa350feeccb13cee230d6a4fa932 100644 (file)
@@ -7,18 +7,7 @@ import subprocess
 from authtests import AuthTest
 
 class TestLuaRecordsLMDB(AuthTest):
-    # Copied from AuthTest, without the bind-config and bind-dnssec fields,
-    # since these tests target LMDB an a backend.
-    _config_template_default = """
-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"""
+    _backend = 'lmdb'
 
     _config_template = """
 launch=lmdb
@@ -45,29 +34,6 @@ nested-lua.example.org.      3600 IN LUA  A   ( ";include('config') "
         """
     }
 
-    @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 testPickRandomWithNestedLua(self):
         """
         Basic pickrandom() test with a set of A records, with a bit of lua inclusion
index 60127f22ffe5833ecd4ba036d739a78802354bd5..8a03ab4844dbd73ba23614261e91707fd0377bab 100644 (file)
@@ -3,6 +3,7 @@ import dns
 import os
 import socket
 import struct
+import subprocess
 import threading
 import time
 import unittest
@@ -12,7 +13,7 @@ from proxyprotocol import ProxyProtocol
 
 class TestProxyProtocolLuaRecords(AuthTest):
     _config_template = """
-launch=bind
+launch={backend}
 any-to-tcp=no
 proxy-protocol-from=127.0.0.1
 enable-lua-records
@@ -113,16 +114,18 @@ myip.example.org.            3600 IN LUA  TXT     "who:toString()..'/'..bestwho:
 
 class TestProxyProtocolNOTIFY(AuthTest):
     _config_template = """
-launch=bind
+launch={backend}
 any-to-tcp=no
 proxy-protocol-from=127.0.0.1
 secondary
 """
 
-    _zones = { 'example.org': '192.0.2.1',
+    _secondary_zones = { 'example.org': '192.0.2.1',
                'example.com': '192.0.2.2'
     }
 
+    _zones = {}
+
     @classmethod
     def generateAuthZone(cls, confdir, zonename, zonecontent):
         try:
@@ -130,6 +133,23 @@ secondary
         except:
             pass
 
+    @classmethod
+    def generateAuthConfig(cls, confdir):
+        super(TestProxyProtocolNOTIFY, cls).generateAuthConfig(confdir)
+        if cls._backend == 'lmdb':
+            for zonename in cls._secondary_zones:
+                pdnsutilCmd = [os.environ['PDNSUTIL'],
+                   '--config-dir=%s' % confdir,
+                   'create-secondary-zone',
+                   zonename,
+                   cls._secondary_zones[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))
+
     @classmethod
     def generateAuthNamedConf(cls, confdir, zones):
         with open(os.path.join(confdir, 'named.conf'), 'w') as namedconf:
@@ -137,7 +157,7 @@ secondary
 options {
     directory "%s";
 };""" % confdir)
-            for zonename in zones:
+            for zonename in cls._secondary_zones:
                 zone = '.' if zonename == 'ROOT' else zonename
 
                 namedconf.write("""
@@ -145,7 +165,7 @@ options {
             type secondary;
             file "%s.zone";
             masters { %s; };
-        };""" % (zone, zonename, cls._zones[zone]))
+        };""" % (zone, zonename, cls._secondary_zones[zone]))
 
 
     @classmethod
@@ -187,7 +207,7 @@ options {
 
 class TestProxyProtocolAXFRACL(AuthTest):
     _config_template = """
-launch=bind
+launch={backend}
 any-to-tcp=no
 proxy-protocol-from=127.0.0.1
 allow-axfr-ips=192.0.2.53
index 00207ef54c98a837e27617015757bdb49040ae5f..7d753e3a119438c8677a41f4cd293ce5082ad2b1 100644 (file)
@@ -10,7 +10,7 @@ from authtests import AuthTest
 class CrossZoneResolveBase(AuthTest):
     _config_template = """
 any-to-tcp=no
-launch=bind
+launch={backend}
 edns-subnet-processing=yes
 """
     target_otherzone_ip = "192.0.2.2"
index 12f35c4b6719054d4759bed1285e7347e31a28da..db4ea8bb908f5282593f1666ccad809da964a062 100644 (file)
@@ -4,19 +4,6 @@ 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"""
-
     _config_template = """
 svc-autohints
 """
@@ -157,6 +144,8 @@ auto-aaaa.example.org.       3600 IN AAAA 2001:db8::80
         self.assertEqual(len(res.additional), 2)
 
 class TestSVCBRecordsBind(SVCBRecordsBase):
+    _backend = "bind"
+
     _config_template_default = (
         SVCBRecordsBase._config_template_default
         + """
@@ -168,7 +157,7 @@ bind-dnssec-db={bind_dnssec_db}
     _config_template = (
         SVCBRecordsBase._config_template
         + """
-launch=bind
+launch={backend}
 """
     )
 
@@ -212,6 +201,8 @@ launch=bind
         self.impl_testAutoAAAA()
 
 class TestSVCBRecordsLMDB(SVCBRecordsBase):
+    _backend='lmdb'
+
     _config_template = (
         SVCBRecordsBase._config_template
         + """
index 3db145e293f155a460a6b25bf8cbbec8f624b707..efe10059d0e80a5663c6dce3cc1020ea1d85ec18 100644 (file)
@@ -140,8 +140,11 @@ class XFRIncompleteAuthTest(AuthTest):
     """
 
     global badxfrServerPort
+
+    _backend = 'gsqlite3'
+
     _config_template = """
-launch=gsqlite3 bind
+launch=gsqlite3
 gsqlite3-database=configs/auth/powerdns.sqlite
 gsqlite3-dnssec
 secondary
index 47a6fa5b5fe255e88ba95a2b9fe42ce8707f7798..049770f37fee6736998397568a25d4884534124d 100644 (file)
--- a/tasks.py
+++ b/tasks.py
@@ -1114,8 +1114,9 @@ def test_auth_backend(c, backend):
 
     if backend == 'authpy':
         c.sudo(f'sh -c \'echo "{auth_backend_ip_addr} kerberos-server" | tee -a /etc/hosts\'')
-        with c.cd('regression-tests.auth-py'):
-            c.run(f'{pdns_auth_env_vars} WITHKERBEROS=YES ./runtests')
+        for auth_backend in ('bind', 'lmdb'):
+            with c.cd('regression-tests.auth-py'):
+                c.run(f'{pdns_auth_env_vars} AUTH_BACKEND={auth_backend} WITHKERBEROS=YES ./runtests')
         return
 
     if backend == 'bind':