flows: use to_stage_response in _flow_done()

This commit is contained in:
Jens Langhammer 2020-12-17 19:31:16 +01:00
parent e1394207e7
commit 349a3a67d5
2 changed files with 14 additions and 2 deletions

View File

@ -8,7 +8,7 @@ from django.test.client import RequestFactory
from django.utils.encoding import force_str from django.utils.encoding import force_str
from authentik.core.models import User from authentik.core.models import User
from authentik.flows.exceptions import EmptyFlowException, FlowNonApplicableException from authentik.flows.exceptions import FlowNonApplicableException
from authentik.flows.markers import ReevaluateMarker, StageMarker from authentik.flows.markers import ReevaluateMarker, StageMarker
from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding
from authentik.flows.planner import FlowPlan, FlowPlanner from authentik.flows.planner import FlowPlan, FlowPlanner
@ -40,6 +40,10 @@ class TestFlowExecutor(TestCase):
def setUp(self): def setUp(self):
self.request_factory = RequestFactory() self.request_factory = RequestFactory()
@patch(
"authentik.flows.views.to_stage_response",
TO_STAGE_RESPONSE_MOCK,
)
def test_existing_plan_diff_flow(self): def test_existing_plan_diff_flow(self):
"""Check that a plan for a different flow cancels the current plan""" """Check that a plan for a different flow cancels the current plan"""
flow = Flow.objects.create( flow = Flow.objects.create(
@ -108,6 +112,10 @@ class TestFlowExecutor(TestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, reverse("authentik_core:shell")) self.assertEqual(response.url, reverse("authentik_core:shell"))
@patch(
"authentik.flows.views.to_stage_response",
TO_STAGE_RESPONSE_MOCK,
)
def test_invalid_flow_redirect(self): def test_invalid_flow_redirect(self):
"""Tests that an invalid flow still redirects""" """Tests that an invalid flow still redirects"""
flow = Flow.objects.create( flow = Flow.objects.create(
@ -157,6 +165,10 @@ class TestFlowExecutor(TestCase):
plan: FlowPlan = session[SESSION_KEY_PLAN] plan: FlowPlan = session[SESSION_KEY_PLAN]
self.assertEqual(len(plan.stages), 1) self.assertEqual(len(plan.stages), 1)
@patch(
"authentik.flows.views.to_stage_response",
TO_STAGE_RESPONSE_MOCK,
)
def test_reevaluate_remove_last(self): def test_reevaluate_remove_last(self):
"""Test planner with re-evaluate (last stage is removed)""" """Test planner with re-evaluate (last stage is removed)"""
flow = Flow.objects.create( flow = Flow.objects.create(

View File

@ -149,7 +149,7 @@ class FlowExecutorView(View):
NEXT_ARG_NAME, "authentik_core:shell" NEXT_ARG_NAME, "authentik_core:shell"
) )
self.cancel() self.cancel()
return redirect_with_qs(next_param) return to_stage_response(self.request, redirect_with_qs(next_param))
def stage_ok(self) -> HttpResponse: def stage_ok(self) -> HttpResponse:
"""Callback called by stages upon successful completion. """Callback called by stages upon successful completion.