From 1af21b372cbd00a647dd0fb216c599fed855f10c Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 11 Jul 2022 14:10:42 -0400 Subject: [PATCH] UT: Move PROPAGATION_CREDENTIALS into data_for_tests --- .../data_for_tests/propagation_credentials.py | 18 +++++++++++++++ monkey/tests/monkey_island/__init__.py | 5 +--- ...stub_propagation_credentials_repository.py | 23 +++++-------------- ...test_configured_propagation_credentials.py | 8 +++---- .../test_stolen_propagation_credentials.py | 5 +++- 5 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 monkey/tests/data_for_tests/propagation_credentials.py diff --git a/monkey/tests/data_for_tests/propagation_credentials.py b/monkey/tests/data_for_tests/propagation_credentials.py new file mode 100644 index 000000000..5d41aca1e --- /dev/null +++ b/monkey/tests/data_for_tests/propagation_credentials.py @@ -0,0 +1,18 @@ +from common.credentials import Credentials, LMHash, NTHash, Password, Username + +username = "m0nk3y_user" +special_username = "m0nk3y.user" +nt_hash = "C1C58F96CDF212B50837BC11A00BE47C" +lm_hash = "299BD128C1101FD6299BD128C1101FD6" +password_1 = "trytostealthis" +password_2 = "password" +password_3 = "12345678" + +PROPAGATION_CREDENTIALS_1 = Credentials( + identities=(Username(username),), + secrets=(NTHash(nt_hash), LMHash(lm_hash), Password(password_1)), +) +PROPAGATION_CREDENTIALS_2 = Credentials( + identities=(Username(username), Username(special_username)), + secrets=(Password(password_1), Password(password_2), Password(password_3)), +) diff --git a/monkey/tests/monkey_island/__init__.py b/monkey/tests/monkey_island/__init__.py index ee3098390..8bf003b21 100644 --- a/monkey/tests/monkey_island/__init__.py +++ b/monkey/tests/monkey_island/__init__.py @@ -4,7 +4,4 @@ from .open_error_file_repository import OpenErrorFileRepository from .in_memory_agent_configuration_repository import InMemoryAgentConfigurationRepository from .in_memory_simulation_configuration import InMemorySimulationRepository from .stub_propagation_credentials_repository import StubPropagationCredentialsRepository -from .stub_propagation_credentials_repository import ( - PROPAGATION_CREDENTIALS_1, - PROPAGATION_CREDENTIALS_2, -) +from .in_memory_credentials_repository import InMemoryCredentialsRepository diff --git a/monkey/tests/monkey_island/stub_propagation_credentials_repository.py b/monkey/tests/monkey_island/stub_propagation_credentials_repository.py index 73cae99bf..51c8964b2 100644 --- a/monkey/tests/monkey_island/stub_propagation_credentials_repository.py +++ b/monkey/tests/monkey_island/stub_propagation_credentials_repository.py @@ -1,23 +1,12 @@ from typing import Sequence -from common.credentials import Credentials, LMHash, NTHash, Password, Username -from monkey_island.cc.repository import ICredentialsRepository +from tests.data_for_tests.propagation_credentials import ( + PROPAGATION_CREDENTIALS_1, + PROPAGATION_CREDENTIALS_2, +) -fake_username = "m0nk3y_user" -fake_special_username = "m0nk3y.user" -fake_nt_hash = "C1C58F96CDF212B50837BC11A00BE47C" -fake_lm_hash = "299BD128C1101FD6299BD128C1101FD6" -fake_password_1 = "trytostealthis" -fake_password_2 = "password" -fake_password_3 = "12345678" -PROPAGATION_CREDENTIALS_1 = Credentials( - identities=(Username(fake_username),), - secrets=(NTHash(fake_nt_hash), LMHash(fake_lm_hash), Password(fake_password_1)), -) -PROPAGATION_CREDENTIALS_2 = Credentials( - identities=(Username(fake_username), Username(fake_special_username)), - secrets=(Password(fake_password_1), Password(fake_password_2), Password(fake_password_3)), -) +from common.credentials import Credentials +from monkey_island.cc.repository import ICredentialsRepository class StubPropagationCredentialsRepository(ICredentialsRepository): diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/credentials/test_configured_propagation_credentials.py b/monkey/tests/unit_tests/monkey_island/cc/resources/credentials/test_configured_propagation_credentials.py index 03d6a2414..5b4844fee 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/credentials/test_configured_propagation_credentials.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/credentials/test_configured_propagation_credentials.py @@ -1,14 +1,14 @@ import json -from tests.monkey_island import PROPAGATION_CREDENTIALS_1, PROPAGATION_CREDENTIALS_2 +from tests.data_for_tests.propagation_credentials import ( + PROPAGATION_CREDENTIALS_1, + PROPAGATION_CREDENTIALS_2, +) from tests.unit_tests.monkey_island.conftest import get_url_for_resource from monkey_island.cc.resources.credentials.configured_propagation_credentials import ( ConfiguredPropagationCredentials, ) -from monkey_island.cc.resources.credentials.stolen_propagation_credentials import ( - StolenPropagationCredentials, -) def test_configured_propagation_credentials_endpoint_get(flask_client): diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/credentials/test_stolen_propagation_credentials.py b/monkey/tests/unit_tests/monkey_island/cc/resources/credentials/test_stolen_propagation_credentials.py index 75976fb1d..138849085 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/credentials/test_stolen_propagation_credentials.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/credentials/test_stolen_propagation_credentials.py @@ -1,6 +1,9 @@ import json -from tests.monkey_island import PROPAGATION_CREDENTIALS_1, PROPAGATION_CREDENTIALS_2 +from tests.data_for_tests.propagation_credentials import ( + PROPAGATION_CREDENTIALS_1, + PROPAGATION_CREDENTIALS_2, +) from tests.unit_tests.monkey_island.conftest import get_url_for_resource from monkey_island.cc.resources.credentials.stolen_propagation_credentials import (