fix: cascade remove external login (#871)

* fix: cascade remove external login

* fix: tests
This commit is contained in:
Fabi 2020-10-19 16:28:06 +02:00 committed by GitHub
parent 4fb6ad3f69
commit bb9747923c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View File

@ -472,8 +472,8 @@ func GetMockManipulateUserWithExternalIDP(ctrl *gomock.Controller) *UserEventsto
dataUser, _ := json.Marshal(user)
dataIDP, _ := json.Marshal(externalIDP)
events := []*es_models.Event{
{AggregateID: "AggregateID", AggregateVersion: "v1", Sequence: 1, Type: model.UserAdded, Data: dataUser},
{AggregateID: "AggregateID", AggregateVersion: "v1", Sequence: 1, Type: model.HumanExternalIDPAdded, Data: dataIDP},
{AggregateID: "AggregateID", AggregateVersion: "v1", Sequence: 1, Type: model.UserAdded, Data: dataUser, ResourceOwner: "ResourceOwner"},
{AggregateID: "AggregateID", AggregateVersion: "v1", Sequence: 1, Type: model.HumanExternalIDPAdded, Data: dataIDP, ResourceOwner: "ResourceOwner"},
}
mockEs := mock.NewMockEventstore(ctrl)
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)

View File

@ -836,7 +836,7 @@ func ExternalIDPRemovedAggregate(ctx context.Context, aggCreator *es_models.Aggr
}
aggregates := make([]*es_models.Aggregate, 0)
agg, err := UserAggregate(ctx, aggCreator, user)
agg, err := UserAggregateOverwriteContext(ctx, aggCreator, user, user.ResourceOwner, authz.GetCtxData(ctx).UserID)
if err != nil {
return nil, err
}
@ -845,7 +845,7 @@ func ExternalIDPRemovedAggregate(ctx context.Context, aggCreator *es_models.Aggr
} else {
agg, err = agg.AppendEvent(model.HumanExternalIDPRemoved, externalIDP)
}
uniqueReleasedAggregate, err := releasedUniqueExternalIDPAggregate(ctx, aggCreator, externalIDP)
uniqueReleasedAggregate, err := releasedUniqueExternalIDPAggregate(ctx, aggCreator, externalIDP, user.ResourceOwner)
if err != nil {
return nil, err
}
@ -870,9 +870,10 @@ func reservedUniqueExternalIDPAggregate(ctx context.Context, aggCreator *es_mode
return aggregate.SetPrecondition(UserExternalIDPUniqueQuery(uniqueExternlIDP), isEventValidation(aggregate, model.HumanExternalIDPReserved)), nil
}
func releasedUniqueExternalIDPAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, externalIDP *model.ExternalIDP) (aggregate *es_models.Aggregate, err error) {
func releasedUniqueExternalIDPAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, externalIDP *model.ExternalIDP, resourceOwnerID string) (aggregate *es_models.Aggregate, err error) {
uniqueExternlIDP := externalIDP.IDPConfigID + externalIDP.UserID
aggregate, err = aggCreator.NewAggregate(ctx, uniqueExternlIDP, model.UserExternalIDPAggregate, model.UserVersion, 0)
aggregate, err = aggCreator.NewAggregate(ctx, uniqueExternlIDP, model.UserExternalIDPAggregate, model.UserVersion, 0, es_models.OverwriteResourceOwner(resourceOwnerID), es_models.OverwriteEditorUser(authz.GetCtxData(ctx).UserID))
if err != nil {
return nil, err
}

View File

@ -2388,8 +2388,9 @@ func TestExternalIDPRemovedAggregates(t *testing.T) {
aggCreator: models.NewAggregateCreator("test"),
user: &model.User{
ObjectRoot: models.ObjectRoot{
AggregateID: "AggregateID",
Sequence: 5,
AggregateID: "AggregateID",
Sequence: 5,
ResourceOwner: "ResourceOwner",
},
},
externalIDP: &model.ExternalIDP{