This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/authentik/flows/tests/test_views_helper.py

40 lines
1.6 KiB
Python
Raw Normal View History

"""flow views tests"""
from django.test import TestCase
from django.urls import reverse
from authentik.core.tests.utils import create_test_flow
2020-12-05 21:08:42 +00:00
from authentik.flows.models import Flow, FlowDesignation
from authentik.flows.planner import FlowPlan
flows: inspector (#1469) * flows: add initial inspector Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * flows: change naming a bit Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web/flow: add inspector frame Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * core: don't use shadydom when inspecting Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * flows: add current stage to api Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * stages/*: fix imports Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * flows: deep-copy plan instead of just adding Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web/flows: ui Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * flows: restrict inspector to admin Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web/admin: add buttons to launch flow with inspector Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web/flows: don't automatically follow redirects when inspector is open Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * flows: make current_plan optional, only require historry Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web/flows: handle error messages in inspector Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web/flows: improve UI when flow is done Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * flows: add is_completed flag to inspector Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * flows: fix monkeypatches for tests Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * flows: add inspector tests Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * ci: re-enable cache Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
2021-09-28 07:36:48 +00:00
from authentik.flows.views.executor import SESSION_KEY_PLAN
class TestHelperView(TestCase):
"""Test helper views logic"""
def test_default_view(self):
"""Test that ToDefaultFlow returns the expected URL"""
Flow.objects.filter(designation=FlowDesignation.INVALIDATION).delete()
flow = create_test_flow(FlowDesignation.INVALIDATION)
2020-09-30 17:34:22 +00:00
response = self.client.get(
2020-12-05 21:08:42 +00:00
reverse("authentik_flows:default-invalidation"),
2020-09-30 17:34:22 +00:00
)
expected_url = reverse("authentik_core:if-flow", kwargs={"flow_slug": flow.slug})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, expected_url)
def test_default_view_invalid_plan(self):
"""Test that ToDefaultFlow returns the expected URL (with an invalid plan)"""
Flow.objects.filter(designation=FlowDesignation.INVALIDATION).delete()
flow = create_test_flow(FlowDesignation.INVALIDATION)
plan = FlowPlan(flow_pk=flow.pk.hex + "aa")
session = self.client.session
session[SESSION_KEY_PLAN] = plan
session.save()
2020-09-30 17:34:22 +00:00
response = self.client.get(
2020-12-05 21:08:42 +00:00
reverse("authentik_flows:default-invalidation"),
2020-09-30 17:34:22 +00:00
)
expected_url = reverse("authentik_core:if-flow", kwargs={"flow_slug": flow.slug})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, expected_url)