From: Remi Gacogne Date: Tue, 29 Aug 2023 11:53:22 +0000 (+0200) Subject: dnsdist: Add regression test for EDE export to protobuf X-Git-Tag: rec-5.0.0-alpha2~22^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3762c2e919fc5538d9b8fcd2b8d7d96117ea300;p=thirdparty%2Fpdns.git dnsdist: Add regression test for EDE export to protobuf --- diff --git a/regression-tests.dnsdist/extendederrors.py b/regression-tests.dnsdist/extendederrors.py new file mode 120000 index 0000000000..6ed0ebae7d --- /dev/null +++ b/regression-tests.dnsdist/extendederrors.py @@ -0,0 +1 @@ +../regression-tests.recursor-dnssec/extendederrors.py \ No newline at end of file diff --git a/regression-tests.dnsdist/test_Protobuf.py b/regression-tests.dnsdist/test_Protobuf.py index 99a97183de..31f7b6c3f8 100644 --- a/regression-tests.dnsdist/test_Protobuf.py +++ b/regression-tests.dnsdist/test_Protobuf.py @@ -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()