]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add a test for the `Date` header in rejected HTTP/1 requests 16429/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 4 Nov 2025 14:21:04 +0000 (15:21 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 4 Nov 2025 14:21:04 +0000 (15:21 +0100)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
regression-tests.dnsdist/test_DOH.py

index fe8f1d0320fc5b5ebe1586369daf611b0fbcf8a8..a7429bf00515788f8031749ff1ba64507ede3070 100644 (file)
@@ -410,6 +410,7 @@ class DOHTests(object):
         wire = query.to_wire()
         b64 = base64.urlsafe_b64encode(wire).decode('UTF8').rstrip('=')
         url = self._dohBaseURL + '?dns=' + b64
+        responseHeaders = BytesIO()
         conn = pycurl.Curl()
         conn.setopt(pycurl.HTTP_VERSION, pycurl.CURL_HTTP_VERSION_1_1)
         conn.setopt(pycurl.HTTPHEADER, ["Content-type: application/dns-message",
@@ -419,14 +420,25 @@ class DOHTests(object):
         conn.setopt(pycurl.SSL_VERIFYPEER, 1)
         conn.setopt(pycurl.SSL_VERIFYHOST, 2)
         conn.setopt(pycurl.CAINFO, self._caCert)
+        conn.setopt(pycurl.HEADERFUNCTION, responseHeaders.write)
         data = conn.perform_rb()
         rcode = conn.getinfo(pycurl.RESPONSE_CODE)
+        responseHeaders = responseHeaders.getvalue()
         self.assertEqual(rcode, 400)
         self.assertEqual(data, b'<html><body>This server implements RFC 8484 - DNS Queries over HTTP, and requires HTTP/2 in accordance with section 5.2 of the RFC.</body></html>\r\n')
         self.assertEqual(self.getHTTPCounter('connects'), httpConnections + 1)
         self.assertEqual(self.getHTTPCounter('http/1.1'), http1 + 1)
         self.assertEqual(self.getHTTPCounter('http/2'), http2)
 
+        dateFound = False
+        for header in responseHeaders.decode().splitlines(False):
+            values = header.split(':')
+            key = values[0]
+            if key.lower() == 'date':
+                dateFound = True
+                break
+        self.assertTrue(dateFound)
+
     def testDOHHTTP1NotSelectedOverH2(self):
         """
         DOH: Check that HTTP/1.1 is not selected over H2 when offered in the wrong order by the client