UT: Renamed Communicate as new user

This commit is contained in:
Ilija Lazoroski 2021-08-30 14:18:03 +02:00
parent 10697934d6
commit 7aa230e9d0
1 changed files with 9 additions and 8 deletions

View File

@ -1,38 +1,39 @@
from infection_monkey.post_breach.actions.communicate_as_new_user import ( from infection_monkey.post_breach.actions.communicate_as_backdoor_user import (
USERNAME_PREFIX, USERNAME_PREFIX,
CommunicateAsNewUser, CommunicateAsBackdoorUser,
) )
URL = "this-is-where-i-wanna-go" URL = "this-is-where-i-wanna-go"
def test_get_random_new_user_name(): def test_get_random_new_user_name():
username = CommunicateAsNewUser.get_random_new_user_name() username = CommunicateAsBackdoorUser.get_random_new_user_name()
assert len(username) == len(USERNAME_PREFIX) + 5 assert len(username) == len(USERNAME_PREFIX) + 5
assert username.islower() assert username.islower()
assert username.startswith(USERNAME_PREFIX) assert username.startswith(USERNAME_PREFIX)
def test_get_commandline_for_http_request_windows(): def test_get_commandline_for_http_request_windows():
cmd_line = CommunicateAsNewUser.get_commandline_for_http_request(URL, is_windows=True) cmd_line = CommunicateAsBackdoorUser.get_commandline_for_http_request(URL, is_windows=True)
assert "powershell.exe" in cmd_line assert "powershell.exe" in cmd_line
assert URL in cmd_line assert URL in cmd_line
def test_get_commandline_for_http_request_linux_curl(monkeypatch): def test_get_commandline_for_http_request_linux_curl(monkeypatch):
monkeypatch.setattr( monkeypatch.setattr(
"infection_monkey.post_breach.actions.communicate_as_new_user.shutil.which", "infection_monkey.post_breach.actions.communicate_as_backdoor_user.shutil.which",
lambda _: "not None", lambda _: "not None",
) )
cmd_line = CommunicateAsNewUser.get_commandline_for_http_request(URL, is_windows=False) cmd_line = CommunicateAsBackdoorUser.get_commandline_for_http_request(URL, is_windows=False)
assert "curl" in cmd_line assert "curl" in cmd_line
assert URL in cmd_line assert URL in cmd_line
def test_get_commandline_for_http_request_linux_wget(monkeypatch): def test_get_commandline_for_http_request_linux_wget(monkeypatch):
monkeypatch.setattr( monkeypatch.setattr(
"infection_monkey.post_breach.actions.communicate_as_new_user.shutil.which", lambda _: None "infection_monkey.post_breach.actions.communicate_as_backdoor_user.shutil.which",
lambda _: None,
) )
cmd_line = CommunicateAsNewUser.get_commandline_for_http_request(URL, is_windows=False) cmd_line = CommunicateAsBackdoorUser.get_commandline_for_http_request(URL, is_windows=False)
assert "wget" in cmd_line assert "wget" in cmd_line
assert URL in cmd_line assert URL in cmd_line