示例#1
0
 def make_request(self,
                  qname: str,
                  rdtype: str,
                  get: bool = False,
                  dnssec: bool = False) -> bytes:
     q = dns.message.make_query(qname=qname,
                                rdtype=rdtype,
                                want_dnssec=dnssec)
     q.id = 0
     data = q.to_wire()
     headers = {
         "accept": DOH_CONTENT_TYPE,
         "content-type": DOH_CONTENT_TYPE
     }
     if get:
         payload = {"dns": doh_b64_encode(data)}
         r = requests.get(self.server,
                          params=payload,
                          headers=headers,
                          verify=self.verify)
         return r.content
     else:
         r = requests.post(self.server,
                           data=data,
                           headers=headers,
                           verify=self.verify)
         return r.content
示例#2
0
 def test_get_valid(self, server_url, dns_query_answer):
     with connect(8000, server_url):
         headers = {
             "accept": DOH_CONTENT_TYPE,
             "content-type": DOH_CONTENT_TYPE
         }
         payload = {"dns": doh_b64_encode(dns_query_answer)}
         r = requests.get(server_url,
                          params=payload,
                          headers=headers,
                          verify=False)
         assert_answer(r)
示例#3
0
 def test_get_accept_missing(self, server_url, dns_query_answer):
     with connect(8000, server_url):
         payload = {"dns": doh_b64_encode(dns_query_answer)}
         r = requests.get(server_url, params=payload, verify=False)
         assert_answer(r)
示例#4
0
 def test_doh_b64_encode(self):
     assert doh_b64_encode(b"test") == "dGVzdA"
     assert doh_b64_encode(b"test==te&111%") == "dGVzdD09dGUmMTExJQ"
     with pytest.raises(TypeError):
         doh_b64_encode(None)