UT: Fix false negative in test_agent_configuration_endpoint()

This commit is contained in:
Mike Salvatore 2022-07-22 11:49:54 -04:00
parent f321d72dc5
commit 1b1bc85804
1 changed files with 14 additions and 12 deletions

View File

@ -6,8 +6,13 @@ from tests.common.example_agent_configuration import AGENT_CONFIGURATION
from tests.monkey_island import InMemoryAgentConfigurationRepository
from tests.unit_tests.monkey_island.conftest import get_url_for_resource
from common.configuration import AgentConfiguration
from monkey_island.cc.repository import IAgentConfigurationRepository
from monkey_island.cc.resources.agent_configuration import AgentConfiguration
from monkey_island.cc.resources.agent_configuration import (
AgentConfiguration as AgentConfigurationResource,
)
AGENT_CONFIGURATION_URL = get_url_for_resource(AgentConfigurationResource)
@pytest.fixture
@ -21,30 +26,27 @@ def flask_client(build_flask_client):
def test_agent_configuration_endpoint(flask_client):
agent_configuration_url = get_url_for_resource(AgentConfiguration)
flask_client.post(
agent_configuration_url, data=json.dumps(AGENT_CONFIGURATION), follow_redirects=True
resp = flask_client.post(
AGENT_CONFIGURATION_URL,
data=AgentConfiguration.to_json(AGENT_CONFIGURATION),
follow_redirects=True,
)
resp = flask_client.get(agent_configuration_url)
assert resp.status_code == 200
resp = flask_client.get(AGENT_CONFIGURATION_URL)
assert resp.status_code == 200
assert json.loads(resp.data) == AGENT_CONFIGURATION
def test_agent_configuration_invalid_config(flask_client):
agent_configuration_url = get_url_for_resource(AgentConfiguration)
resp = flask_client.post(
agent_configuration_url, data=json.dumps({"invalid_config": "invalid_stuff"})
AGENT_CONFIGURATION_URL, data=json.dumps({"invalid_config": "invalid_stuff"})
)
assert resp.status_code == 400
def test_agent_configuration_invalid_json(flask_client):
agent_configuration_url = get_url_for_resource(AgentConfiguration)
resp = flask_client.post(agent_configuration_url, data="InvalidJson!")
resp = flask_client.post(AGENT_CONFIGURATION_URL, data="InvalidJson!")
assert resp.status_code == 400