From 2275ba3addc1c0cae99d966005d160ca315a8f92 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 10 Jun 2021 12:17:46 +0200 Subject: [PATCH] flows: fix get_pending_user returning in-memory user when PLAN_CONTEXT_PENDING_USER_IDENTIFIER is set Signed-off-by: Jens Langhammer --- authentik/flows/stage.py | 9 ++++++--- authentik/flows/tests/test_views.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/authentik/flows/stage.py b/authentik/flows/stage.py index 968c1b876..3c32472c3 100644 --- a/authentik/flows/stage.py +++ b/authentik/flows/stage.py @@ -50,14 +50,17 @@ class StageView(View): self.executor = executor super().__init__(**kwargs) - def get_pending_user(self) -> User: + def get_pending_user(self, for_display=False) -> User: """Either show the matched User object or show what the user entered, based on what the earlier stage (mostly IdentificationStage) set. _USER_IDENTIFIER overrides the first User, as PENDING_USER is used for other things besides the form display. If no user is pending, returns request.user""" - if PLAN_CONTEXT_PENDING_USER_IDENTIFIER in self.executor.plan.context: + if ( + PLAN_CONTEXT_PENDING_USER_IDENTIFIER in self.executor.plan.context + and for_display + ): return User( username=self.executor.plan.context.get( PLAN_CONTEXT_PENDING_USER_IDENTIFIER @@ -109,7 +112,7 @@ class ChallengeStageView(StageView): # If there's a pending user, update the `username` field # this field is only used by password managers. # If there's no user set, an error is raised later. - if user := self.get_pending_user(): + if user := self.get_pending_user(for_display=True): challenge.initial_data["pending_user"] = user.username challenge.initial_data["pending_user_avatar"] = DEFAULT_AVATAR if not isinstance(user, AnonymousUser): diff --git a/authentik/flows/tests/test_views.py b/authentik/flows/tests/test_views.py index 16823d3f5..fee5ff259 100644 --- a/authentik/flows/tests/test_views.py +++ b/authentik/flows/tests/test_views.py @@ -511,4 +511,4 @@ class TestFlowExecutor(TestCase): executor.flow = flow stage_view = StageView(executor) - self.assertEqual(ident, stage_view.get_pending_user().username) + self.assertEqual(ident, stage_view.get_pending_user(for_display=True).username)