Island: Remove RegistrationNotNeeded exception

This commit is contained in:
Ilija Lazoroski 2021-11-18 16:28:11 +01:00
parent 8dfacbc099
commit f5e1b46a31
3 changed files with 5 additions and 11 deletions

View File

@ -10,11 +10,7 @@ class InvalidRegistrationCredentialsError(Exception):
""" Raise when server config file changed and island needs to restart """ """ Raise when server config file changed and island needs to restart """
class RegistrationNotNeededError(Exception): class AlreadyRegisteredError(Exception):
""" Raise to indicate the reason why registration is not required """
class AlreadyRegisteredError(RegistrationNotNeededError):
""" Raise to indicate the reason why registration is not required """ """ Raise to indicate the reason why registration is not required """

View File

@ -3,7 +3,7 @@ import logging
import flask_restful import flask_restful
from flask import make_response, request 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.resources.auth.credential_utils import get_username_password_from_request
from monkey_island.cc.services import AuthenticationService from monkey_island.cc.services import AuthenticationService
@ -20,5 +20,5 @@ class Registration(flask_restful.Resource):
try: try:
AuthenticationService.register_new_user(username, password) AuthenticationService.register_new_user(username, password)
return make_response({"error": ""}, 200) return make_response({"error": ""}, 200)
except (InvalidRegistrationCredentialsError, RegistrationNotNeededError) as e: except (InvalidRegistrationCredentialsError, AlreadyRegisteredError) as e:
return make_response({"error": str(e)}, 400) return make_response({"error": str(e)}, 400)

View File

@ -3,7 +3,7 @@ from unittest.mock import MagicMock
import pytest import pytest
from common.utils.exceptions import InvalidRegistrationCredentialsError, RegistrationNotNeededError from common.utils.exceptions import AlreadyRegisteredError, InvalidRegistrationCredentialsError
REGISTRATION_URL = "/api/registration" 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): def test_registration_not_needed(make_registration_request, mock_authentication_service):
mock_authentication_service.register_new_user = MagicMock( mock_authentication_service.register_new_user = MagicMock(side_effect=AlreadyRegisteredError())
side_effect=RegistrationNotNeededError()
)
registration_request_body = "{}" registration_request_body = "{}"
response = make_registration_request(registration_request_body) response = make_registration_request(registration_request_body)