forked from p15670423/monkey
Merge pull request #2149 from guardicore/2105-new-api-endpoint-registration-status
New API endpoint for registration status
This commit is contained in:
commit
dc4749da63
|
@ -18,6 +18,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- The ability to download the Monkey Island logs from the Infection Map page. #1640
|
- The ability to download the Monkey Island logs from the Infection Map page. #1640
|
||||||
- `/api/reset-agent-configuration` endpoint. #2036
|
- `/api/reset-agent-configuration` endpoint. #2036
|
||||||
- `/api/clear-simulation-data` endpoint. #2036
|
- `/api/clear-simulation-data` endpoint. #2036
|
||||||
|
- `/api/registration-status` endpoint. #2149
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Reset workflow. Now it's possible to delete data gathered by agents without
|
- Reset workflow. Now it's possible to delete data gathered by agents without
|
||||||
|
|
|
@ -23,6 +23,7 @@ from monkey_island.cc.resources.agent_controls import StopAgentCheck, StopAllAge
|
||||||
from monkey_island.cc.resources.attack.attack_report import AttackReport
|
from monkey_island.cc.resources.attack.attack_report import AttackReport
|
||||||
from monkey_island.cc.resources.auth.authenticate import Authenticate, init_jwt
|
from monkey_island.cc.resources.auth.authenticate import Authenticate, init_jwt
|
||||||
from monkey_island.cc.resources.auth.register import Registration
|
from monkey_island.cc.resources.auth.register import Registration
|
||||||
|
from monkey_island.cc.resources.auth.registration_status import RegistrationStatus
|
||||||
from monkey_island.cc.resources.blackbox.log_blackbox_endpoint import LogBlackboxEndpoint
|
from monkey_island.cc.resources.blackbox.log_blackbox_endpoint import LogBlackboxEndpoint
|
||||||
from monkey_island.cc.resources.blackbox.monkey_blackbox_endpoint import MonkeyBlackboxEndpoint
|
from monkey_island.cc.resources.blackbox.monkey_blackbox_endpoint import MonkeyBlackboxEndpoint
|
||||||
from monkey_island.cc.resources.blackbox.telemetry_blackbox_endpoint import (
|
from monkey_island.cc.resources.blackbox.telemetry_blackbox_endpoint import (
|
||||||
|
@ -153,6 +154,7 @@ def init_api_resources(api: FlaskDIWrapper):
|
||||||
def init_restful_endpoints(api: FlaskDIWrapper):
|
def init_restful_endpoints(api: FlaskDIWrapper):
|
||||||
api.add_resource(Root)
|
api.add_resource(Root)
|
||||||
api.add_resource(Registration)
|
api.add_resource(Registration)
|
||||||
|
api.add_resource(RegistrationStatus)
|
||||||
api.add_resource(Authenticate)
|
api.add_resource(Authenticate)
|
||||||
api.add_resource(Monkey)
|
api.add_resource(Monkey)
|
||||||
api.add_resource(LocalRun)
|
api.add_resource(LocalRun)
|
||||||
|
|
|
@ -18,9 +18,6 @@ class Registration(AbstractResource):
|
||||||
def __init__(self, authentication_service: AuthenticationService):
|
def __init__(self, authentication_service: AuthenticationService):
|
||||||
self._authentication_service = authentication_service
|
self._authentication_service = authentication_service
|
||||||
|
|
||||||
def get(self):
|
|
||||||
return {"needs_registration": self._authentication_service.needs_registration()}
|
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
username, password = get_username_password_from_request(request)
|
username, password = get_username_password_from_request(request)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
from monkey_island.cc.resources.AbstractResource import AbstractResource
|
||||||
|
from monkey_island.cc.services import AuthenticationService
|
||||||
|
|
||||||
|
|
||||||
|
class RegistrationStatus(AbstractResource):
|
||||||
|
|
||||||
|
urls = ["/api/registration-status"]
|
||||||
|
|
||||||
|
def __init__(self, authentication_service: AuthenticationService):
|
||||||
|
self._authentication_service = authentication_service
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
return {"needs_registration": self._authentication_service.needs_registration()}
|
|
@ -4,6 +4,7 @@ export default class AuthService {
|
||||||
SECONDS_BEFORE_JWT_EXPIRES = 20;
|
SECONDS_BEFORE_JWT_EXPIRES = 20;
|
||||||
AUTHENTICATION_API_ENDPOINT = '/api/authenticate';
|
AUTHENTICATION_API_ENDPOINT = '/api/authenticate';
|
||||||
REGISTRATION_API_ENDPOINT = '/api/register';
|
REGISTRATION_API_ENDPOINT = '/api/register';
|
||||||
|
REGISTRATION_STATUS_API_ENDPOINT = '/api/registration-status';
|
||||||
|
|
||||||
login = (username, password) => {
|
login = (username, password) => {
|
||||||
return this._login(username, password);
|
return this._login(username, password);
|
||||||
|
@ -91,7 +92,7 @@ export default class AuthService {
|
||||||
};
|
};
|
||||||
|
|
||||||
needsRegistration = () => {
|
needsRegistration = () => {
|
||||||
return fetch(this.REGISTRATION_API_ENDPOINT,
|
return fetch(this.REGISTRATION_STATUS_API_ENDPOINT,
|
||||||
{method: 'GET'})
|
{method: 'GET'})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
|
|
@ -62,12 +62,3 @@ def test_internal_error(make_registration_request, mock_authentication_service):
|
||||||
response = make_registration_request(registration_request_body)
|
response = make_registration_request(registration_request_body)
|
||||||
|
|
||||||
assert response.status_code == 500
|
assert response.status_code == 500
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("needs_registration", [True, False])
|
|
||||||
def test_needs_registration(flask_client, mock_authentication_service, needs_registration):
|
|
||||||
mock_authentication_service.needs_registration = MagicMock(return_value=needs_registration)
|
|
||||||
response = flask_client.get(REGISTRATION_URL, follow_redirects=True)
|
|
||||||
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json["needs_registration"] is needs_registration
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from monkey_island.cc.resources.auth.registration_status import RegistrationStatus
|
||||||
|
|
||||||
|
REGISTRATION_STATUS_URL = RegistrationStatus.urls[0]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("needs_registration", [True, False])
|
||||||
|
def test_needs_registration(flask_client, mock_authentication_service, needs_registration):
|
||||||
|
mock_authentication_service.needs_registration = MagicMock(return_value=needs_registration)
|
||||||
|
response = flask_client.get(REGISTRATION_STATUS_URL, follow_redirects=True)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json["needs_registration"] is needs_registration
|
Loading…
Reference in New Issue