Commit 05023f32 authored by Alexandre's avatar Alexandre
Browse files

Separate --check option

parent f95c8dc7
...@@ -63,6 +63,11 @@ STATE_CRITICAL = 2 ...@@ -63,6 +63,11 @@ STATE_CRITICAL = 2
STATE_UNKNOWN = 3 STATE_UNKNOWN = 3
STATE_DEPENDENT = 4 STATE_DEPENDENT = 4
# For the check option
DOH_GET = 0
DOH_POST = 1
DOH_HEAD = 2
def error(msg=None): def error(msg=None):
if msg is None: if msg is None:
msg = "Unknown error" msg = "Unknown error"
...@@ -211,14 +216,14 @@ class RequestDoH(Request): ...@@ -211,14 +216,14 @@ class RequestDoH(Request):
self.response = "ERROR Not proper DNS data (wrong path in the URL?) \"%s\"" % self.body[:100] self.response = "ERROR Not proper DNS data (wrong path in the URL?) \"%s\"" % self.body[:100]
ok = False ok = False
else: else:
if self.body_size == 0: if self.response_size == 0:
self.response = "HEAD successful" self.response = "HEAD successful"
else: else:
self.response = "ERROR Body length is not null \"%s\"" % self.body[:100] self.response = "ERROR Body length is not null \"%s\"" % self.body[:100]
ok = False ok = False
else: else:
ok = False ok = False
if self.body_size == 0: if self.response_size == 0:
self.response = "[No details]" self.response = "[No details]"
else: else:
self.response = self.body self.response = self.body
...@@ -467,7 +472,7 @@ class ConnectionDoH(Connection): ...@@ -467,7 +472,7 @@ class ConnectionDoH(Connection):
http_code = self.curl.getinfo(pycurl.RESPONSE_CODE) http_code = self.curl.getinfo(pycurl.RESPONSE_CODE)
content_type = self.curl.getinfo(pycurl.CONTENT_TYPE) content_type = self.curl.getinfo(pycurl.CONTENT_TYPE)
request.body = body request.body = body
request.body_size = body_size request.response_size = body_size
request.rcode = http_code request.rcode = http_code
request.ctype = content_type request.ctype = content_type
self.buffer.close() self.buffer.close()
...@@ -482,7 +487,7 @@ class ConnectionDoH(Connection): ...@@ -482,7 +487,7 @@ class ConnectionDoH(Connection):
request = RequestDoH(qname, qtype, want_dnssec=dnssec, use_edns=edns) request = RequestDoH(qname, qtype, want_dnssec=dnssec, use_edns=edns)
self.send_and_receive(request) self.send_and_receive(request)
request.check_response() request.check_response()
return (request.rcode, request.response, request.body_size) return (request.rcode, request.response, request.response_size)
def get_next_domain(input_file): def get_next_domain(input_file):
...@@ -669,7 +674,41 @@ if not check: ...@@ -669,7 +674,41 @@ if not check:
if delay is not None: if delay is not None:
time.sleep(delay) time.sleep(delay)
else: else:
pass # TODO --check option running several tests 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))
]
else:
requests = [
('GET', RequestDoH(name, rtype, use_edns=edns, want_dnssec=dnssec), DOH_GET),
('POST', RequestDoH(name, rtype, use_edns=edns, want_dnssec=dnssec), DOH_POST),
('HEAD', RequestDoH(name, rtype, use_edns=edns, want_dnssec=dnssec), DOH_HEAD)
]
for request_pack in requests:
if dot:
test_name, request = request_pack
else:
test_name, request, method = request_pack
if verbose:
print(test_name)
if not dot:
if method == DOH_POST:
request.post = True
request.head = False
elif method == DOH_HEAD:
request.head = True
request.post = False
try:
conn.send_and_receive(request)
except Exception as e:
ok = False
error(e)
break
request.check_response()
if not conn.print_result(request.rcode, request.response, request.response_size):
ok = False
break
stop = time.time() stop = time.time()
if tests > 1: if tests > 1:
extra = ", %.2f ms/request if we ignore the first one" % ((stop-start2)*1000/(tests-1)) extra = ", %.2f ms/request if we ignore the first one" % ((stop-start2)*1000/(tests-1))
......
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