Commit a9e5fa1b authored by Alexandre's avatar Alexandre
Browse files

Add check with truncated data in request

parent d8dfc1a3
......@@ -181,11 +181,27 @@ class CustomException(Exception):
pass
def create_request(dot=False, trunc=False):
if dot:
request = RequestDoT(name, rtype, use_edns=edns, want_dnssec=dnssec)
else:
request = RequestDoH(name, rtype, use_edns=edns, want_dnssec=dnssec)
if trunc:
request.trunc_data()
else:
request.to_wire()
return request
class Request:
def __init__(self, qname, qtype=rtype, use_edns=edns, want_dnssec=dnssec):
self.message = dns.message.make_query(qname, dns.rdatatype.from_text(qtype), use_edns=use_edns, want_dnssec=want_dnssec)
self.message.flags |= dns.flags.AD # Ask for validation
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()
......@@ -383,12 +399,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.rcode, request.response, request.response_size)
......@@ -486,13 +502,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.rcode, request.response, request.response_size)
......@@ -688,14 +704,16 @@ if not check:
else:
if dot:
requests = [
('Test 1', RequestDoT(name, rtype, use_edns=edns, want_dnssec=dnssec)),
('Test 2', RequestDoT(name, rtype, use_edns=edns, want_dnssec=dnssec))
('Test 1', create_request(dot=True)),
('Test 2', create_request(dot=True)),
('Test 3', create_request(dot=True, trunc=True))
]
else:
requests = [
('Test GET', RequestDoH(name, rtype, use_edns=edns, want_dnssec=dnssec), DOH_GET),
('Test POST', RequestDoH(name, rtype, use_edns=edns, want_dnssec=dnssec), DOH_POST),
('Test HEAD', RequestDoH(name, rtype, use_edns=edns, want_dnssec=dnssec), DOH_HEAD)
('Test GET', create_request(), DOH_GET),
('Test POST', create_request(), DOH_POST),
('Test HEAD', create_request(), DOH_HEAD),
('Test truncated data', create_request(trunc=True), DOH_POST)
]
for request_pack in requests:
if dot:
......@@ -713,7 +731,7 @@ else:
request.post = False
try:
conn.send_and_receive(request)
except Exception as e:
except CustomException as e:
ok = False
error(e)
break
......
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