forked from p15670423/monkey
Island: Publish AgentRegistrationData from Agents resource
This commit is contained in:
parent
f811f91d73
commit
d514ac283c
|
@ -5,6 +5,7 @@ from http import HTTPStatus
|
|||
from flask import make_response, request
|
||||
|
||||
from common import AgentRegistrationData
|
||||
from monkey_island.cc.event_queue import IIslandEventQueue, IslandEventTopic
|
||||
from monkey_island.cc.resources.AbstractResource import AbstractResource
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -13,12 +14,18 @@ logger = logging.getLogger(__name__)
|
|||
class Agents(AbstractResource):
|
||||
urls = ["/api/agents"]
|
||||
|
||||
def __init__(self, island_event_queue: IIslandEventQueue):
|
||||
self._island_event_queue = island_event_queue
|
||||
|
||||
def post(self):
|
||||
try:
|
||||
# Just parse for now
|
||||
agent_registration_data = AgentRegistrationData(**request.json)
|
||||
|
||||
logger.debug(f"Agent registered: {agent_registration_data}")
|
||||
self._island_event_queue(
|
||||
IslandEventTopic.AGENT_CONNECTED, agent_registration_data=agent_registration_data
|
||||
)
|
||||
|
||||
return make_response({}, HTTPStatus.NO_CONTENT)
|
||||
except (TypeError, ValueError, json.JSONDecodeError) as err:
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
from http import HTTPStatus
|
||||
from unittest.mock import MagicMock
|
||||
from uuid import UUID
|
||||
|
||||
import pytest
|
||||
from tests.common import StubDIContainer
|
||||
from tests.unit_tests.monkey_island.conftest import get_url_for_resource
|
||||
|
||||
from monkey_island.cc.event_queue import IIslandEventQueue
|
||||
from monkey_island.cc.resources import Agents
|
||||
|
||||
AGENTS_URL = get_url_for_resource(Agents)
|
||||
|
@ -17,6 +21,15 @@ AGENT_REGISTRATION_DICT = {
|
|||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def flask_client(build_flask_client):
|
||||
container = StubDIContainer()
|
||||
container.register_instance(IIslandEventQueue, MagicMock(spec=IIslandEventQueue))
|
||||
|
||||
with build_flask_client(container) as flask_client:
|
||||
yield flask_client
|
||||
|
||||
|
||||
def test_agent_registration(flask_client):
|
||||
print(AGENTS_URL)
|
||||
resp = flask_client.post(
|
||||
|
|
Loading…
Reference in New Issue