From e22fce02f88efb77aeb53bb1c54890eaec2fe92a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 28 Nov 2022 10:52:51 +0100 Subject: [PATCH] stages/authenticator_validate: improve validation for not_configured_action Signed-off-by: Jens Langhammer --- authentik/stages/authenticator_validate/api.py | 17 +++++++++-------- .../authenticator_validate/tests/test_stage.py | 5 ++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/authentik/stages/authenticator_validate/api.py b/authentik/stages/authenticator_validate/api.py index ecae971ac..9d48b6aff 100644 --- a/authentik/stages/authenticator_validate/api.py +++ b/authentik/stages/authenticator_validate/api.py @@ -11,16 +11,17 @@ from authentik.stages.authenticator_validate.models import AuthenticatorValidate class AuthenticatorValidateStageSerializer(StageSerializer): """AuthenticatorValidateStage Serializer""" - def validate_configuration_stages(self, value): + def validate_not_configured_action(self, value): """Ensure that a configuration stage is set when not_configured_action is configure""" - not_configured_action = self.initial_data.get("not_configured_action", []) - if not_configured_action == NotConfiguredAction.CONFIGURE and len(value) < 1: - raise ValidationError( - ( - 'When "Not configured action" is set to "Configure", ' - "you must set a configuration stage." + configuration_stages = self.initial_data.get("configuration_stages", None) + if value == NotConfiguredAction.CONFIGURE: + if not configuration_stages or len(configuration_stages) < 1: + raise ValidationError( + ( + 'When "Not configured action" is set to "Configure", ' + "you must set a configuration stage." + ) ) - ) return value class Meta: diff --git a/authentik/stages/authenticator_validate/tests/test_stage.py b/authentik/stages/authenticator_validate/tests/test_stage.py index 3fed9a6c0..4dc8170d6 100644 --- a/authentik/stages/authenticator_validate/tests/test_stage.py +++ b/authentik/stages/authenticator_validate/tests/test_stage.py @@ -68,7 +68,10 @@ class AuthenticatorValidateStageTests(FlowTestCase): """Test serializer validation""" self.client.force_login(self.user) serializer = AuthenticatorValidateStageSerializer( - data={"name": generate_id(), "not_configured_action": NotConfiguredAction.CONFIGURE} + data={ + "name": generate_id(), + "not_configured_action": NotConfiguredAction.CONFIGURE, + } ) self.assertFalse(serializer.is_valid()) self.assertIn("not_configured_action", serializer.errors)