From 777897cb742181a2b0367570ce6c804a0c4b7f0d Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Wed, 6 Jul 2022 15:16:05 +0200 Subject: [PATCH] UT: Compare actual propagation credentials vs expected --- monkey/tests/monkey_island/__init__.py | 4 ++++ .../stub_propagation_credentials_repository.py | 8 ++++---- .../cc/resources/test_propagation_credentials.py | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/monkey/tests/monkey_island/__init__.py b/monkey/tests/monkey_island/__init__.py index df36a5d01..ee3098390 100644 --- a/monkey/tests/monkey_island/__init__.py +++ b/monkey/tests/monkey_island/__init__.py @@ -4,3 +4,7 @@ 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, +) diff --git a/monkey/tests/monkey_island/stub_propagation_credentials_repository.py b/monkey/tests/monkey_island/stub_propagation_credentials_repository.py index 3e3978e36..7eeec1815 100644 --- a/monkey/tests/monkey_island/stub_propagation_credentials_repository.py +++ b/monkey/tests/monkey_island/stub_propagation_credentials_repository.py @@ -10,7 +10,7 @@ fake_lm_hash = "299BD128C1101FD6" fake_password_1 = "trytostealthis" fake_password_2 = "password" fake_password_3 = "12345678" -propagation_credentials_1 = { +PROPAGATION_CREDENTIALS_1 = { "identities": [{"username": fake_username, "credential_type": "USERNAME"}], "secrets": [ {"nt_hash": fake_nt_hash, "credential_type": "NT_HASH"}, @@ -19,7 +19,7 @@ propagation_credentials_1 = { ], } -propagation_credentials_2 = { +PROPAGATION_CREDENTIALS_2 = { "identities": [ {"username": fake_username, "credential_type": "USERNAME"}, {"username": fake_special_username, "credential_type": "USERNAME"}, @@ -42,8 +42,8 @@ class StubPropagationCredentialsRepository(ICredentialsRepository): def get_all_credentials(self) -> Sequence[Credentials]: return [ - Credentials.from_mapping(propagation_credentials_1, monkey_guid="some_guid"), - Credentials.from_mapping(propagation_credentials_2, monkey_guid="second_guid"), + Credentials.from_mapping(PROPAGATION_CREDENTIALS_1, monkey_guid="some_guid"), + Credentials.from_mapping(PROPAGATION_CREDENTIALS_2, monkey_guid="second_guid"), ] def save_configured_credentials(self, credentials: Credentials): diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_propagation_credentials.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_propagation_credentials.py index 26e9fb233..e1469b1ea 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_propagation_credentials.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_propagation_credentials.py @@ -2,7 +2,11 @@ import json import pytest from tests.common import StubDIContainer -from tests.monkey_island import StubPropagationCredentialsRepository +from tests.monkey_island import ( + PROPAGATION_CREDENTIALS_1, + PROPAGATION_CREDENTIALS_2, + StubPropagationCredentialsRepository, +) from tests.unit_tests.monkey_island.conftest import get_url_for_resource from monkey_island.cc.repository import ICredentialsRepository @@ -25,4 +29,10 @@ def test_propagation_credentials_endpoint_get(flask_client): resp = flask_client.get(propagation_credentials_url) assert resp.status_code == 200 - assert len(json.loads(resp.data)["propagation_credentials"]) == 2 + actual_propagation_credentials = json.loads(resp.data)["propagation_credentials"] + assert len(actual_propagation_credentials) == 2 + + del actual_propagation_credentials[0]["monkey_guid"] + assert actual_propagation_credentials[0] == PROPAGATION_CREDENTIALS_1 + del actual_propagation_credentials[1]["monkey_guid"] + assert actual_propagation_credentials[1] == PROPAGATION_CREDENTIALS_2