stages/authenticator_validate: improve validation for not_configured_action
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
3b8cb9e525
commit
e22fce02f8
|
@ -11,16 +11,17 @@ from authentik.stages.authenticator_validate.models import AuthenticatorValidate
|
||||||
class AuthenticatorValidateStageSerializer(StageSerializer):
|
class AuthenticatorValidateStageSerializer(StageSerializer):
|
||||||
"""AuthenticatorValidateStage Serializer"""
|
"""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"""
|
"""Ensure that a configuration stage is set when not_configured_action is configure"""
|
||||||
not_configured_action = self.initial_data.get("not_configured_action", [])
|
configuration_stages = self.initial_data.get("configuration_stages", None)
|
||||||
if not_configured_action == NotConfiguredAction.CONFIGURE and len(value) < 1:
|
if value == NotConfiguredAction.CONFIGURE:
|
||||||
raise ValidationError(
|
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."
|
'When "Not configured action" is set to "Configure", '
|
||||||
|
"you must set a configuration stage."
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -68,7 +68,10 @@ class AuthenticatorValidateStageTests(FlowTestCase):
|
||||||
"""Test serializer validation"""
|
"""Test serializer validation"""
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
serializer = AuthenticatorValidateStageSerializer(
|
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.assertFalse(serializer.is_valid())
|
||||||
self.assertIn("not_configured_action", serializer.errors)
|
self.assertIn("not_configured_action", serializer.errors)
|
||||||
|
|
Reference in New Issue