From 0b34df85b0c1192d8112e7f191873fd53ba400f3 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 30 Jun 2025 13:37:20 +0200 Subject: [PATCH] dnsdist: Add a regression test for `getObjectFromYAMLConfiguration` Signed-off-by: Remi Gacogne (cherry picked from commit 80f292fc5d96ab59afea63aaf8323267081b9114) Signed-off-by: Remi Gacogne --- regression-tests.dnsdist/test_Console.py | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/regression-tests.dnsdist/test_Console.py b/regression-tests.dnsdist/test_Console.py index ff55c36f66..e8a5b95594 100644 --- a/regression-tests.dnsdist/test_Console.py +++ b/regression-tests.dnsdist/test_Console.py @@ -1,5 +1,6 @@ #!/usr/bin/env python import base64 +import cdbx import dns import os import socket @@ -118,3 +119,56 @@ class TestConsoleConcurrentConnections(DNSDistTest): # this should work version = self.sendConsoleCommand('showVersion()') self.assertTrue(version.startswith('dnsdist ')) + +def writeCDB(fname, variant=1): + cdb = cdbx.CDB.make(fname+'.tmp') + cdb.add(socket.inet_aton(f'127.0.0.{variant}'), b'this is the value of the source address tag') + cdb.add(b'\x05qname\x03cdb\x05tests\x08powerdns\x03com\x00', b'this is the value of the qname tag') + cdb.add(b'\x06suffix\x03cdb\x05tests\x08powerdns\x03com\x00', b'this is the value of the suffix tag') + cdb.add(b'this is the value of the qname tag', b'this is the value of the second tag') + cdb.commit().close() + os.rename(fname+'.tmp', fname) + cdb.close() + +class TestConsoleAccessObjectsFromYAML(DNSDistTest): + + _consoleKey = DNSDistTest.generateConsoleKey() + _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') + + _cdbFileName = '/tmp/test-cdb-db' + + _yaml_config_template = """ +console: + key: "%s" + listen_address: "127.0.0.1:%d" + acl: + - 127.0.0.0/8 +key_value_stores: + cdb: + - name: "cdb-kvs" + file_name: "%s" + refresh_delay: 1 +""" + _yaml_config_params = ['_consoleKeyB64', '_consolePort', '_cdbFileName'] + _config_params = [] + + @classmethod + def setUpCDB(cls): + writeCDB(cls._cdbFileName, 1) + + @classmethod + def setUpClass(cls): + + cls.setUpCDB() + cls.startResponders() + cls.startDNSDist() + cls.setUpSockets() + + def testConsoleCanAccessYamlObject(self): + """ + Console: Check that we can access Yaml-defined objects + """ + cdb = self.sendConsoleCommand("getObjectFromYAMLConfiguration('cdb-kvs')") + self.assertTrue(cdb.startswith('Command returned an object we can\'t print: Trying to cast a lua variable from "userdata" to')) + got = self.sendConsoleCommand("if getObjectFromYAMLConfiguration('cdb-kvs'):reload() then return 'reloading worked' else return 'reloading failed' end") + self.assertEqual(got, 'reloading worked\n') -- 2.47.3