]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add regression tests for the XFR end detection feature
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 11 Jun 2021 15:02:38 +0000 (17:02 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 11 Jun 2021 15:02:38 +0000 (17:02 +0200)
regression-tests.dnsdist/test_AXFR.py

index 6bc5004614ad49caf2460b98518f2ddc614063b0..c4e43c7bad3212efdde044330ab05493bccfe36d 100644 (file)
@@ -165,6 +165,156 @@ class TestAXFR(DNSDistTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(len(receivedResponses), len(responses))
 
+    def testThreePlusTrailingAXFR(self):
+        """
+        AXFR: Three messages including the final SOA, plus a trailing one
+        """
+        name = 'threeplustrailing.axfr.tests.powerdns.com.'
+        query = dns.message.make_query(name, 'AXFR', 'IN')
+        responses = []
+        soa = dns.rrset.from_text(name,
+                                  60,
+                                  dns.rdataclass.IN,
+                                  dns.rdatatype.SOA,
+                                  'ns.' + name + ' hostmaster.' + name + ' 1 3600 3600 3600 60')
+
+        # the SOA starts the AXFR
+        response = dns.message.make_response(query)
+        response.answer.append(soa)
+        responses.append(response)
+
+        # one A
+        response = dns.message.make_response(query)
+        response.answer.append(dns.rrset.from_text(name,
+                                                   60,
+                                                   dns.rdataclass.IN,
+                                                   dns.rdatatype.A,
+                                                   '192.0.2.1'))
+        responses.append(response)
+
+        # one AAAA
+        response = dns.message.make_response(query)
+        rrset = dns.rrset.from_text(name,
+                                    60,
+                                    dns.rdataclass.IN,
+                                    dns.rdatatype.AAAA,
+                                    '2001:DB8::1')
+        response.answer.append(rrset)
+        responses.append(response)
+
+        # one TXT then the SOA that ends the AXFR
+        response = dns.message.make_response(query)
+        rrset = dns.rrset.from_text(name,
+                                    60,
+                                    dns.rdataclass.IN,
+                                    dns.rdatatype.TXT,
+                                    "Some text")
+        response.answer.append(rrset)
+        response.answer.append(soa)
+        responses.append(response)
+
+        # and we add a final, dummy TXT message that will
+        # be sent by the backend but that dnsdist should not
+        # pass along to the client
+        response = dns.message.make_response(query)
+        rrset = dns.rrset.from_text(name,
+                                    60,
+                                    dns.rdataclass.IN,
+                                    dns.rdatatype.TXT,
+                                    'dummy')
+        response.answer.append(rrset)
+        responses.append(response)
+
+        (receivedQuery, receivedResponses) = self.sendTCPQueryWithMultipleResponses(query, responses)
+        receivedQuery.id = query.id
+        self.assertEqual(query, receivedQuery)
+        self.assertEqual(len(receivedResponses), len(responses) - 1)
+
+    def testThreePlusTrailingIXFR(self):
+        """
+        IXFR: Three messages including the final SOA, plus a trailing one
+        """
+        name = 'threeplustrailing.ixfr.tests.powerdns.com.'
+        query = dns.message.make_query(name, 'AXFR', 'IN')
+        responses = []
+
+        finalSoa = dns.rrset.from_text(name,
+                                       60,
+                                       dns.rdataclass.IN,
+                                       dns.rdatatype.SOA,
+                                       'ns.' + name + ' hostmaster.' + name + ' 3 3600 3600 3600 60')
+
+        # the final SOA starts the AXFR, with first an update from 1 to 2 (one removal, two additions)
+        response = dns.message.make_response(query)
+        response.answer.append(finalSoa)
+        # update from 1 to 2
+        response.answer.append(dns.rrset.from_text(name,
+                                                   60,
+                                                   dns.rdataclass.IN,
+                                                   dns.rdatatype.SOA,
+                                                   'ns.' + name + ' hostmaster.' + name + ' 1 3600 3600 3600 60'))
+        # one removal
+        response.answer.append(dns.rrset.from_text(name,
+                                                   60,
+                                                   dns.rdataclass.IN,
+                                                   dns.rdatatype.A,
+                                                   '192.0.2.1'))
+        # then additions
+        response.answer.append(dns.rrset.from_text(name,
+                                                   60,
+                                                   dns.rdataclass.IN,
+                                                   dns.rdatatype.SOA,
+                                                   'ns.' + name + ' hostmaster.' + name + ' 2 3600 3600 3600 60'))
+        # new message in the middle of the additions
+        responses.append(response)
+        response = dns.message.make_response(query)
+
+        response.answer.append(dns.rrset.from_text_list(name,
+                                                        60,
+                                                        dns.rdataclass.IN,
+                                                        dns.rdatatype.A,
+                                                        ['192.0.2.2', '192.0.2.3']))
+        # done with 1 -> 2
+        response.answer.append(dns.rrset.from_text(name,
+                                                   60,
+                                                   dns.rdataclass.IN,
+                                                   dns.rdatatype.SOA,
+                                                   'ns.' + name + ' hostmaster.' + name + ' 2 3600 3600 3600 60'))
+        # new message
+        responses.append(response)
+        response = dns.message.make_response(query)
+
+        # then upgrade to 3
+        # no removals
+        response.answer.append(finalSoa)
+
+        # and one addition
+        response.answer.append(dns.rrset.from_text(name,
+                                                   60,
+                                                   dns.rdataclass.IN,
+                                                   dns.rdatatype.A,
+                                                   '192.0.2.4'))
+        # and the final SOA
+        response.answer.append(finalSoa)
+        responses.append(response)
+
+        # and we add a final, dummy TXT message that will
+        # be sent by the backend but that dnsdist should not
+        # pass along to the client
+        response = dns.message.make_response(query)
+        rrset = dns.rrset.from_text(name,
+                                    60,
+                                    dns.rdataclass.IN,
+                                    dns.rdatatype.TXT,
+                                    'dummy')
+        response.answer.append(rrset)
+        responses.append(response)
+
+        (receivedQuery, receivedResponses) = self.sendTCPQueryWithMultipleResponses(query, responses)
+        receivedQuery.id = query.id
+        self.assertEqual(query, receivedQuery)
+        self.assertEqual(len(receivedResponses), len(responses) - 1)
+
     # def testFourNoFirstSOAAXFR(self):
     #     """
     #     AXFR: Four messages, no SOA in the first one