diff --git a/authentik/stages/prompt/models.py b/authentik/stages/prompt/models.py index 264f3b06d..bf196381b 100644 --- a/authentik/stages/prompt/models.py +++ b/authentik/stages/prompt/models.py @@ -119,10 +119,12 @@ class Prompt(SerializerModel): } if self.type == FieldTypes.TEXT: kwargs["trim_whitespace"] = False + kwargs["allow_blank"] = not self.required if self.type == FieldTypes.TEXT_READ_ONLY: field_class = ReadOnlyField if self.type == FieldTypes.EMAIL: field_class = EmailField + kwargs["allow_blank"] = not self.required if self.type == FieldTypes.NUMBER: field_class = IntegerField if self.type == FieldTypes.CHECKBOX: diff --git a/authentik/stages/prompt/tests.py b/authentik/stages/prompt/tests.py index cabb6e6a2..6e0ef2491 100644 --- a/authentik/stages/prompt/tests.py +++ b/authentik/stages/prompt/tests.py @@ -292,7 +292,7 @@ class TestPromptStage(FlowTestCase): prompt.save() -def field_type_tester_factory(field_type: FieldTypes): +def field_type_tester_factory(field_type: FieldTypes, required: bool): """Test field for field_type""" def tester(self: TestPromptStage): @@ -304,11 +304,16 @@ def field_type_tester_factory(field_type: FieldTypes): placeholder_expression=False, sub_text="test", order=123, + required=required, ) self.assertIsNotNone(prompt.field("foo")) return tester -for _type in FieldTypes: - setattr(TestPromptStage, f"test_field_type_{_type}", field_type_tester_factory(_type)) +for _required in (True, False): + for _type in FieldTypes: + test_name = f"test_field_type_{_type}" + if _required: + test_name += "_required" + setattr(TestPromptStage, test_name, field_type_tester_factory(_type, _required))