From: n0tlu5 Date: Sun, 22 Dec 2024 08:53:30 +0000 (+0700) Subject: adds selfweighted test with a set of A records X-Git-Tag: dnsdist-2.0.0-alpha1~178^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8df1aded1280fc4f738a152512cfcc630fbfc9d;p=thirdparty%2Fpdns.git adds selfweighted test with a set of A records --- diff --git a/regression-tests.auth-py/test_LuaRecords.py b/regression-tests.auth-py/test_LuaRecords.py index 973d98568c..08d0d84583 100644 --- a/regression-tests.auth-py/test_LuaRecords.py +++ b/regression-tests.auth-py/test_LuaRecords.py @@ -27,6 +27,8 @@ class FakeHTTPServer(BaseHTTPRequestHandler): self._set_headers() if self.path == '/ping.json': self.wfile.write(bytes('{"ping":"pong"}', 'utf-8')) + if self.path == '/weight.txt': + self.wfile.write(bytes('12', 'utf-8')) else: self.wfile.write(bytes("

hi!

Programming in Lua !

", "utf-8")) @@ -78,6 +80,7 @@ rand-txt.example.org. 3600 IN LUA TXT "pickrandom({{ 'bob', 'alice' }} randn-txt.example.org. 3600 IN LUA TXT "pickrandomsample( 2, {{ 'bob', 'alice', 'john' }} )" v6-bogus.rand.example.org. 3600 IN LUA AAAA "pickrandom({{'{prefix}.101', '{prefix}.102'}})" v6.rand.example.org. 3600 IN LUA AAAA "pickrandom({{ '2001:db8:a0b:12f0::1', 'fe80::2a1:9bff:fe9b:f268' }})" +selfweighted.example.org. 3600 IN LUA A "pickselfweighted('http://selfweighted.example.org:8080/weight.txt',{{'{prefix}.101', '{prefix}.102'}})" closest.geo 3600 IN LUA A "pickclosest({{ '1.1.1.2', '1.2.3.4' }})" empty.rand.example.org. 3600 IN LUA A "pickrandom()" timeout.example.org. 3600 IN LUA A "; local i = 0 ; while i < 1000 do pickrandom() ; i = i + 1 end return '1.2.3.4'" @@ -260,6 +263,24 @@ createforward6.example.org. 3600 IN NS ns2.example.org. res = self.sendUDPQuery(query) self.assertRcodeEqual(res, dns.rcode.SERVFAIL) + def testSelfWeighted(self): + """ + Test the selfweighted() function with a set of A records + """ + expected = [dns.rrset.from_text('selfweighted.example.org.', 0, dns.rdataclass.IN, 'A', + '{prefix}.101'.format(prefix=self._PREFIX)), + dns.rrset.from_text('selfweighted.example.org.', 0, dns.rdataclass.IN, 'A', + '{prefix}.102'.format(prefix=self._PREFIX))] + query = dns.message.make_query('selfweighted.example.org', 'A') + res = self.sendUDPQuery(query) + + # wait for health checks to happen + time.sleep(3) + + res = self.sendUDPQuery(query) + self.assertRcodeEqual(res, dns.rcode.NOERROR) + self.assertAnyRRsetInAnswer(res, expected) + def testPickRandomSampleTxt(self): """ Basic pickrandomsample() test with a set of TXT records