Commit fecd969e authored by Alexandre's avatar Alexandre
Browse files

Merge branch 'test-trunc_data' into option-check

parents 2db5614a a9e5fa1b
......@@ -181,11 +181,15 @@ class CustomException(Exception):
pass
def create_request(dot=dot, **req_args):
def create_request(dot=dot, trunc=False, **req_args):
if dot:
request = RequestDoT(**req_args)
else:
request = RequestDoH(**req_args)
if trunc:
request.trunc_data()
else:
request.to_wire()
return request
def create_requests_list(dot=dot, **req_args):
......@@ -193,10 +197,12 @@ def create_requests_list(dot=dot, **req_args):
if dot:
requests.append(('Test 1', create_request(dot=dot, **req_args)))
requests.append(('Test 2', create_request(dot=dot, **req_args)))
requests.append(('Test truncated data', create_request(dot=dot, trunc=True, **req_args)))
else:
requests.append(('Test GET', create_request(**req_args), DOH_GET))
requests.append(('Test POST', create_request(**req_args), DOH_POST))
requests.append(('Test HEAD', create_request(**req_args), DOH_HEAD))
requests.append(('Test truncated data', create_request(trunc=True, **req_args), DOH_POST))
return requests
......@@ -206,6 +212,11 @@ class Request:
self.message.flags |= dns.flags.AD # Ask for validation
self.ok = True
def trunc_data(self):
self.data = self.message.to_wire()
half = round(len(self.data) / 2)
self.data = self.data[:half]
def to_wire(self):
self.data = self.message.to_wire()
......@@ -371,12 +382,12 @@ class ConnectionDoT(Connection):
request.rcode = True
def send_and_receive(self, request):
request.to_wire()
self.send_data(request.data)
self.receive_data(request)
def do_test(self, qname, qtype=rtype):
request = RequestDoT(qname, qtype, want_dnssec=dnssec, use_edns=edns)
request.to_wire()
self.send_and_receive(request)
request.check_response()
return request
......@@ -477,13 +488,13 @@ class ConnectionDoH(Connection):
self.buffer.close()
def send_and_receive(self, request):
request.to_wire()
self.prepare(request)
self.perform()
self.receive(request)
def do_test(self, qname, qtype=rtype):
request = RequestDoH(qname, qtype, want_dnssec=dnssec, use_edns=edns)
request.to_wire()
self.send_and_receive(request)
request.check_response()
return request
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment