UT: Add stolen and configured credentials endpoint tests

This commit is contained in:
vakarisz 2022-07-11 12:27:36 +03:00 committed by Mike Salvatore
parent c5ba5d444d
commit d437f02544
6 changed files with 102 additions and 1 deletions

View File

@ -25,7 +25,10 @@ class StubPropagationCredentialsRepository(ICredentialsRepository):
pass pass
def get_stolen_credentials(self) -> Sequence[Credentials]: def get_stolen_credentials(self) -> Sequence[Credentials]:
pass return [
Credentials.from_mapping(PROPAGATION_CREDENTIALS_1, monkey_guid="some_guid"),
Credentials.from_mapping(PROPAGATION_CREDENTIALS_2, monkey_guid="second_guid"),
]
def get_all_credentials(self) -> Sequence[Credentials]: def get_all_credentials(self) -> Sequence[Credentials]:

View File

@ -0,0 +1,15 @@
import pytest
from tests.common import StubDIContainer
from tests.monkey_island import StubPropagationCredentialsRepository
from monkey_island.cc.repository import ICredentialsRepository
@pytest.fixture
def flask_client(build_flask_client):
container = StubDIContainer()
container.register(ICredentialsRepository, StubPropagationCredentialsRepository)
with build_flask_client(container) as flask_client:
yield flask_client

View File

@ -0,0 +1,43 @@
import json
from tests.monkey_island 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):
configured_propagation_credentials_url = get_url_for_resource(ConfiguredPropagationCredentials)
resp = flask_client.get(configured_propagation_credentials_url)
assert resp.status_code == 200
actual_propagation_credentials = json.loads(resp.data)
assert len(actual_propagation_credentials) == 2
# TODO: delete the removal of monkey_guid key when the serialization of credentials
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
def test_configured_propagation_credentials_endpoint_post(flask_client):
configured_propagation_credentials_url = get_url_for_resource(ConfiguredPropagationCredentials)
resp = flask_client.post(configured_propagation_credentials_url, json=PROPAGATION_CREDENTIALS_1)
assert resp.status_code == 204
def test_configured_propagation_credentials_endpoint_delete(flask_client):
configured_propagation_credentials_url = get_url_for_resource(ConfiguredPropagationCredentials)
resp = flask_client.delete(configured_propagation_credentials_url)
assert resp.status_code == 204

View File

@ -0,0 +1,40 @@
import json
from tests.monkey_island 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 (
StolenPropagationCredentials,
)
def test_stolen_propagation_credentials_endpoint_get(flask_client):
stolen_propagation_credentials_url = get_url_for_resource(StolenPropagationCredentials)
resp = flask_client.get(stolen_propagation_credentials_url)
assert resp.status_code == 200
actual_propagation_credentials = json.loads(resp.data)
assert len(actual_propagation_credentials) == 2
# TODO: delete the removal of monkey_guid key when the serialization of credentials
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
def test_stolen_propagation_credentials_endpoint_post(flask_client):
stolen_propagation_credentials_url = get_url_for_resource(StolenPropagationCredentials)
resp = flask_client.post(stolen_propagation_credentials_url, json=PROPAGATION_CREDENTIALS_1)
assert resp.status_code == 204
def test_stolen_propagation_credentials_endpoint_delete(flask_client):
stolen_propagation_credentials_url = get_url_for_resource(StolenPropagationCredentials)
resp = flask_client.delete(stolen_propagation_credentials_url)
assert resp.status_code == 204