Commit c17991a7 authored by Alexandre's avatar Alexandre
Browse files

Improve outputs

parent fe792d59
......@@ -223,13 +223,15 @@ class Request:
class RequestDoT(Request):
def check_response(self):
def check_response(self, debug=False):
ok = self.ok
if not self.rcode:
self.ok = False
return False
if self.response.id != self.message.id:
self.response = "The ID in the answer does not match the one in the query"
if debug:
self.response += f'"(query id: {self.message.id}) (response id: {self.response.id})'
self.ok = False
return False
return self.ok
......@@ -242,7 +244,7 @@ class RequestDoH(Request):
self.post = False
self.head = False
def check_response(self):
def check_response(self, debug=False):
ok = self.ok
if self.rcode == 200:
if self.ctype != "application/dns-message":
......@@ -251,20 +253,29 @@ class RequestDoH(Request):
else:
if not self.head:
try:
self.response = dns.message.from_wire(self.response)
response = dns.message.from_wire(self.response)
except dns.message.TrailingJunk: # Not DNS. Should
# not happen for a content type
# application/dns-message but who knows?
self.response = "ERROR Not proper DNS data, trailing junk \"%s\"" % self.response
self.response = "ERROR Not proper DNS data, trailing junk"
if debug:
self.response += " \"%s\"" % response
ok = False
except dns.name.BadLabelType: # Not DNS.
self.response = "ERROR Not proper DNS data (wrong path in the URL?) \"%s\"" % self.response[:100]
self.response = "ERROR Not proper DNS data (wrong path in the URL?)"
if debug:
self.response += " \"%s\"" % response[:100]
ok = False
else:
self.response = response
else:
if self.response_size == 0:
self.response = "HEAD successful"
else:
self.response = "ERROR Body length is not null \"%s\"" % self.response[:100]
data = self.response
self.response = "ERROR Body length is not null"
if debug:
self.response += "\"%s\"" % data[:100]
ok = False
else:
ok = False
......@@ -440,7 +451,7 @@ class ConnectionDoT(Connection):
request = RequestDoT(qname, qtype, want_dnssec=dnssec, use_edns=edns)
request.to_wire()
self.send_and_receive(request)
request.check_response()
request.check_response(self.debug)
return request
......@@ -549,7 +560,7 @@ class ConnectionDoH(Connection):
request.post = post
request.to_wire()
self.send_and_receive(request)
request.check_response()
request.check_response(self.debug)
return request
......@@ -663,12 +674,16 @@ def run_check_default(connection):
ok = False
error(e)
break
request.check_response()
request.check_response(debug)
if not print_result(connection, request, prefix=test_name, display_err=False):
if mandatory >= mandatory_level:
print_result(connection, request, prefix=test_name, display_err=True)
ok = False
if verbose:
print()
break
if verbose:
print()
return ok
def run_check_mime(connection, accept="application/dns-message", content_type="application/dns-message"):
......@@ -676,6 +691,9 @@ def run_check_mime(connection, accept="application/dns-message", content_type="a
return True
ok = True
header = [f"Accept: {accept}", f"Content-type: {content_type}"]
if verbose:
test_name = f'Test mime: {", ".join(h for h in header)}'
print(test_name)
req_args = { 'qname': name, 'qtype': rtype, 'use_edns': edns, 'want_dnssec': dnssec }
request = create_request(**req_args)
connection.curl.setopt(pycurl.HTTPHEADER, header)
......@@ -684,12 +702,14 @@ def run_check_mime(connection, accept="application/dns-message", content_type="a
except CustomException as e:
ok = False
error(e)
request.check_response()
request.check_response(debug)
if not print_result(connection, request, prefix=f"Test Header {', '.join(header)}"):
ok = False
default = "application/dns-message"
default_header = [f"Accept: {default}", f"Content-type: {default}"]
connection.curl.setopt(pycurl.HTTPHEADER, default_header)
if verbose:
print()
return ok
def run_check_trunc(connection):
......@@ -716,7 +736,7 @@ def run_check_trunc(connection):
# the RCODE set to FORMERR
# so response can not be parsed in this case
return ok
if request.check_response(): # FORMERR is expected
if request.check_response(debug): # FORMERR is expected
if dot:
ok = request.rcode == dns.rcode.FORMERR
else:
......@@ -727,6 +747,8 @@ def run_check_trunc(connection):
else: # a 400 response's status is acceptable
ok = (request.rcode >= 400 and request.rcode < 500)
print_result(connection, request, prefix=test_name, display_err=not ok)
if verbose:
print()
return ok
def run_check_additionals(connection):
......
Markdown is supported
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