UT: Add test for thread-safety of ExploitClassHTTPServer

This commit is contained in:
Shreya Malviya 2022-03-02 16:45:48 +05:30 committed by vakarisz
parent 7739094cfd
commit 1ca9a21d43
1 changed files with 20 additions and 0 deletions

View File

@ -30,6 +30,16 @@ def server(ip, port, java_class):
server.stop()
@pytest.fixture
def second_server(ip, java_class):
server = ExploitClassHTTPServer(ip, get_free_tcp_port(), java_class, 0.01)
server.run()
yield server
server.stop()
@pytest.fixture
def exploit_url(ip, port):
return f"http://{ip}:{port}/Exploit"
@ -52,3 +62,13 @@ def test_exploit_class_downloaded(server, exploit_url):
requests.get(exploit_url)
assert server.exploit_class_downloaded()
def test_thread_safety(server, second_server, exploit_url):
assert not server.exploit_class_downloaded()
assert not second_server.exploit_class_downloaded()
requests.get(exploit_url)
assert server.exploit_class_downloaded()
assert not second_server.exploit_class_downloaded()