Commit d17a9aa2 authored by Alexandre's avatar Alexandre
Browse files

Move method into utils + improve test coverage

parent 3dc45e0a
......@@ -139,12 +139,6 @@ def usage(msg=None):
""", file=sys.stderr)
print("See the README.md for more details.", file=sys.stderr)
def dump_data(data, text="data"):
pref = ' ' * (len(text) - 4)
print(f'{text}: ', data)
print(pref, 'hex:', " ".join(format(c, '02x') for c in data))
print(pref, 'bin:', " ".join(format(c, '08b') for c in data))
def get_next_domain(input_file):
name, rtype = 'framagit.org', 'AAAA'
line = input_file.readline()
......
from .utils import dump_data
from .utils import is_valid_hostname
from .utils import is_valid_ip_address
from .utils import is_valid_url
......
......@@ -221,7 +221,7 @@ class ConnectionDOT(Connection):
def send_data(self, data, dump=False):
if dump:
dump_data(data, 'data sent')
homer.dump_data(data, 'data sent')
length = len(data)
self.session.send(length.to_bytes(2, byteorder='big') + data)
......@@ -233,7 +233,7 @@ class ConnectionDOT(Connection):
size = int.from_bytes(buf, byteorder='big')
data = self.session.recv(size)
if dump:
dump_data(data, 'data recv')
homer.dump_data(data, 'data recv')
return (True, data, size)
def send_and_receive(self, request, dump=False):
......
......@@ -18,6 +18,12 @@ import homer
# Do not change these
re_host = re.compile(r'^([0-9a-z][0-9a-z-\.]*)|([0-9:]+)|([0-9\.])$')
def dump_data(data, text="data"):
pref = ' ' * (len(text) - 4)
print(f'{text}: ', data)
print(pref, 'hex:', " ".join(format(c, '02x') for c in data))
print(pref, 'bin:', " ".join(format(c, '08b') for c in data))
def is_valid_hostname(name):
name = canonicalize(name)
return re_host.search(name)
......
......@@ -146,6 +146,21 @@ tests:
stderr: ''
stdout: "OK\n"
- exe: './homer.py'
name: '--check of a correct DoT with debug mode'
markers:
- 'dot'
- 'check'
args:
- '--dot'
- '--check'
- '--debug'
- 'dot.bortzmeyer.fr'
- 'dnsforum.bj'
retcode: 0
stderr: ''
partstdout: "OK\n"
- exe: './homer.py'
name: "[doh][check] Successcul check"
markers:
......
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