fix and add more tests

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-09-17 12:06:05 +02:00
parent aeff24d034
commit 75f79ba951
4 changed files with 15 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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