tests: Add unit tests for communicate as back door user PBA

This commit is contained in:
Shreya Malviya 2021-08-30 16:12:08 +05:30
parent 0f2f39f0a0
commit deb037c617
1 changed files with 38 additions and 0 deletions

View File

@ -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