From 5cab280759544faba25ab67362a08014e0d68cfa Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 1 Jan 2023 18:15:41 +0100 Subject: [PATCH] stages/captcha: fix captcha not loading correctly, add tests closes #4320 Signed-off-by: Jens Langhammer --- authentik/stages/captcha/stage.py | 2 +- authentik/stages/captcha/tests.py | 21 ++++++++++++++++++++- schema.yml | 1 - 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/authentik/stages/captcha/stage.py b/authentik/stages/captcha/stage.py index 4ea0738d6..e6782ef78 100644 --- a/authentik/stages/captcha/stage.py +++ b/authentik/stages/captcha/stage.py @@ -20,7 +20,7 @@ class CaptchaChallenge(WithUserInfoChallenge): """Site public key""" site_key = CharField() - js_url = CharField(read_only=True) + js_url = CharField() component = CharField(default="ak-stage-captcha") diff --git a/authentik/stages/captcha/tests.py b/authentik/stages/captcha/tests.py index fb335951b..e83fdd116 100644 --- a/authentik/stages/captcha/tests.py +++ b/authentik/stages/captcha/tests.py @@ -22,7 +22,7 @@ class TestCaptchaStage(FlowTestCase): self.user = create_test_admin_user() self.flow = create_test_flow(FlowDesignation.AUTHENTICATION) - self.stage = CaptchaStage.objects.create( + self.stage: CaptchaStage = CaptchaStage.objects.create( name="captcha", public_key=RECAPTCHA_PUBLIC_KEY, private_key=RECAPTCHA_PRIVATE_KEY, @@ -41,3 +41,22 @@ class TestCaptchaStage(FlowTestCase): ) self.assertEqual(response.status_code, 200) self.assertStageRedirects(response, reverse("authentik_core:root-redirect")) + + def test_urls(self): + """Test URLs captcha""" + self.stage.js_url = "https://test.goauthentik.io/test.js" + self.stage.api_url = "https://test.goauthentik.io/test" + self.stage.save() + plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()]) + session = self.client.session + session[SESSION_KEY_PLAN] = plan + session.save() + response = self.client.get( + reverse("authentik_api:flow-executor", kwargs={"flow_slug": self.flow.slug}), + ) + self.assertEqual(response.status_code, 200) + self.assertStageResponse( + response, + self.flow, + js_url="https://test.goauthentik.io/test.js", + ) diff --git a/schema.yml b/schema.yml index b53d9bcf2..8792d6d32 100644 --- a/schema.yml +++ b/schema.yml @@ -26358,7 +26358,6 @@ components: type: string js_url: type: string - readOnly: true required: - js_url - pending_user