From 2f5e6b516a829a07d0064d0f212338d4ee43dd2e Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 31 Aug 2021 19:35:06 +0530 Subject: [PATCH] tests: Modify unit tests for AutoNewWindowsUser based on previous commit changes --- .../utils/windows/test_windows_users.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/monkey/tests/unit_tests/infection_monkey/utils/windows/test_windows_users.py b/monkey/tests/unit_tests/infection_monkey/utils/windows/test_windows_users.py index 9e8d8da1b..a5c40e4c5 100644 --- a/monkey/tests/unit_tests/infection_monkey/utils/windows/test_windows_users.py +++ b/monkey/tests/unit_tests/infection_monkey/utils/windows/test_windows_users.py @@ -5,7 +5,6 @@ import pytest from infection_monkey.utils.windows.users import AutoNewWindowsUser TEST_USER = "test_user" -ACTIVE_NO_NET_USER = "/ACTIVE:NO" @pytest.fixture @@ -20,13 +19,21 @@ def subprocess_check_output_spy(monkeypatch): return mock_check_output -def test_new_user_try_delete_windows(subprocess_check_output_spy): - new_user = AutoNewWindowsUser(TEST_USER, "password") +class StubLogonUser: + def __init__(self): + pass - new_user.try_deactivate_user() - assert f"net user {TEST_USER} {ACTIVE_NO_NET_USER}" in " ".join( - subprocess_check_output_spy.command + def Close(): + return None + + +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)