import time
-import pytest
-
import utils
"""
time.sleep(utils.MAX_TIMEOUT)
- with pytest.raises(BrokenPipeError, message="kresd didn't close the connection"):
- try:
- utils.ping_alive(kresd_sock)
- except ConnectionResetError:
- pytest.skip('TCP RST')
+ with utils.expect_kresd_close():
+ utils.ping_alive(kresd_sock)
def test_slow_lorris_attack(kresd_sock):
"""
buff, _ = utils.get_msgbuff()
- with pytest.raises(BrokenPipeError, message="kresd didn't close the connection"):
- try:
- for i in range(len(buff)):
- b = buff[i:i+1]
- kresd_sock.send(b)
- time.sleep(1)
- except ConnectionResetError:
- pytest.skip('TCP RST')
+ with utils.expect_kresd_close():
+ for i in range(len(buff)):
+ b = buff[i:i+1]
+ kresd_sock.send(b)
+ time.sleep(1)
import time
-import pytest
-
import utils
"""
end_time = time.time() + utils.MAX_TIMEOUT
- with pytest.raises(BrokenPipeError, message="kresd didn't close connection"):
+ with utils.expect_kresd_close():
while time.time() < end_time:
- try:
- sock.sendall(buff)
- except ConnectionResetError:
- pytest.skip("kresd closed connection with TCP RST")
+ sock.sendall(buff)
time.sleep(delay)
+from contextlib import contextmanager
import struct
import random
import dns
import dns.message
+import pytest
# default net.tcp_in_idle is 10s, TCP_DEFER_ACCEPT 3s, some extra for
sock.sendall(buff)
answer = receive_parse_answer(sock)
return answer.id == msgid
+
+
+@contextmanager
+def expect_kresd_close():
+ with pytest.raises(BrokenPipeError, message="kresd didn't close the connection"):
+ try:
+ yield
+ except ConnectionResetError:
+ pytest.skip("kresd closed connection with TCP RST")