From 4c50b6dfa2bf6f045cf690bae796e42fb65bbdbc Mon Sep 17 00:00:00 2001 From: Fabi <38692350+fgerschwiler@users.noreply.github.com> Date: Tue, 19 Oct 2021 09:38:35 +0200 Subject: [PATCH] fix: mfa translations (#2527) --- internal/command/user_human_otp.go | 11 ++++++----- internal/domain/human_otp.go | 2 +- .../user/repository/eventsourcing/model/web_auth_n.go | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/command/user_human_otp.go b/internal/command/user_human_otp.go index 43c82ddd4..6e52925f9 100644 --- a/internal/command/user_human_otp.go +++ b/internal/command/user_human_otp.go @@ -2,6 +2,7 @@ package command import ( "context" + "github.com/caos/logging" "github.com/caos/zitadel/internal/domain" caos_errs "github.com/caos/zitadel/internal/errors" @@ -34,7 +35,7 @@ func (c *Commands) AddHumanOTP(ctx context.Context, userID, resourceowner string return nil, err } if otpWriteModel.State == domain.MFAStateReady { - return nil, caos_errs.ThrowAlreadyExists(nil, "COMMAND-do9se", "Errors.User.MFA.Provider0.AlreadyReady") + return nil, caos_errs.ThrowAlreadyExists(nil, "COMMAND-do9se", "Errors.User.MFA.OTP.AlreadyReady") } userAgg := UserAggregateFromWriteModel(&otpWriteModel.WriteModel) accountName := domain.GenerateLoginName(human.GetUsername(), org.PrimaryDomain, orgPolicy.UserLoginMustBeDomain) @@ -69,10 +70,10 @@ func (c *Commands) HumanCheckMFAOTPSetup(ctx context.Context, userID, code, user return nil, err } if existingOTP.State == domain.MFAStateUnspecified || existingOTP.State == domain.MFAStateRemoved { - return nil, caos_errs.ThrowNotFound(nil, "COMMAND-3Mif9s", "Errors.User.MFA.Provider0.NotExisting") + return nil, caos_errs.ThrowNotFound(nil, "COMMAND-3Mif9s", "Errors.User.MFA.OTP.NotExisting") } if existingOTP.State == domain.MFAStateReady { - return nil, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-qx4ls", "Errors.Users.MFA.Provider0.AlreadyReady") + return nil, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-qx4ls", "Errors.Users.MFA.OTP.AlreadyReady") } if err := domain.VerifyMFAOTP(code, existingOTP.Secret, c.multifactors.OTP.CryptoMFA); err != nil { return nil, err @@ -99,7 +100,7 @@ func (c *Commands) HumanCheckMFAOTP(ctx context.Context, userID, code, resourceo return err } if existingOTP.State != domain.MFAStateReady { - return caos_errs.ThrowPreconditionFailed(nil, "COMMAND-3Mif9s", "Errors.User.MFA.Provider0.NotReady") + return caos_errs.ThrowPreconditionFailed(nil, "COMMAND-3Mif9s", "Errors.User.MFA.OTP.NotReady") } userAgg := UserAggregateFromWriteModel(&existingOTP.WriteModel) err = domain.VerifyMFAOTP(code, existingOTP.Secret, c.multifactors.OTP.CryptoMFA) @@ -122,7 +123,7 @@ func (c *Commands) HumanRemoveOTP(ctx context.Context, userID, resourceOwner str return nil, err } if existingOTP.State == domain.MFAStateUnspecified || existingOTP.State == domain.MFAStateRemoved { - return nil, caos_errs.ThrowNotFound(nil, "COMMAND-Hd9sd", "Errors.User.MFA.Provider0.NotExisting") + return nil, caos_errs.ThrowNotFound(nil, "COMMAND-Hd9sd", "Errors.User.MFA.OTP.NotExisting") } userAgg := UserAggregateFromWriteModel(&existingOTP.WriteModel) pushedEvents, err := c.eventstore.PushEvents(ctx, user.NewHumanOTPRemovedEvent(ctx, userAgg)) diff --git a/internal/domain/human_otp.go b/internal/domain/human_otp.go index 673aecfb8..cf715c702 100644 --- a/internal/domain/human_otp.go +++ b/internal/domain/human_otp.go @@ -37,7 +37,7 @@ func VerifyMFAOTP(code string, secret *crypto.CryptoValue, cryptoAlg crypto.Encr valid := totp.Validate(code, decrypt) if !valid { - return caos_errs.ThrowInvalidArgument(nil, "EVENT-8isk2", "Errors.User.MFA.Provider0.InvalidCode") + return caos_errs.ThrowInvalidArgument(nil, "EVENT-8isk2", "Errors.User.MFA.OTP.InvalidCode") } return nil } diff --git a/internal/user/repository/eventsourcing/model/web_auth_n.go b/internal/user/repository/eventsourcing/model/web_auth_n.go index 6193658aa..9d788043f 100644 --- a/internal/user/repository/eventsourcing/model/web_auth_n.go +++ b/internal/user/repository/eventsourcing/model/web_auth_n.go @@ -102,7 +102,7 @@ func (u *Human) appendU2FVerifiedEvent(event *es_models.Event) error { token.State = int32(model.MFAStateReady) return nil } - return caos_errs.ThrowPreconditionFailed(nil, "MODEL-4hu9s", "Errors.Users.MFA.Provider1.NotExisting") + return caos_errs.ThrowPreconditionFailed(nil, "MODEL-4hu9s", "Errors.Users.MFA.U2F.NotExisting") } func (u *Human) appendU2FChangeSignCountEvent(event *es_models.Event) error { @@ -115,7 +115,7 @@ func (u *Human) appendU2FChangeSignCountEvent(event *es_models.Event) error { token.setData(event) return nil } - return caos_errs.ThrowPreconditionFailed(nil, "MODEL-5Ms8h", "Errors.Users.MFA.Provider1.NotExisting") + return caos_errs.ThrowPreconditionFailed(nil, "MODEL-5Ms8h", "Errors.Users.MFA.U2F.NotExisting") } func (u *Human) appendU2FRemovedEvent(event *es_models.Event) error {