diff --git a/authentik/stages/dummy/api.py b/authentik/stages/dummy/api.py index 25f23abfd2..bdc451ba76 100644 --- a/authentik/stages/dummy/api.py +++ b/authentik/stages/dummy/api.py @@ -12,7 +12,7 @@ class DummyStageSerializer(StageSerializer): class Meta: model = DummyStage - fields = StageSerializer.Meta.fields + fields = StageSerializer.Meta.fields + ["throw_error"] class DummyStageViewSet(UsedByMixin, ModelViewSet): diff --git a/authentik/stages/dummy/migrations/0002_dummystage_throw_error.py b/authentik/stages/dummy/migrations/0002_dummystage_throw_error.py new file mode 100644 index 0000000000..60a2895b47 --- /dev/null +++ b/authentik/stages/dummy/migrations/0002_dummystage_throw_error.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.4 on 2023-01-01 19:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentik_stages_dummy", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="dummystage", + name="throw_error", + field=models.BooleanField(default=False), + ), + ] diff --git a/authentik/stages/dummy/models.py b/authentik/stages/dummy/models.py index 88489899a4..acf4e310e7 100644 --- a/authentik/stages/dummy/models.py +++ b/authentik/stages/dummy/models.py @@ -1,5 +1,5 @@ """dummy stage models""" - +from django.db import models from django.utils.translation import gettext as _ from django.views import View from rest_framework.serializers import BaseSerializer @@ -10,6 +10,8 @@ from authentik.flows.models import Stage class DummyStage(Stage): """Used for debugging.""" + throw_error = models.BooleanField(default=False) + __debug_only__ = True @property diff --git a/authentik/stages/dummy/stage.py b/authentik/stages/dummy/stage.py index 3732c71de1..77423dd4e4 100644 --- a/authentik/stages/dummy/stage.py +++ b/authentik/stages/dummy/stage.py @@ -4,6 +4,7 @@ from rest_framework.fields import CharField from authentik.flows.challenge import Challenge, ChallengeResponse, ChallengeTypes from authentik.flows.stage import ChallengeStageView +from authentik.lib.sentry import SentryIgnoredException class DummyChallenge(Challenge): @@ -27,6 +28,8 @@ class DummyStageView(ChallengeStageView): return self.executor.stage_ok() def get_challenge(self, *args, **kwargs) -> Challenge: + if self.executor.current_stage.throw_error: + raise SentryIgnoredException("Test error") return DummyChallenge( data={ "type": ChallengeTypes.NATIVE.value, diff --git a/schema.yml b/schema.yml index 8792d6d327..ac68062cf5 100644 --- a/schema.yml +++ b/schema.yml @@ -21607,6 +21607,10 @@ paths: schema: type: string format: uuid + - in: query + name: throw_error + schema: + type: boolean tags: - stages security: @@ -27177,6 +27181,8 @@ components: type: array items: $ref: '#/components/schemas/FlowSet' + throw_error: + type: boolean required: - component - meta_model_name @@ -27195,6 +27201,8 @@ components: type: array items: $ref: '#/components/schemas/FlowSetRequest' + throw_error: + type: boolean required: - name DuoDevice: @@ -33739,6 +33747,8 @@ components: type: array items: $ref: '#/components/schemas/FlowSetRequest' + throw_error: + type: boolean PatchedDuoDeviceRequest: type: object description: Serializer for Duo authenticator devices diff --git a/web/src/admin/stages/dummy/DummyStageForm.ts b/web/src/admin/stages/dummy/DummyStageForm.ts index 950695e315..336cc0acf5 100644 --- a/web/src/admin/stages/dummy/DummyStageForm.ts +++ b/web/src/admin/stages/dummy/DummyStageForm.ts @@ -1,4 +1,5 @@ import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; +import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/HorizontalFormElement"; import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; @@ -52,6 +53,16 @@ export class DummyStageForm extends ModelForm { required /> + +
+ + +
+
`; } }