UT: Add test for GET propagation credentials

This commit is contained in:
Ilija Lazoroski 2022-07-06 13:04:01 +02:00
parent dda5e37764
commit a27edfa94b
3 changed files with 91 additions and 0 deletions

View File

@ -3,3 +3,4 @@ from .mock_file_repository import MockFileRepository, FILE_CONTENTS, FILE_NAME
from .open_error_file_repository import OpenErrorFileRepository
from .in_memory_agent_configuration_repository import InMemoryAgentConfigurationRepository
from .in_memory_simulation_configuration import InMemorySimulationRepository
from .propagation_credentials_repository import PropagationCredentialsRepository

View File

@ -0,0 +1,62 @@
from typing import Sequence
from monkey_island.cc.repository import ICredentialsRepository
from monkey_island.cc.services.telemetry.processing.credentials import Credentials
fake_username = "m0nk3y_user"
fake_special_username = "m0nk3y.user"
fake_nt_hash = "c1c58f96cdf212b50837bc11a00be47c"
fake_lm_hash = "299BD128C1101FD6"
fake_password_1 = "trytostealthis"
fake_password_2 = "password"
fake_password_3 = "12345678"
propagation_credentials_1 = {
"identities": [{"username": fake_username, "credential_type": "USERNAME"}],
"secrets": [
{"nt_hash": fake_nt_hash, "credential_type": "NT_HASH"},
{"lm_hash": fake_lm_hash, "credential_type": "LM_HASH"},
{"password": fake_password_1, "credential_type": "PASSWORD"},
],
}
propagation_credentials_2 = {
"identities": [
{"username": fake_username, "credential_type": "USERNAME"},
{"username": fake_special_username, "credential_type": "USERNAME"},
],
"secrets": [
{"password": fake_password_1, "credential_type": "PASSWORD"},
{"password": fake_password_2, "credential_type": "PASSWORD"},
{"password": fake_password_3, "credential_type": "PASSWORD"},
],
}
class PropagationCredentialsRepository(ICredentialsRepository):
def get_configured_credentials(self) -> Sequence[Credentials]:
pass
def get_stolen_credentials(self) -> Sequence[Credentials]:
pass
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"),
]
def save_configured_credentials(self, credentials: Credentials):
pass
def save_stolen_credentials(self, credentials: Credentials):
pass
def remove_configured_credentials(self):
pass
def remove_stolen_credentials(self):
pass
def remove_all_credentials(self):
pass

View File

@ -0,0 +1,28 @@
import json
import pytest
from tests.common import StubDIContainer
from tests.monkey_island import PropagationCredentialsRepository
from tests.unit_tests.monkey_island.conftest import get_url_for_resource
from monkey_island.cc.repository import ICredentialsRepository
from monkey_island.cc.resources.propagation_credentials import PropagationCredentials
@pytest.fixture
def flask_client(build_flask_client):
container = StubDIContainer()
container.register(ICredentialsRepository, PropagationCredentialsRepository)
with build_flask_client(container) as flask_client:
yield flask_client
def test_propagation_credentials_endpoint_get(flask_client):
propagation_credentials_url = get_url_for_resource(PropagationCredentials)
resp = flask_client.get(propagation_credentials_url)
assert resp.status_code == 200
assert len(json.loads(resp.data)["propagation_credentials"]) == 2