stages/authenticator_validate: use friendly_name for stage selector when enrolling (#8255)

* stages/authenticator_validate: use friendly_name for stage selector when enrolling

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix tests

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L
2024-01-22 16:06:38 +01:00
committed by GitHub
parent 6dd2fc3c45
commit b1c7c228c3
7 changed files with 31 additions and 25 deletions

View File

@ -38,4 +38,11 @@ class Migration(migrations.Migration):
name="statictoken", name="statictoken",
options={"verbose_name": "Static Token", "verbose_name_plural": "Static Tokens"}, options={"verbose_name": "Static Token", "verbose_name_plural": "Static Tokens"},
), ),
migrations.AlterModelOptions(
name="authenticatorstaticstage",
options={
"verbose_name": "Static Authenticator Setup Stage",
"verbose_name_plural": "Static Authenticator Setup Stages",
},
),
] ]

View File

@ -46,11 +46,11 @@ class AuthenticatorStaticStage(ConfigurableStage, FriendlyNamedStage, Stage):
) )
def __str__(self) -> str: def __str__(self) -> str:
return f"Static Authenticator Stage {self.name}" return f"Static Authenticator Setup Stage {self.name}"
class Meta: class Meta:
verbose_name = _("Static Authenticator Stage") verbose_name = _("Static Authenticator Setup Stage")
verbose_name_plural = _("Static Authenticator Stages") verbose_name_plural = _("Static Authenticator Setup Stages")
class StaticDevice(SerializerModel, ThrottlingMixin, Device): class StaticDevice(SerializerModel, ThrottlingMixin, Device):

View File

@ -300,8 +300,10 @@ class AuthenticatorValidateStageView(ChallengeStageView):
serializer = SelectableStageSerializer( serializer = SelectableStageSerializer(
data={ data={
"pk": stage.pk, "pk": stage.pk,
"name": stage.name, "name": stage.friendly_name or stage.name,
"verbose_name": str(stage._meta.verbose_name), "verbose_name": str(stage._meta.verbose_name)
.replace("Setup Stage", "")
.strip(),
"meta_model_name": f"{stage._meta.app_label}.{stage._meta.model_name}", "meta_model_name": f"{stage._meta.app_label}.{stage._meta.model_name}",
} }
) )

View File

