forked from p15670423/monkey
Island: Remove RegistrationNotNeeded exception
This commit is contained in:
parent
8dfacbc099
commit
f5e1b46a31
|
@ -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 """
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue