Skip to content

Commit

Permalink
stages/authenticator_validate: improve validation for not_configured_…
Browse files Browse the repository at this point in the history
…action

Signed-off-by: Jens Langhammer <[email protected]>
  • Loading branch information
BeryJu committed Nov 28, 2022
1 parent 3b8cb9e commit e22fce0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 9 additions & 8 deletions authentik/stages/authenticator_validate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
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:
Expand Down
5 changes: 4 additions & 1 deletion authentik/stages/authenticator_validate/tests/test_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def test_stage_validation(self):
"""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)
Expand Down

0 comments on commit e22fce0

Please sign in to comment.