]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add test for proxy exception mechanism
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 2 Apr 2024 08:33:45 +0000 (10:33 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 2 Apr 2024 11:00:08 +0000 (13:00 +0200)
pdns/recursordist/docs/upgrade.rst
pdns/recursordist/rec-main.cc
regression-tests.recursor-dnssec/test_ProxyProtocol.py

index 3d3023ceeca56e072ce54ebcd48277eeb358b161..dcf7d09755b62f4b5c45df686fc2241c87efeb37 100644 (file)
@@ -17,7 +17,7 @@ Changed settings
 New Settings
 ^^^^^^^^^^^^
 
-- The :ref:`setting-proxy-protocol-exceptions` has been added. It allows to exclude specific listen addresses from requiring th e Proxy Protocol.
+- The :ref:`setting-proxy-protocol-exceptions` has been added. It allows to exclude specific listen addresses from requiring the Proxy Protocol.
 
 5.0.2 to 5.0.3, 4.9.3 to 4.9.4 and 4.8.6 to 4.8.7
 -------------------------------------------------
index db062182fdf1edbade045dc1ef4e084e3adef88d..d151e0623bbebf76edd20153d26d2bbfc70d1442 100644 (file)
@@ -2123,7 +2123,7 @@ static int serviceMain(Logr::log_t log)
   {
     std::vector<std::string> vec;
     stringtok(vec, ::arg()["proxy-protocol-exceptions"], ", ");
-    for (const auto& sockAddrStr: vec) {
+    for (const auto& sockAddrStr : vec) {
       ComboAddress sockAddr(sockAddrStr, 53);
       g_proxyProtocolExceptions.emplace(sockAddr);
     }
index f28020f58dfd208bb7ed4cfdbf53907880204bd1..cdf71de143dcfe099ebbe587095b95b64b16d301 100644 (file)
@@ -603,3 +603,41 @@ class ProxyProtocolNotAllowedRecursorTest(ProxyProtocolRecursorTest):
             sender = getattr(self, method)
             res = sender(query, False, '127.0.0.42', '255.255.255.255', 0, 65535, [ [0, b'foo' ], [ 255, b'bar'] ])
             self.assertEqual(res, None)
+
+class ProxyProtocolExceptionRecursorTest(ProxyProtocolRecursorTest):
+    _confdir = 'ProxyProtocolException'
+    _lua_dns_script_file = """
+
+    function preresolve(dq)
+      dq:addAnswer(pdns.A, '192.0.2.1', 60)
+      return true
+    end
+    """
+
+    _config_template = """
+    proxy-protocol-from=127.0.0.1/32
+    proxy-protocol-exceptions=127.0.0.1:%d
+    allow-from=127.0.0.0/24, ::1/128
+""" % (ProxyProtocolRecursorTest._recursorPort)
+
+    def testNoHeaderProxyProtocol(self):
+        qname = 'no-header.proxy-protocol-not-allowed.recursor-tests.powerdns.com.'
+        expected = dns.rrset.from_text(qname, 0, dns.rdataclass.IN, 'A', '192.0.2.1')
+
+        query = dns.message.make_query(qname, 'A', want_dnssec=True)
+        for method in ("sendUDPQuery", "sendTCPQuery"):
+            sender = getattr(self, method)
+            res = sender(query)
+            self.assertRcodeEqual(res, dns.rcode.NOERROR)
+            self.assertRRsetInAnswer(res, expected)
+
+    def testIPv4ProxyProtocol(self):
+        qname = 'ipv4.proxy-protocol-not-allowed.recursor-tests.powerdns.com.'
+        expected = dns.rrset.from_text(qname, 0, dns.rdataclass.IN, 'A', '192.0.2.1')
+
+        query = dns.message.make_query(qname, 'A', want_dnssec=True)
+        for method in ("sendUDPQueryWithProxyProtocol", "sendTCPQueryWithProxyProtocol"):
+            sender = getattr(self, method)
+            res = sender(query, False, '127.0.0.42', '255.255.255.255', 0, 65535, [ [0, b'foo' ], [ 255, b'bar'] ])
+            self.assertEqual(res, None)
+