diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/conftest.py b/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/conftest.py new file mode 100644 index 000000000..d2891678e --- /dev/null +++ b/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/conftest.py @@ -0,0 +1,23 @@ +from datetime import datetime + +import mongoengine +import pytest + +from monkey_island.cc.services.config import ConfigService + + +@pytest.fixture +def fake_mongo(monkeypatch): + mongo = mongoengine.connection.get_connection() + monkeypatch.setattr("monkey_island.cc.services.config.mongo", mongo) + config = ConfigService.get_default_config() + ConfigService.update_config(config, should_encrypt=True) + + +CREDENTIAL_TELEM_TEMPLATE = { + "monkey_guid": "272405690278083", + "telem_category": "credentials", + "timestamp": datetime(2022, 2, 18, 11, 51, 15, 338953), + "command_control_channel": {"src": "10.2.2.251", "dst": "10.2.2.251:5000"}, + "data": None, +} diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/test_credential_processing.py b/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/test_credential_processing.py index 87326d228..94874cd4a 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/test_credential_processing.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/test_credential_processing.py @@ -1,9 +1,10 @@ from copy import deepcopy -from datetime import datetime import dpath.util -import mongoengine import pytest +from tests.unit_tests.monkey_island.cc.services.telemetry.processing.credentials.conftest import ( + CREDENTIAL_TELEM_TEMPLATE, +) from common.config_value_paths import ( LM_HASH_LIST_PATH, @@ -16,14 +17,6 @@ from monkey_island.cc.services.telemetry.processing.credentials.credentials_pars parse_credentials, ) -CREDENTIAL_TELEM_TEMPLATE = { - "monkey_guid": "272405690278083", - "telem_category": "credentials", - "timestamp": datetime(2022, 2, 18, 11, 51, 15, 338953), - "command_control_channel": {"src": "10.2.2.251", "dst": "10.2.2.251:5000"}, - "data": None, -} - fake_username = "m0nk3y_user" cred_telem_usernames = deepcopy(CREDENTIAL_TELEM_TEMPLATE) cred_telem_usernames["data"] = [ @@ -58,31 +51,22 @@ cred_empty_telem = deepcopy(CREDENTIAL_TELEM_TEMPLATE) cred_empty_telem["data"] = [{"identities": [], "secrets": []}] -@pytest.fixture -def fake_mongo(monkeypatch): - mongo = mongoengine.connection.get_connection() - monkeypatch.setattr("monkey_island.cc.services.config.mongo", mongo) - config = ConfigService.get_default_config() - ConfigService.update_config(config, should_encrypt=True) - return mongo - - -@pytest.mark.usefixtures("uses_database") -def test_cred_username_parsing(fake_mongo): +@pytest.mark.usefixtures("uses_database", "fake_mongo") +def test_cred_username_parsing(): parse_credentials(cred_telem_usernames) config = ConfigService.get_config(should_decrypt=True) assert fake_username in dpath.util.get(config, USER_LIST_PATH) -@pytest.mark.usefixtures("uses_database") -def test_cred_special_username_parsing(fake_mongo): +@pytest.mark.usefixtures("uses_database", "fake_mongo") +def test_cred_special_username_parsing(): parse_credentials(cred_telem_special_usernames) config = ConfigService.get_config(should_decrypt=True) assert fake_special_username in dpath.util.get(config, USER_LIST_PATH) -@pytest.mark.usefixtures("uses_database") -def test_cred_telemetry_parsing(fake_mongo): +@pytest.mark.usefixtures("uses_database", "fake_mongo") +def test_cred_telemetry_parsing(): parse_credentials(cred_telem) config = ConfigService.get_config(should_decrypt=True) assert fake_username in dpath.util.get(config, USER_LIST_PATH) @@ -91,8 +75,8 @@ def test_cred_telemetry_parsing(fake_mongo): assert fake_password in dpath.util.get(config, PASSWORD_LIST_PATH) -@pytest.mark.usefixtures("uses_database") -def test_empty_cred_telemetry_parsing(fake_mongo): +@pytest.mark.usefixtures("uses_database", "fake_mongo") +def test_empty_cred_telemetry_parsing(): default_config = deepcopy(ConfigService.get_config(should_decrypt=True)) default_usernames = dpath.util.get(default_config, USER_LIST_PATH) default_nt_hashes = dpath.util.get(default_config, NTLM_HASH_LIST_PATH)