diff --git a/monkey/common/utils/exceptions.py b/monkey/common/utils/exceptions.py index dd84380f6..cc70cbc51 100644 --- a/monkey/common/utils/exceptions.py +++ b/monkey/common/utils/exceptions.py @@ -10,11 +10,7 @@ class InvalidRegistrationCredentialsError(Exception): """ Raise when server config file changed and island needs to restart """ -class RegistrationNotNeededError(Exception): - """ Raise to indicate the reason why registration is not required """ - - -class AlreadyRegisteredError(RegistrationNotNeededError): +class AlreadyRegisteredError(Exception): """ Raise to indicate the reason why registration is not required """ diff --git a/monkey/monkey_island/cc/resources/auth/registration.py b/monkey/monkey_island/cc/resources/auth/registration.py index bc9f3086f..175582733 100644 --- a/monkey/monkey_island/cc/resources/auth/registration.py +++ b/monkey/monkey_island/cc/resources/auth/registration.py @@ -3,7 +3,7 @@ import logging import flask_restful from flask import make_response, request -from common.utils.exceptions import InvalidRegistrationCredentialsError, RegistrationNotNeededError +from common.utils.exceptions import AlreadyRegisteredError, InvalidRegistrationCredentialsError from monkey_island.cc.resources.auth.credential_utils import get_username_password_from_request from monkey_island.cc.services import AuthenticationService @@ -20,5 +20,5 @@ class Registration(flask_restful.Resource): try: AuthenticationService.register_new_user(username, password) return make_response({"error": ""}, 200) - except (InvalidRegistrationCredentialsError, RegistrationNotNeededError) as e: + except (InvalidRegistrationCredentialsError, AlreadyRegisteredError) as e: return make_response({"error": str(e)}, 400) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/auth/test_registration.py b/monkey/tests/unit_tests/monkey_island/cc/resources/auth/test_registration.py index 0b1b60251..041eec264 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/auth/test_registration.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/auth/test_registration.py @@ -3,7 +3,7 @@ from unittest.mock import MagicMock import pytest -from common.utils.exceptions import InvalidRegistrationCredentialsError, RegistrationNotNeededError +from common.utils.exceptions import AlreadyRegisteredError, InvalidRegistrationCredentialsError REGISTRATION_URL = "/api/registration" @@ -59,9 +59,7 @@ def test_invalid_credentials(make_registration_request, mock_authentication_serv def test_registration_not_needed(make_registration_request, mock_authentication_service): - mock_authentication_service.register_new_user = MagicMock( - side_effect=RegistrationNotNeededError() - ) + mock_authentication_service.register_new_user = MagicMock(side_effect=AlreadyRegisteredError()) registration_request_body = "{}" response = make_registration_request(registration_request_body)