stages/captcha: fix captcha not loading correctly, add tests

closes #4320

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2023-01-01 18:15:41 +01:00
parent a03a64b35c
commit 5cab280759
No known key found for this signature in database
3 changed files with 21 additions and 3 deletions

View file

@ -20,7 +20,7 @@ class CaptchaChallenge(WithUserInfoChallenge):
"""Site public key""" """Site public key"""
site_key = CharField() site_key = CharField()
js_url = CharField(read_only=True) js_url = CharField()
component = CharField(default="ak-stage-captcha") component = CharField(default="ak-stage-captcha")

View file

@ -22,7 +22,7 @@ class TestCaptchaStage(FlowTestCase):
self.user = create_test_admin_user() self.user = create_test_admin_user()
self.flow = create_test_flow(FlowDesignation.AUTHENTICATION) self.flow = create_test_flow(FlowDesignation.AUTHENTICATION)
self.stage = CaptchaStage.objects.create( self.stage: CaptchaStage = CaptchaStage.objects.create(
name="captcha", name="captcha",
public_key=RECAPTCHA_PUBLIC_KEY, public_key=RECAPTCHA_PUBLIC_KEY,
private_key=RECAPTCHA_PRIVATE_KEY, private_key=RECAPTCHA_PRIVATE_KEY,
@ -41,3 +41,22 @@ class TestCaptchaStage(FlowTestCase):
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertStageRedirects(response, reverse("authentik_core:root-redirect")) 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",
)

View file

@ -26358,7 +26358,6 @@ components:
type: string type: string
js_url: js_url:
type: string type: string
readOnly: true
required: required:
- js_url - js_url
- pending_user - pending_user