From: Remi Gacogne Date: Fri, 11 Jul 2025 10:30:41 +0000 (+0200) Subject: dnsdist: Test accessing the rings via the console X-Git-Tag: rec-5.4.0-alpha0~26^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F15826%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Test accessing the rings via the console Signed-off-by: Remi Gacogne --- diff --git a/regression-tests.dnsdist/test_Console.py b/regression-tests.dnsdist/test_Console.py index e8a5b95594..8d394322a5 100644 --- a/regression-tests.dnsdist/test_Console.py +++ b/regression-tests.dnsdist/test_Console.py @@ -172,3 +172,74 @@ key_value_stores: 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') + +class TestConsoleRings(DNSDistTest): + + _consoleKey = DNSDistTest.generateConsoleKey() + _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') + + _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort'] + _config_template = """ + setKey("%s") + controlSocket("127.0.0.1:%d") + newServer{address="127.0.0.1:%d"} + """ + + def testConsoleRingEntries(self): + """ + Console: Ring entries + """ + # check that the ring is empty first + numberOfEntries = self.sendConsoleCommand('#getRingEntries()') + self.assertEqual(int(numberOfEntries), 0) + + name = 'a.console-ring.tests.powerdns.com.' + query = dns.message.make_query(name, 'A', 'IN', use_edns=False) + response = dns.message.make_response(query) + rrset = dns.rrset.from_text(name, + 3600, + dns.rdataclass.IN, + dns.rdatatype.A, + '127.0.0.1') + response.answer.append(rrset) + + for method in ("sendUDPQuery", "sendTCPQuery"): + sender = getattr(self, method) + (receivedQuery, receivedResponse) = sender(query, response) + self.assertTrue(receivedQuery) + self.assertTrue(receivedResponse) + receivedQuery.id = query.id + self.assertEqual(query, receivedQuery) + self.assertEqual(response, receivedResponse) + + # we should now have 4 entries in the ring + numberOfEntries = self.sendConsoleCommand('#getRingEntries()') + self.assertEqual(int(numberOfEntries), 4) + + # check the first query + index = 1 + qname = self.sendConsoleCommand(f'getRingEntries()[{index}].qname:toString()').rstrip() + self.assertEqual(qname, name) + qtype = self.sendConsoleCommand(f'getRingEntries()[{index}].qtype').rstrip() + self.assertEqual(int(qtype), 1) + protocol = self.sendConsoleCommand(f'getRingEntries()[{index}].protocol').rstrip() + self.assertEqual(protocol, "DoUDP") + requestor = self.sendConsoleCommand(f'getRingEntries()[{index}].requestor:toString()').rstrip() + self.assertEqual(requestor, "127.0.0.1") + isResponse = self.sendConsoleCommand(f'tostring(getRingEntries()[{index}].isResponse)').rstrip() + self.assertEqual(isResponse, "false") + + # check the first response + index = 2 + qname = self.sendConsoleCommand(f'getRingEntries()[{index}].qname:toString()').rstrip() + self.assertEqual(qname, name) + qtype = self.sendConsoleCommand(f'getRingEntries()[{index}].qtype').rstrip() + self.assertEqual(int(qtype), 1) + protocol = self.sendConsoleCommand(f'getRingEntries()[{index}].protocol').rstrip() + self.assertEqual(protocol, "DoUDP") + requestor = self.sendConsoleCommand(f'getRingEntries()[{index}].requestor:toString()').rstrip() + self.assertEqual(requestor, "127.0.0.1") + backend = self.sendConsoleCommand(f'getRingEntries()[{index}].backend:toStringWithPort()').rstrip() + self.assertEqual(backend, f"127.0.0.1:{self._testServerPort}") + isResponse = self.sendConsoleCommand(f'tostring(getRingEntries()[{index}].isResponse)').rstrip() + self.assertEqual(isResponse, "true")