From: Remi Gacogne Date: Mon, 6 Oct 2025 14:34:03 +0000 (+0200) Subject: dnsdist: Add regression tests for Lua pool bindings X-Git-Tag: rec-5.4.0-alpha1~224^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9aae19dbc1e18cf85e510228ebac4728d9e07150;p=thirdparty%2Fpdns.git dnsdist: Add regression tests for Lua pool bindings Signed-off-by: Remi Gacogne --- diff --git a/regression-tests.dnsdist/test_Lua.py b/regression-tests.dnsdist/test_Lua.py index 153c490b91..d81054f2b3 100644 --- a/regression-tests.dnsdist/test_Lua.py +++ b/regression-tests.dnsdist/test_Lua.py @@ -129,3 +129,58 @@ class TestLuaFrontendBindings(DNSDistTest): sender = getattr(self, method) (_, receivedResponse) = sender(query, response=None, useQueue=False) self.assertEqual(receivedResponse, expectedResponse) + +class TestLuaPoolBindings(DNSDistTest): + _config_template = """ + local serverPort = %d + newServer{address="127.0.0.1:" .. serverPort} + local pc = newPacketCache(1000, {maxTTL=86400, minTTL=1}) + -- at the moment getCache() does not return nil but an empty + -- shared_pointer when there is not cache, which is annoying + -- but necessary to prevent the client mode from failing, + -- so we test the result of :toString() instead + if getPool(""):getCache():toString() ~= "" then + print("The default pool should not have a cache") + os.exit(1) + end + getPool(""):setCache(pc) + if getPool(""):getCache():toString() == "" then + print("The default pool should have a cache") + os.exit(2) + end + getPool(""):unsetCache() + if getPool(""):getCache():toString() ~= "" then + print("The default pool should no longer have a cache") + os.exit(3) + end + local servers = getPoolServers("") + if #servers ~= 1 then + print("The default pool should have only one server") + os.exit(4) + end + if getPool(""):getECS() ~= false then + print("The default pool should not have ECS set") + os.exit(5) + end + rmServer(0) + newServer{address="127.0.0.1:" .. serverPort, useClientSubnet=true} + getPool(""):setECS(true) + if getPool(""):getECS() ~= true then + print("The default pool should now have ECS set") + os.exit(6) + end + """ + + def testLuaBindings(self): + """ + LuaPoolBindings: Test Lua pool bindings + """ + name = 'basic.lua-pool-bindings.tests.powerdns.com.' + query = dns.message.make_query(name, 'A', 'IN') + # dnsdist set RA = RD for spoofed responses + query.flags &= ~dns.flags.RD + response = dns.message.make_response(query) + for method in ("sendUDPQuery", "sendTCPQuery"): + sender = getattr(self, method) + (_, receivedResponse) = sender(query, response=response) + self.assertEqual(receivedResponse, response)