From deb037c6174b8adbf27a3f6b36b2e634bd252951 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 30 Aug 2021 16:12:08 +0530 Subject: [PATCH] tests: Add unit tests for communicate as back door user PBA --- .../test_communicate_as_backdoor_user.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 monkey/tests/unit_tests/infection_monkey/post_breach/actions/test_communicate_as_backdoor_user.py diff --git a/monkey/tests/unit_tests/infection_monkey/post_breach/actions/test_communicate_as_backdoor_user.py b/monkey/tests/unit_tests/infection_monkey/post_breach/actions/test_communicate_as_backdoor_user.py new file mode 100644 index 000000000..2a1bf8f49 --- /dev/null +++ b/monkey/tests/unit_tests/infection_monkey/post_breach/actions/test_communicate_as_backdoor_user.py @@ -0,0 +1,38 @@ +from infection_monkey.post_breach.actions.communicate_as_new_user import ( + USERNAME_PREFIX, + CommunicateAsNewUser, +) + +URL = "this-is-where-i-wanna-go" + + +def test_get_random_new_user_name(): + username = CommunicateAsNewUser.get_random_new_user_name() + assert len(username) == len(USERNAME_PREFIX) + 5 + assert username.islower() + assert username.startswith(USERNAME_PREFIX) + + +def test_get_commandline_for_http_request_windows(): + cmd_line = CommunicateAsNewUser.get_commandline_for_http_request(URL, is_windows=True) + assert "powershell.exe" in cmd_line + assert URL in cmd_line + + +def test_get_commandline_for_http_request_linux_curl(monkeypatch): + monkeypatch.setattr( + "infection_monkey.post_breach.actions.communicate_as_new_user.shutil.which", + lambda _: "not None", + ) + cmd_line = CommunicateAsNewUser.get_commandline_for_http_request(URL, is_windows=False) + assert "curl" in cmd_line + assert URL in cmd_line + + +def test_get_commandline_for_http_request_linux_wget(monkeypatch): + monkeypatch.setattr( + "infection_monkey.post_breach.actions.communicate_as_new_user.shutil.which", lambda _: None + ) + cmd_line = CommunicateAsNewUser.get_commandline_for_http_request(URL, is_windows=False) + assert "wget" in cmd_line + assert URL in cmd_line