]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add TTL test for `SpoofAction` 9784/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Fri, 27 Nov 2020 12:27:45 +0000 (13:27 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 27 Nov 2020 12:27:45 +0000 (13:27 +0100)
regression-tests.dnsdist/test_Spoofing.py

index d8ce626f0359375e69e3f4061e93d366fb3e9f0e..ff2675c313e2fba8cb8adec728dff4a822ef5de1 100644 (file)
@@ -10,6 +10,7 @@ class TestSpoofingSpoof(DNSDistTest):
     addAction(makeRule("spoofaction-ad.spoofing.tests.powerdns.com."), SpoofAction({"192.0.2.1", "2001:DB8::1"}, {ad=true}))
     addAction(makeRule("spoofaction-ra.spoofing.tests.powerdns.com."), SpoofAction({"192.0.2.1", "2001:DB8::1"}, {ra=true}))
     addAction(makeRule("spoofaction-nora.spoofing.tests.powerdns.com."), SpoofAction({"192.0.2.1", "2001:DB8::1"}, {ra=false}))
+    addAction(makeRule("spoofaction-ttl.spoofing.tests.powerdns.com."), SpoofAction({"192.0.2.1", "2001:DB8::1"}, {ttl=1500}))
     addAction(makeRule("cnamespoofaction.spoofing.tests.powerdns.com."), SpoofCNAMEAction("cnameaction.spoofing.tests.powerdns.com."))
     addAction("multispoof.spoofing.tests.powerdns.com", SpoofAction({"192.0.2.1", "192.0.2.2", "2001:DB8::1", "2001:DB8::2"}))
     addAction(AndRule{makeRule("raw.spoofing.tests.powerdns.com"), QTypeRule(DNSQType.A)}, SpoofRawAction("\\192\\000\\002\\001"))
@@ -270,6 +271,28 @@ class TestSpoofingSpoof(DNSDistTest):
             self.assertEquals(expectedResponse, receivedResponse)
             self.assertEquals(receivedResponse.answer[0].ttl, 60)
 
+    def testSpoofActionSetTTL(self):
+        """
+        Spoofing: Spoof via Action, setting the TTL to 1500
+        """
+        name = 'spoofaction-ttl.spoofing.tests.powerdns.com.'
+        query = dns.message.make_query(name, 'AAAA', 'IN')
+        expectedResponse = dns.message.make_response(query)
+        expectedResponse.flags |= dns.flags.RA
+        rrset = dns.rrset.from_text(name,
+                                    60,
+                                    dns.rdataclass.IN,
+                                    dns.rdatatype.AAAA,
+                                    '2001:DB8::1')
+        expectedResponse.answer.append(rrset)
+
+        for method in ("sendUDPQuery", "sendTCPQuery"):
+            sender = getattr(self, method)
+            (_, receivedResponse) = sender(query, response=None, useQueue=False)
+            self.assertTrue(receivedResponse)
+            self.assertEquals(expectedResponse, receivedResponse)
+            self.assertEquals(receivedResponse.answer[0].ttl, 1500)
+
     def testSpoofRawAction(self):
         """
         Spoofing: Spoof a response from raw bytes