tests: Modify unit tests for AutoNewWindowsUser based on previous commit

changes
This commit is contained in:
Shreya Malviya 2021-08-31 19:35:06 +05:30
parent 8d14ff6385
commit 2f5e6b516a
1 changed files with 14 additions and 7 deletions

View File

@ -5,7 +5,6 @@ import pytest
from infection_monkey.utils.windows.users import AutoNewWindowsUser from infection_monkey.utils.windows.users import AutoNewWindowsUser
TEST_USER = "test_user" TEST_USER = "test_user"
ACTIVE_NO_NET_USER = "/ACTIVE:NO"
@pytest.fixture @pytest.fixture
@ -20,13 +19,21 @@ def subprocess_check_output_spy(monkeypatch):
return mock_check_output return mock_check_output
def test_new_user_try_delete_windows(subprocess_check_output_spy): class StubLogonUser:
new_user = AutoNewWindowsUser(TEST_USER, "password") def __init__(self):
pass
new_user.try_deactivate_user() def Close():
assert f"net user {TEST_USER} {ACTIVE_NO_NET_USER}" in " ".join( return None
subprocess_check_output_spy.command
def test_new_user_delete_windows(subprocess_check_output_spy, monkeypatch):
monkeypatch.setattr(
"infection_monkey.utils.windows.users.win32security.LogonUser",
lambda _, __, ___, ____, _____: StubLogonUser,
) )
new_user.try_delete_user() with (AutoNewWindowsUser(TEST_USER, "password")):
pass
assert f"net user {TEST_USER} /delete" in " ".join(subprocess_check_output_spy.command) assert f"net user {TEST_USER} /delete" in " ".join(subprocess_check_output_spy.command)