forked from p15670423/monkey
Island: Return 500 from POST /api/island-mode if unexpected exception
This commit is contained in:
parent
acdfeb858f
commit
7549e64b41
|
@ -22,3 +22,5 @@ class IslandMode(flask_restful.Resource):
|
||||||
return make_response({}, 200)
|
return make_response({}, 200)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return make_response({}, 422)
|
return make_response({}, 422)
|
||||||
|
except Exception:
|
||||||
|
return make_response({}, 500)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from tests.utils import raise_
|
||||||
|
|
||||||
from monkey_island.cc.models.island_mode_model import IslandMode
|
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")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -24,6 +26,15 @@ def test_island_mode_post__invalid_mode(flask_client):
|
||||||
assert resp.status_code == 422
|
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):
|
def test_island_mode_post__set_model(flask_client, uses_database):
|
||||||
flask_client.post(
|
flask_client.post(
|
||||||
"/api/island-mode", data=json.dumps({"mode": "ransomware"}), follow_redirects=True
|
"/api/island-mode", data=json.dumps({"mode": "ransomware"}), follow_redirects=True
|
||||||
|
|
Loading…
Reference in New Issue