Tests: Move host fixtures to conftest.py

This commit is contained in:
Mike Salvatore 2022-03-23 12:50:24 -04:00
parent 3d7586f713
commit 385449101d
2 changed files with 33 additions and 37 deletions

View File

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

View File

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