From 347746cbcd040ce7484710424067ce7c74d94e44 Mon Sep 17 00:00:00 2001 From: Jens L Date: Wed, 22 May 2024 18:12:31 +0200 Subject: [PATCH] enterprise/stages/source: fix error when creating source stage from blueprint (#9810) * enterprise/stages/source: fix error when creating source stage from blueprint Signed-off-by: Jens Langhammer * fix error for pretend user Signed-off-by: Jens Langhammer * fix unrelated frontend bug Signed-off-by: Jens Langhammer * cleanup Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- authentik/enterprise/stages/source/api.py | 9 ++++++--- authentik/enterprise/stages/source/stage.py | 2 +- authentik/stages/authenticator_webauthn/tests.py | 1 - web/src/flow/stages/FlowErrorStage.ts | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/authentik/enterprise/stages/source/api.py b/authentik/enterprise/stages/source/api.py index 5b2be29dc6..97afcffa8b 100644 --- a/authentik/enterprise/stages/source/api.py +++ b/authentik/enterprise/stages/source/api.py @@ -18,9 +18,12 @@ class SourceStageSerializer(EnterpriseRequiredMixin, StageSerializer): source = Source.objects.filter(pk=_source.pk).select_subclasses().first() if not source: raise ValidationError("Invalid source") - login_button = source.ui_login_button(self.context["request"]) - if not login_button: - raise ValidationError("Invalid source selected, only web-based sources are supported.") + if "request" in self.context: + login_button = source.ui_login_button(self.context["request"]) + if not login_button: + raise ValidationError( + "Invalid source selected, only web-based sources are supported." + ) return source class Meta: diff --git a/authentik/enterprise/stages/source/stage.py b/authentik/enterprise/stages/source/stage.py index a500d3138d..44d405d33a 100644 --- a/authentik/enterprise/stages/source/stage.py +++ b/authentik/enterprise/stages/source/stage.py @@ -54,7 +54,7 @@ class SourceStageView(ChallengeStageView): def create_flow_token(self) -> FlowToken: """Save the current flow state in a token that can be used to resume this flow""" pending_user: User = self.get_pending_user() - if pending_user.is_anonymous: + if pending_user.is_anonymous or not pending_user.pk: pending_user = get_anonymous_user() current_stage: SourceStage = self.executor.current_stage identifier = slugify(f"ak-source-stage-{current_stage.name}-{str(uuid4())}") diff --git a/authentik/stages/authenticator_webauthn/tests.py b/authentik/stages/authenticator_webauthn/tests.py index 0fa8794b52..c22ee64259 100644 --- a/authentik/stages/authenticator_webauthn/tests.py +++ b/authentik/stages/authenticator_webauthn/tests.py @@ -304,6 +304,5 @@ class TestAuthenticatorWebAuthnStage(FlowTestCase): SERVER_PORT="9000", ) self.assertEqual(response.status_code, 200) - print(response.content) self.assertStageRedirects(response, reverse("authentik_core:root-redirect")) self.assertTrue(WebAuthnDevice.objects.filter(user=self.user).exists()) diff --git a/web/src/flow/stages/FlowErrorStage.ts b/web/src/flow/stages/FlowErrorStage.ts index f7a83ee88c..4db4e53eeb 100644 --- a/web/src/flow/stages/FlowErrorStage.ts +++ b/web/src/flow/stages/FlowErrorStage.ts @@ -49,7 +49,7 @@ export class FlowErrorStage extends BaseStage