def test_ignore_garbage(kresd_sock):
- """
- Send chunk of garbage, correctly prefixed by garbage length. Then, send
- correct DNS query.
-
- Expected: garbage must be ignored and the second query must be answered
- """
+ """Send chunk of garbage, prefixed by garbage length. It should be ignored."""
msg_buff, msgid = utils.get_msgbuff()
garbage_buff = utils.get_prefixed_garbage(1024)
kresd_sock.sendall(garbage_buff + msg_buff)
def test_pipelining(kresd_sock):
- """
- Test sends two queries to kresd - 1000.delay.getdnsapi.net and 1.delay.getdnsapi.net.
-
- Expected: answer to the second query must come first.
- """
+ """First query takes longer to resolve - answer to second query should arrive sooner."""
buff1, msgid1 = utils.get_msgbuff('1000.delay.getdnsapi.net.', msgid=1)
buff2, msgid2 = utils.get_msgbuff('1.delay.getdnsapi.net.', msgid=2)
buff = buff1 + buff2
def test_long_lived(kresd_sock):
- """
- Test establishes a TCP connection a sends several queries over it. They are sent
- seqeuntially, each with a delay, which in total exceeds maximum timeout.
-
- Expected: kresd must not close the connection
- """
+ """Establish and keep connection alive for longer than maximum timeout."""
utils.ping_alive(kresd_sock)
end_time = time.time() + utils.MAX_TIMEOUT
False # test closing established connection after handshake
])
def test_close(kresd_sock, query_before):
- """
- Test establishes a TCP connection, optionally sends a query and waits for response,
- and then pauses (MAX_TIMEOUT). Afterwards, another query is sent.
-
- Expected: kresd closes the connection
- """
+ """Establish a connection and wait for timeout from kresd."""
if query_before:
utils.ping_alive(kresd_sock)
time.sleep(utils.MAX_TIMEOUT)
False # test slow-lorris right after handshake
])
def test_slow_lorris(kresd_sock, query_before):
- """
- Test simulates slow-lorris attack by sending byte after byte with a delay in between.
-
- Expected: kresd closes the connection
- """
+ """Simulate slow-lorris attack by sending byte after byte with delays in between."""
if query_before:
utils.ping_alive(kresd_sock)
def test_ignore_jumbo_message(kresd_sock):
- """
- Test if kresd correcty ignores bigger queries than 4096 (current maximum size in kresd).
-
- Expected: jumbo message must be ignored, other queries answered
- """
+ """Queries bigger than 4096 bytes should be ignored."""
buff1, msgid1 = utils.get_msgbuff(msgid=1)
gbuff = utils.get_prefixed_garbage(65533)
kresd_sock.sendall(buff1 + gbuff)
def test_query_flood_close(make_kresd_sock):
- """
- Test floods resolver with queries and closes the connection.
-
- Expected: resolver must not crash
- """
+ """Flood resolver with queries and close the connection."""
buff = flood_buffer(10000)
sock1 = make_kresd_sock()
sock1.sendall(buff)
def test_query_flood_garbage(make_kresd_sock):
- """Flood resolver with correctly prefixed garbage of maximum size."""
+ """Flood resolver with prefixed garbage of maximum size."""
# TODO - despite the fact that kresd closes TCP connection, it seems to be
# error in TCP stream parsing. Kresd closes TCP connection because of
# message length in TCP prefix is lesser then length of the fixed message
time.sleep(delay)
-def test_less_than_header(kresd_sock):
+def test_prefix_less_than_header(kresd_sock):
"""Prefix is less than the length of the DNS message header."""
wire, _ = utils.prepare_wire()
datalen = 11 # DNS header size minus 1
send_incorrect_repeatedly(kresd_sock, buff)
-def test_greater_than_message(kresd_sock):
+def test_prefix_greater_than_message(kresd_sock):
"""Prefix is greater than the length of the entire DNS message."""
wire, _ = utils.prepare_wire()
datalen = len(wire) + 16
send_incorrect_repeatedly(kresd_sock, buff)
-def test_cuts_message(kresd_sock):
+def test_prefix_cuts_message(kresd_sock):
"""Prefix is greater than the length of the DNS message header, but shorter than
the entire DNS message."""
wire, _ = utils.prepare_wire()
send_incorrect_repeatedly(kresd_sock, buff)
-def test_cuts_message_after_ok(kresd_sock):
+def test_prefix_cuts_message_after_ok(kresd_sock):
"""First, normal DNS message is sent. Afterwards, message with incorrect prefix
(greater than header, less than entire message) is sent. First message must be
answered, then the connection should be closed after timeout."""
def test_trailing_garbage(kresd_sock):
- """Prefix is correct, but the message has trailing garbage. The connection must
- stay open until all message have been sent and answered."""
+ """Send messages with trailing garbage (its length included in prefix)."""
for _ in range(10):
wire, msgid = utils.prepare_wire()
wire += utils.get_garbage(8)