def test_prefix_cuts_message(kresd_sock, datalen, send_query): """Prefix is shorter than the DNS message.""" wire, _ = utils.prepare_wire() assert datalen < len(wire) invalid_buff = utils.prepare_buffer(wire, datalen) send_query(kresd_sock, invalid_buff) # buffer breaks parsing of TCP stream with utils.expect_kresd_close(): utils.ping_alive(kresd_sock)
def test_prefix_trailing_garbage(kresd_sock, glength, query_before): """Send messages with trailing garbage (its length included in prefix).""" if query_before: utils.ping_alive(kresd_sock) for _ in range(10): wire, msgid = utils.prepare_wire() wire += utils.get_garbage(glength) buff = utils.prepare_buffer(wire) kresd_sock.sendall(buff) answer = utils.receive_parse_answer(kresd_sock) assert answer.id == msgid time.sleep(0.1)
def test_prefix_greater_than_message(kresd_sock, send_query): """Prefix is greater than the length of the entire DNS message.""" wire, invalid_msgid = utils.prepare_wire() datalen = len(wire) + 16 invalid_buff = utils.prepare_buffer(wire, datalen) send_query(kresd_sock, invalid_buff) valid_buff, _ = utils.get_msgbuff() kresd_sock.sendall(valid_buff) # invalid_buff is answered (treats additional data as trailing garbage) answer = utils.receive_parse_answer(kresd_sock) assert answer.id == invalid_msgid # parsing stream is broken by the invalid_buff, valid query is never answered with utils.expect_kresd_close(): utils.receive_parse_answer(kresd_sock)