Skip to content

Commit 9897ef6

Browse files
committed
Updates /api/v2/health endpoint
Makes it require authenticated users. Simplifies back the management of the returned "access" field.
1 parent bb08807 commit 9897ef6

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

app/api/v2/handlers/health_api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from aiohttp import web
55

66
import app
7-
from app.api.v2 import security
87
from app.api.v2.handlers.base_api import BaseApi
98
from app.api.v2.schemas.caldera_info_schemas import CalderaInfoSchema
109

@@ -16,7 +15,7 @@ def __init__(self, services):
1615

1716
def add_routes(self, app: web.Application):
1817
router = app.router
19-
router.add_get('/health', security.authentication_exempt(self.get_health_info))
18+
router.add_get('/health', self.get_health_info)
2019

2120
@aiohttp_apispec.docs(tags=['health'],
2221
summary='Health endpoints returns the status of Caldera',
@@ -29,7 +28,7 @@ async def get_health_info(self, request):
2928
mapping = {
3029
'application': 'Caldera',
3130
'version': app.get_version(),
32-
'access': access[0].name if len(access) > 0 else None, # 0 when not authenticated.
31+
'access': access[0].name,
3332
'plugins': loaded_plugins_sorted
3433
}
3534

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import copy
2-
31
import pytest
42
import app
53

@@ -16,22 +14,13 @@ def expected_caldera_info():
1614
}
1715

1816

19-
@pytest.fixture
20-
def expected_unauthorized_caldera_info(expected_caldera_info):
21-
new_info = copy.deepcopy(expected_caldera_info)
22-
new_info['access'] = None
23-
return new_info
24-
25-
2617
class TestHealthApi:
2718
async def test_get_health(self, api_v2_client, api_cookies, expected_caldera_info):
2819
resp = await api_v2_client.get('/api/v2/health', cookies=api_cookies)
2920
assert resp.status == HTTPStatus.OK
3021
output_info = await resp.json()
3122
assert output_info == expected_caldera_info
3223

33-
async def test_unauthorized_get_health(self, api_v2_client, expected_unauthorized_caldera_info):
24+
async def test_unauthorized_get_health(self, api_v2_client):
3425
resp = await api_v2_client.get('/api/v2/health')
35-
assert resp.status == HTTPStatus.OK
36-
output_info = await resp.json()
37-
assert output_info == expected_unauthorized_caldera_info
26+
assert resp.status == HTTPStatus.UNAUTHORIZED

0 commit comments

Comments
 (0)