]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add regression test for EDE export to protobuf
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 29 Aug 2023 11:53:22 +0000 (13:53 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 11 Sep 2023 08:37:10 +0000 (10:37 +0200)
regression-tests.dnsdist/extendederrors.py [new symlink]
regression-tests.dnsdist/test_Protobuf.py

diff --git a/regression-tests.dnsdist/extendederrors.py b/regression-tests.dnsdist/extendederrors.py
new file mode 120000 (symlink)
index 0000000..6ed0eba
--- /dev/null
@@ -0,0 +1 @@
+../regression-tests.recursor-dnssec/extendederrors.py
\ No newline at end of file
index 99a97183de7a20ac6259931133aeb56cb646067c..31f7b6c3f814bdf32efa2fdaf4d05b8ec5bf2bde 100644 (file)
@@ -10,6 +10,7 @@ from proxyprotocol import ProxyProtocol
 
 import dns
 import dnsmessage_pb2
+import extendederrors
 
 class DNSDistProtobufTest(DNSDistTest):
     _protobufServerPort = pickAvailablePort()
@@ -295,8 +296,9 @@ class TestProtobuf(DNSDistProtobufTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(response, receivedResponse)
 
-        # let the protobuf messages the time to get there
-        time.sleep(1)
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
 
         # check the protobuf message corresponding to the UDP query
         msg = self.getFirstProtobufMessage()
@@ -323,8 +325,9 @@ class TestProtobuf(DNSDistProtobufTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(response, receivedResponse)
 
-        # let the protobuf messages the time to get there
-        time.sleep(1)
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
 
         # check the protobuf message corresponding to the TCP query
         msg = self.getFirstProtobufMessage()
@@ -368,9 +371,9 @@ class TestProtobuf(DNSDistProtobufTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(response, receivedResponse)
 
-
-        # let the protobuf messages the time to get there
-        time.sleep(1)
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
 
         # check the protobuf message corresponding to the UDP query
         msg = self.getFirstProtobufMessage()
@@ -394,8 +397,9 @@ class TestProtobuf(DNSDistProtobufTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(response, receivedResponse)
 
-        # let the protobuf messages the time to get there
-        time.sleep(1)
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
 
         # check the protobuf message corresponding to the TCP query
         msg = self.getFirstProtobufMessage()
@@ -445,8 +449,9 @@ class TestProtobufMetaTags(DNSDistProtobufTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(response, receivedResponse)
 
-        # let the protobuf messages the time to get there
-        time.sleep(1)
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
 
         # check the protobuf message corresponding to the UDP query
         msg = self.getFirstProtobufMessage()
@@ -485,6 +490,64 @@ class TestProtobufMetaTags(DNSDistProtobufTest):
         # no ':' when the value is empty
         self.assertIn('my-empty-key', msg.meta[0].value.stringVal)
 
+class TestProtobufExtendedDNSErrorTags(DNSDistProtobufTest):
+    _config_params = ['_testServerPort', '_protobufServerPort']
+    _config_template = """
+    newServer{address="127.0.0.1:%s"}
+    rl = newRemoteLogger('127.0.0.1:%d')
+
+    addAction(AllRule(), RemoteLogAction(rl, nil, {serverID='dnsdist-server-1'}))
+    addResponseAction(AllRule(), RemoteLogResponseAction(rl, nil, false, {serverID='dnsdist-server-1', exportExtendedErrorsToMeta='extended-error'}))
+    """
+
+    def testProtobufExtendedError(self):
+        """
+        Protobuf: Extended Error
+        """
+        name = 'extended-error.protobuf.tests.powerdns.com.'
+        query = dns.message.make_query(name, 'A', 'IN')
+        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)
+        ede = extendederrors.ExtendedErrorOption(15, b'Blocked by RPZ!')
+        response.use_edns(edns=True, payload=4096, options=[ede])
+
+        (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+        self.assertTrue(receivedQuery)
+        self.assertTrue(receivedResponse)
+        receivedQuery.id = query.id
+        self.assertEqual(query, receivedQuery)
+        self.assertEqual(response, receivedResponse)
+
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
+
+        # check the protobuf message corresponding to the UDP query
+        msg = self.getFirstProtobufMessage()
+
+        self.checkProtobufQuery(msg, dnsmessage_pb2.PBDNSMessage.UDP, query, dns.rdataclass.IN, dns.rdatatype.A, name)
+
+        # meta tags
+        self.assertEqual(len(msg.meta), 0)
+
+        # check the protobuf message corresponding to the UDP response
+        msg = self.getFirstProtobufMessage()
+        self.checkProtobufResponse(msg, dnsmessage_pb2.PBDNSMessage.UDP, response)
+
+        # meta tags
+        self.assertEqual(len(msg.meta), 1)
+
+        self.assertEqual(msg.meta[0].key, 'extended-error')
+        self.assertEqual(len(msg.meta[0].value.intVal), 1)
+        self.assertEqual(len(msg.meta[0].value.stringVal), 1)
+        self.assertIn(15, msg.meta[0].value.intVal)
+        self.assertIn('Blocked by RPZ!', msg.meta[0].value.stringVal)
+
 class TestProtobufMetaDOH(DNSDistProtobufTest):
 
     _serverKey = 'server.key'
@@ -534,8 +597,9 @@ class TestProtobufMetaDOH(DNSDistProtobufTest):
             self.assertEqual(query, receivedQuery)
             self.assertEqual(response, receivedResponse)
 
-            # let the protobuf messages the time to get there
-            time.sleep(1)
+            if self._protobufQueue.empty():
+                # let the protobuf messages the time to get there
+                time.sleep(1)
 
             # check the protobuf message corresponding to the query
             msg = self.getFirstProtobufMessage()
@@ -637,8 +701,9 @@ class TestProtobufMetaProxy(DNSDistProtobufTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(response, receivedResponse)
 
-        # let the protobuf messages the time to get there
-        time.sleep(1)
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
 
         # check the protobuf message corresponding to the UDP query
         msg = self.getFirstProtobufMessage()
@@ -698,8 +763,9 @@ class TestProtobufIPCipher(DNSDistProtobufTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(response, receivedResponse)
 
-        # let the protobuf messages the time to get there
-        time.sleep(1)
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
 
         # check the protobuf message corresponding to the UDP query
         msg = self.getFirstProtobufMessage()
@@ -726,8 +792,9 @@ class TestProtobufIPCipher(DNSDistProtobufTest):
         self.assertEqual(query, receivedQuery)
         self.assertEqual(response, receivedResponse)
 
-        # let the protobuf messages the time to get there
-        time.sleep(1)
+        if self._protobufQueue.empty():
+            # let the protobuf messages the time to get there
+            time.sleep(1)
 
         # check the protobuf message corresponding to the TCP query
         msg = self.getFirstProtobufMessage()