qprep: nitpicks

parent fa19a979
......@@ -89,7 +89,7 @@ def wrk_process_line(
return None, None
def wrk_process_frame(args: Tuple[int, bytes, str]):
def wrk_process_frame(args: Tuple[int, bytes, str]) -> Tuple[Optional[int], Optional[bytes]]:
"""
Worker: convert packet from pcap to binary data
"""
......@@ -112,15 +112,17 @@ def wrk_process_wire_packet(
"""
try:
msg = dns.message.from_wire(wire_packet)
except dns.exception.DNSException:
# pass invalid blobs to LMDB (for testing non-standard states)
pass
else:
if blacklist.is_blacklisted(msg):
logging.debug('Blacklisted query "%s", skipping QID %d',
log_repr, qid)
return None, None
except dns.exception.DNSException:
# pass invalid blobs to LMDB (for testing non-standard states)
pass
return qid, wire_packet
def int_or_fromtext(value, fromtext):
try:
return int(value)
......@@ -135,7 +137,10 @@ def msg_from_text(text):
Returns: DNS packet in binary form
Raises: ValueError or dns.exception.Exception on invalid input
"""
qname, qtype = text.rsplit(None, 1)
try:
qname, qtype = text.split()
except ValueError:
raise ValueError('space is only allowed as separator between qname qtype')
qname = dns.name.from_text(qname.encode('ascii'))
qtype = int_or_fromtext(qtype, dns.rdatatype.from_text)
msg = dns.message.make_query(qname, qtype, dns.rdataclass.IN,
......@@ -186,7 +191,7 @@ def main():
if qid is not None:
key = qid2key(qid)
txn.put(key, wire)
except KeyboardInterrupt as err:
except KeyboardInterrupt:
logging.info('SIGINT received, exiting...')
sys.exit(130)
except RuntimeError as err:
......
......@@ -10,8 +10,10 @@ from qprep import wrk_process_line
@pytest.mark.parametrize('line', [
'',
'x'*256 + ' A',
('\123x.test. 65536'),
('\321.test. 1'),
'\123x.test. 65536',
'\321.test. 1',
'test. A,AAAA',
'test. A, AAAA',
])
def test_text_input_invalid(line):
assert wrk_process_line((1, line, line)) == (None, None)
......@@ -36,9 +38,11 @@ def test_text_input_valid(qname, qtype):
assert msg.question == expected
assert qid == 1
@pytest.mark.parametrize('line', [
'test. ANY',
'test. RRSIG',
'dotnxdomain.net. 28',
'something.dotnxdomain.net. A',
'something.dashnxdomain.net. AAAA',
])
......
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