diff --git a/monkey/monkey_island/cc/resources/island_mode.py b/monkey/monkey_island/cc/resources/island_mode.py index dd51d9fdb..b69b399c0 100644 --- a/monkey/monkey_island/cc/resources/island_mode.py +++ b/monkey/monkey_island/cc/resources/island_mode.py @@ -22,3 +22,5 @@ class IslandMode(flask_restful.Resource): return make_response({}, 200) except ValueError: return make_response({}, 422) + except Exception: + return make_response({}, 500) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py index 91c6d0435..df4e9c25a 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_island_mode.py @@ -1,8 +1,10 @@ import json import pytest +from tests.utils import raise_ from monkey_island.cc.models.island_mode_model import IslandMode +from monkey_island.cc.resources import island_mode as island_mode_resource @pytest.fixture(scope="function") @@ -24,6 +26,15 @@ def test_island_mode_post__invalid_mode(flask_client): assert resp.status_code == 422 +def test_island_mode_post__internal_server_error(monkeypatch, flask_client): + monkeypatch.setattr(island_mode_resource, "set_mode", lambda x: raise_(Exception())) + + resp = flask_client.post( + "/api/island-mode", data=json.dumps({"mode": "ransomware"}), follow_redirects=True + ) + assert resp.status_code == 500 + + def test_island_mode_post__set_model(flask_client, uses_database): flask_client.post( "/api/island-mode", data=json.dumps({"mode": "ransomware"}), follow_redirects=True