Island: Return 500 from POST /api/island-mode if unexpected exception

This commit is contained in:
Mike Salvatore 2021-07-13 10:46:47 -04:00
parent acdfeb858f
commit 7549e64b41
2 changed files with 13 additions and 0 deletions

View File

@ -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)

View File

@ -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