@ -11,6 +11,7 @@ from authentik.flows.tests import FlowTestCase
from authentik.flows.views.executor import SESSION_KEY_PLAN from authentik.flows.views.executor import SESSION_KEY_PLAN
from authentik.lib.generators import generate_id, generate_key from authentik.lib.generators import generate_id, generate_key
from authentik.stages.authenticator_duo.models import AuthenticatorDuoStage, DuoDevice from authentik.stages.authenticator_duo.models import AuthenticatorDuoStage, DuoDevice
from authentik.stages.authenticator_static.models import AuthenticatorStaticStage
from authentik.stages.authenticator_validate.api import AuthenticatorValidateStageSerializer from authentik.stages.authenticator_validate.api import AuthenticatorValidateStageSerializer
from authentik.stages.authenticator_validate.models import AuthenticatorValidateStage, DeviceClasses from authentik.stages.authenticator_validate.models import AuthenticatorValidateStage, DeviceClasses
from authentik.stages.authenticator_validate.stage import PLAN_CONTEXT_DEVICE_CHALLENGES from authentik.stages.authenticator_validate.stage import PLAN_CONTEXT_DEVICE_CHALLENGES
@ -26,19 +27,22 @@ class AuthenticatorValidateStageTests(FlowTestCase):
def test_not_configured_action(self): def test_not_configured_action(self):
"""Test not_configured_action""" """Test not_configured_action"""
conf_stage = IdentificationStage.objects.create( ident_stage = IdentificationStage.objects.create(
name=generate_id(), name=generate_id(),
user_fields=[ user_fields=[
UserFields.USERNAME, UserFields.USERNAME,
], ],
) )
conf_stage = AuthenticatorStaticStage.objects.create(
name=generate_id(),
)
stage = AuthenticatorValidateStage.objects.create( stage = AuthenticatorValidateStage.objects.create(
name=generate_id(), name=generate_id(),
not_configured_action=NotConfiguredAction.CONFIGURE, not_configured_action=NotConfiguredAction.CONFIGURE,
) )
stage.configuration_stages.set([conf_stage]) stage.configuration_stages.set([conf_stage])
flow = create_test_flow() flow = create_test_flow()
FlowStageBinding.objects.create(target=flow, stage=conf_stage, order=0) FlowStageBinding.objects.create(target=flow, stage=ident_stage, order=0)
FlowStageBinding.objects.create(target=flow, stage=stage, order=1) FlowStageBinding.objects.create(target=flow, stage=stage, order=1)
response = self.client.get( response = self.client.get(
@ -57,27 +61,22 @@ class AuthenticatorValidateStageTests(FlowTestCase):
self.assertStageResponse( self.assertStageResponse(
response, response,
flow, flow,
component="ak-stage-identification", component="ak-stage-authenticator-static",
password_fields=False,
primary_action="Continue",
user_fields=["username"],
sources=[],
show_source_labels=False,
) )
def test_not_configured_action_multiple(self): def test_not_configured_action_multiple(self):
"""Test not_configured_action""" """Test not_configured_action"""
conf_stage = IdentificationStage.objects.create( ident_stage = IdentificationStage.objects.create(
name=generate_id(), name=generate_id(),
user_fields=[ user_fields=[
UserFields.USERNAME, UserFields.USERNAME,
], ],
) )
conf_stage2 = IdentificationStage.objects.create( conf_stage = AuthenticatorStaticStage.objects.create(
name=generate_id(),
)
conf_stage2 = AuthenticatorStaticStage.objects.create(
name=generate_id(), name=generate_id(),
user_fields=[
UserFields.USERNAME,
],
) )
stage = AuthenticatorValidateStage.objects.create( stage = AuthenticatorValidateStage.objects.create(
name=generate_id(), name=generate_id(),
@ -85,7 +84,7 @@ class AuthenticatorValidateStageTests(FlowTestCase):
) )
stage.configuration_stages.set([conf_stage, conf_stage2]) stage.configuration_stages.set([conf_stage, conf_stage2])
flow = create_test_flow() flow = create_test_flow()
FlowStageBinding.objects.create(target=flow, stage=conf_stage, order=0) FlowStageBinding.objects.create(target=flow, stage=ident_stage, order=0)
FlowStageBinding.objects.create(target=flow, stage=stage, order=1) FlowStageBinding.objects.create(target=flow, stage=stage, order=1)
# Get initial identification stage # Get initial identification stage
@ -118,12 +117,7 @@ class AuthenticatorValidateStageTests(FlowTestCase):
self.assertStageResponse( self.assertStageResponse(
response, response,
flow, flow,
component="ak-stage-identification", component="ak-stage-authenticator-static",
password_fields=False,
primary_action="Continue",
user_fields=["username"],
sources=[],
show_source_labels=False,
) )
def test_stage_validation(self): def test_stage_validation(self):

View File

@ -14,6 +14,7 @@ entries:
- attrs: - attrs:
configure_flow: !KeyOf flow configure_flow: !KeyOf flow
token_count: 6 token_count: 6
friendly_name: Static tokens
identifiers: identifiers:
name: default-authenticator-static-setup name: default-authenticator-static-setup
id: default-authenticator-static-setup id: default-authenticator-static-setup

View File

@ -14,6 +14,7 @@ entries:
- attrs: - attrs:
configure_flow: !KeyOf flow configure_flow: !KeyOf flow
digits: 6 digits: 6
friendly_name: TOTP Device
identifiers: identifiers:
name: default-authenticator-totp-setup name: default-authenticator-totp-setup
id: default-authenticator-totp-setup id: default-authenticator-totp-setup

View File

@ -13,6 +13,7 @@ entries:
id: flow id: flow
- attrs: - attrs:
configure_flow: !KeyOf flow configure_flow: !KeyOf flow
friendly_name: WebAuthn device
identifiers: identifiers:
name: default-authenticator-webauthn-setup name: default-authenticator-webauthn-setup
id: default-authenticator-webauthn-setup id: default-authenticator-webauthn-setup