fix(user): move check if user is existing from user idp link (#4363)

* fix(user): move check if user is existing from user idp link

* fix(user): correct unit tests for user link bulk

* fix(user): correct placement of existing user check for user link

Co-authored-by: Silvan <silvan.reusser@gmail.com>
This commit is contained in:
Stefan Benz 2022-09-14 13:21:23 +01:00 committed by GitHub
parent 7a5f7f82cf
commit 69230def56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 3 deletions

View File

@ -15,6 +15,9 @@ func (c *Commands) AddUserIDPLink(ctx context.Context, userID, resourceOwner str
if userID == "" {
return caos_errs.ThrowInvalidArgument(nil, "COMMAND-03j8f", "Errors.IDMissing")
}
if err := c.checkUserExists(ctx, userID, resourceOwner); err != nil {
return err
}
linkWriteModel := NewUserIDPLinkWriteModel(userID, link.IDPConfigID, link.ExternalUserID, resourceOwner)
userAgg := UserAggregateFromWriteModel(&linkWriteModel.WriteModel)
@ -36,6 +39,10 @@ func (c *Commands) BulkAddedUserIDPLinks(ctx context.Context, userID, resourceOw
return caos_errs.ThrowInvalidArgument(nil, "COMMAND-Ek9s", "Errors.User.ExternalIDP.MinimumExternalIDPNeeded")
}
if err := c.checkUserExists(ctx, userID, resourceOwner); err != nil {
return err
}
events := make([]eventstore.Command, len(links))
for i, link := range links {
linkWriteModel := NewUserIDPLinkWriteModel(userID, link.IDPConfigID, link.ExternalUserID, resourceOwner)
@ -58,9 +65,6 @@ func (c *Commands) addUserIDPLink(ctx context.Context, human *eventstore.Aggrega
if !link.IsValid() {
return nil, caos_errs.ThrowInvalidArgument(nil, "COMMAND-6m9Kd", "Errors.User.ExternalIDP.Invalid")
}
if err := c.checkUserExists(ctx, human.ID, human.ResourceOwner); err != nil {
return nil, err
}
_, err := c.getOrgIDPConfigByID(ctx, link.IDPConfigID, human.ResourceOwner)
if caos_errs.IsNotFound(err) {

View File

@ -79,6 +79,23 @@ func TestCommandSide_BulkAddUserIDPLinks(t *testing.T) {
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(
context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"userName",
"firstName",
"lastName",
"nickName",
"displayName",
language.German,
domain.GenderFemale,
"email@Address.ch",
false,
),
),
),
),
},
args: args{
@ -104,6 +121,23 @@ func TestCommandSide_BulkAddUserIDPLinks(t *testing.T) {
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(
context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"userName",
"firstName",
"lastName",
"nickName",
"displayName",
language.German,
domain.GenderFemale,
"email@Address.ch",
false,
),
),
),
),
},
args: args{