From: Bob Halley Date: Wed, 23 Mar 2022 13:06:05 +0000 (-0700) Subject: test padding in DoH X-Git-Tag: v2.3.0rc1~84 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=44233c7d644a41e1fb90ad6de67b355dd279f6f4;p=thirdparty%2Fdnspython.git test padding in DoH --- diff --git a/tests/test_doh.py b/tests/test_doh.py index 35cb1d3c..bae28dcb 100644 --- a/tests/test_doh.py +++ b/tests/test_doh.py @@ -25,6 +25,7 @@ try: except Exception: _have_ssl = False +import dns.edns import dns.message import dns.query import dns.rdatatype @@ -69,6 +70,11 @@ KNOWN_ANYCAST_DOH_RESOLVER_URLS = [ # 'https://dns11.quad9.net/dns-query', ] +KNOWN_PAD_AWARE_DOH_RESOLVER_URLS = [ + "https://cloudflare-dns.com/dns-query", + "https://dns.google/dns-query", +] + # Some tests require the internet to be available to run, so let's # skip those if it's not there. _network_available = True @@ -256,6 +262,21 @@ class DNSOverHTTPSTestCaseHttpx(unittest.TestCase): self.assertTrue("8.8.8.8" in seen) self.assertTrue("8.8.4.4" in seen) + def test_padded_get(self): + nameserver_url = random.choice(KNOWN_PAD_AWARE_DOH_RESOLVER_URLS) + q = dns.message.make_query("example.com.", dns.rdatatype.A, use_edns=0, pad=128) + r = dns.query.https( + q, nameserver_url, session=self.session, post=False, timeout=4 + ) + self.assertTrue(q.is_response(r)) + # the response should have a padding option + self.assertIsNotNone(r.opt) + has_pad = False + for o in r.opt[0].options: + if o.otype == dns.edns.OptionType.PADDING: + has_pad = True + self.assertTrue(has_pad) + if __name__ == "__main__": unittest.main()