From 27b56e443e9bd4c54e409144669caff0fd0e6e13 Mon Sep 17 00:00:00 2001 From: blee Date: Tue, 5 Oct 2021 13:42:43 -0400 Subject: [PATCH 1/2] add pytests for health v2 api --- tests/api/v2/handlers/test_health_api.py | 40 ++++++++++++++++++++++++ tests/conftest.py | 2 ++ 2 files changed, 42 insertions(+) create mode 100644 tests/api/v2/handlers/test_health_api.py diff --git a/tests/api/v2/handlers/test_health_api.py b/tests/api/v2/handlers/test_health_api.py new file mode 100644 index 000000000..87b6d8172 --- /dev/null +++ b/tests/api/v2/handlers/test_health_api.py @@ -0,0 +1,40 @@ +import pytest +import app + +from http import HTTPStatus + + +@pytest.fixture +def expected_caldera_info(loop, api_v2_client, app_svc): + return { + 'application': 'CALDERA', + 'plugins': [ + { + 'address': '/plugin/sandcat/gui', + 'description': 'A custom multi-platform RAT', + 'enabled': True, + 'name': 'sandcat' + }, + { + 'address': 'plugin/ssl/gui', + 'description': 'Run an SSL proxy in front of the server', + 'enabled': False, + 'name': 'ssl' + } + ], + 'version': app.get_version() + } + + +class TestHealthApi: + async def test_get_health(self, api_v2_client, api_cookies, expected_caldera_info): + resp = await api_v2_client.get('/api/v2/health', cookies=api_cookies) + assert resp.status == HTTPStatus.OK + output_info = await resp.json() + assert output_info == expected_caldera_info + + async def test_unauthorized_get_health(self, api_v2_client, expected_caldera_info): + resp = await api_v2_client.get('/api/v2/health') + assert resp.status == HTTPStatus.OK + output_info = await resp.json() + assert output_info == expected_caldera_info diff --git a/tests/conftest.py b/tests/conftest.py index e8e735c92..0c1bed3b6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,6 +17,7 @@ from app.api.v2.handlers.operation_api import OperationApi from app.api.v2.handlers.contact_api import ContactApi from app.api.v2.handlers.obfuscator_api import ObfuscatorApi +from app.api.v2.handlers.health_api import HealthApi from app.objects.c_obfuscator import Obfuscator from app.utility.base_world import BaseWorld from app.service.app_svc import AppService @@ -275,6 +276,7 @@ def make_app(svcs): AdversaryApi(svcs).add_routes(app) ContactApi(svcs).add_routes(app) ObfuscatorApi(svcs).add_routes(app) + HealthApi(svcs).add_routes(app) return app async def initialize(): From dd99e9b51286a2d4f2a3a0243455a149536a53f3 Mon Sep 17 00:00:00 2001 From: blee Date: Tue, 5 Oct 2021 13:46:34 -0400 Subject: [PATCH 2/2] remove unnecessary params --- tests/api/v2/handlers/test_health_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api/v2/handlers/test_health_api.py b/tests/api/v2/handlers/test_health_api.py index 87b6d8172..1cad409bf 100644 --- a/tests/api/v2/handlers/test_health_api.py +++ b/tests/api/v2/handlers/test_health_api.py @@ -5,7 +5,7 @@ @pytest.fixture -def expected_caldera_info(loop, api_v2_client, app_svc): +def expected_caldera_info(): return { 'application': 'CALDERA', 'plugins': [