From 385449101d2c4bd41829868882c9479ad2ac014d Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 23 Mar 2022 12:50:24 -0400 Subject: [PATCH] Tests: Move host fixtures to conftest.py --- .../infection_monkey/exploit/conftest.py | 33 +++++++++++++++++ .../powershell_utils/test_auth_options.py | 37 ------------------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/conftest.py b/monkey/tests/unit_tests/infection_monkey/exploit/conftest.py index c0d84708b..142a3065a 100644 --- a/monkey/tests/unit_tests/infection_monkey/exploit/conftest.py +++ b/monkey/tests/unit_tests/infection_monkey/exploit/conftest.py @@ -19,3 +19,36 @@ def patch_win32api_get_user_name(local_user): win32api.NameSamCompatible = None sys.modules["win32api"] = win32api + + +def _create_host(http_enabled, https_enabled): + host = MagicMock() + host.services = {} + + if http_enabled: + host.services["tcp-5985"] = {} + + if https_enabled: + host.services["tcp-5986"] = {} + + return host + + +@pytest.fixture +def https_only_host(): + return _create_host(False, True) + + +@pytest.fixture +def http_only_host(): + return _create_host(True, False) + + +@pytest.fixture +def http_and_https_both_enabled_host(): + return _create_host(True, True) + + +@pytest.fixture +def powershell_disabled_host(): + return _create_host(False, False) diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options.py b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options.py index 7d550c59e..fe18ccf9e 100644 --- a/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options.py +++ b/monkey/tests/unit_tests/infection_monkey/exploit/powershell_utils/test_auth_options.py @@ -1,7 +1,3 @@ -from unittest.mock import MagicMock - -import pytest - # from infection_monkey.exploit.powershell_utils.auth_options import AuthOptions from infection_monkey.exploit.powershell_utils.auth_options import ( AUTH_BASIC, @@ -20,39 +16,6 @@ CREDENTIALS_LM_HASH = Credentials("user4", "LM_HASH:NONE", SecretType.LM_HASH) CREDENTIALS_NT_HASH = Credentials("user5", "NONE:NT_HASH", SecretType.NT_HASH) -def _create_host(http_enabled, https_enabled): - host = MagicMock() - host.services = {} - - if http_enabled: - host.services["tcp-5985"] = {} - - if https_enabled: - host.services["tcp-5986"] = {} - - return host - - -@pytest.fixture -def https_only_host(): - return _create_host(False, True) - - -@pytest.fixture -def http_only_host(): - return _create_host(True, False) - - -@pytest.fixture -def http_and_https_both_enabled_host(): - return _create_host(True, True) - - -@pytest.fixture -def powershell_disabled_host(): - return _create_host(False, False) - - def test_get_auth_options__ssl_false_with_no_open_ports(powershell_disabled_host): auth_options = get_auth_options(CREDENTIALS_WITH_PASSWORD, powershell_disabled_host) assert auth_options.ssl is False