From 75f79ba951fbcb9ceb0fe5bb25bc31868f883d2b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 17 Sep 2022 12:06:05 +0200 Subject: [PATCH] fix and add more tests Signed-off-by: Jens Langhammer --- authentik/flows/tests/test_inspector.py | 6 +++--- authentik/flows/tests/test_planner.py | 4 ++-- authentik/root/monitoring.py | 4 ++-- authentik/root/tests.py | 8 ++++++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/authentik/flows/tests/test_inspector.py b/authentik/flows/tests/test_inspector.py index 25fafe926..49ba59356 100644 --- a/authentik/flows/tests/test_inspector.py +++ b/authentik/flows/tests/test_inspector.py @@ -8,7 +8,7 @@ from rest_framework.test import APITestCase from authentik.core.tests.utils import create_test_admin_user, create_test_flow from authentik.flows.challenge import ChallengeTypes -from authentik.flows.models import FlowStageBinding, InvalidResponseAction +from authentik.flows.models import FlowDesignation, FlowStageBinding, InvalidResponseAction from authentik.stages.dummy.models import DummyStage from authentik.stages.identification.models import IdentificationStage, UserFields @@ -23,7 +23,7 @@ class TestFlowInspector(APITestCase): def test(self): """test inspector""" - flow = create_test_flow() + flow = create_test_flow(FlowDesignation.AUTHENTICATION) # Stage 1 is an identification stage ident_stage = IdentificationStage.objects.create( @@ -50,7 +50,7 @@ class TestFlowInspector(APITestCase): "flow_info": { "background": flow.background_url, "cancel_url": reverse("authentik_flows:cancel"), - "title": "", + "title": flow.title, "layout": "stacked", }, "type": ChallengeTypes.NATIVE.value, diff --git a/authentik/flows/tests/test_planner.py b/authentik/flows/tests/test_planner.py index 92141b608..e7da06e0a 100644 --- a/authentik/flows/tests/test_planner.py +++ b/authentik/flows/tests/test_planner.py @@ -11,7 +11,7 @@ from authentik.core.models import User from authentik.core.tests.utils import create_test_flow from authentik.flows.exceptions import EmptyFlowException, FlowNonApplicableException from authentik.flows.markers import ReevaluateMarker, StageMarker -from authentik.flows.models import FlowStageBinding +from authentik.flows.models import FlowDesignation, FlowStageBinding from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlanner, cache_key from authentik.lib.tests.utils import dummy_get_response from authentik.policies.dummy.models import DummyPolicy @@ -62,7 +62,7 @@ class TestFlowPlanner(TestCase): @patch("authentik.flows.planner.cache", CACHE_MOCK) def test_planner_cache(self): """Test planner cache""" - flow = create_test_flow() + flow = create_test_flow(FlowDesignation.AUTHENTICATION) FlowStageBinding.objects.create( target=flow, stage=DummyStage.objects.create(name="dummy"), order=0 ) diff --git a/authentik/root/monitoring.py b/authentik/root/monitoring.py index 2c0b2d129..7b4ba1e4f 100644 --- a/authentik/root/monitoring.py +++ b/authentik/root/monitoring.py @@ -48,11 +48,11 @@ class ReadyView(View): try: db_conn = connections["default"] _ = db_conn.cursor() - except OperationalError: + except OperationalError: # pragma: no cover return HttpResponse(status=503) try: redis_conn = get_redis_connection() redis_conn.ping() - except RedisError: + except RedisError: # pragma: no cover return HttpResponse(status=503) return HttpResponse(status=204) diff --git a/authentik/root/tests.py b/authentik/root/tests.py index 4ed4f9532..444a4ada6 100644 --- a/authentik/root/tests.py +++ b/authentik/root/tests.py @@ -20,3 +20,11 @@ class TestRoot(TestCase): auth_headers = {"HTTP_AUTHORIZATION": creds} response = self.client.get(reverse("metrics"), **auth_headers) self.assertEqual(response.status_code, 200) + + def test_monitoring_live(self): + """Test LiveView""" + self.assertEqual(self.client.get(reverse("health-live")).status_code, 204) + + def test_monitoring_ready(self): + """Test ReadyView""" + self.assertEqual(self.client.get(reverse("health-ready")).status_code, 204)