feat(eventstore): increase parallel write capabilities (#5940)

This implementation increases parallel write capabilities of the eventstore.
Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and  [06](https://zitadel.com/docs/support/advisory/a10006).
The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`.
If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
This commit is contained in:
Silvan
2023-10-19 12:19:10 +02:00
committed by GitHub
parent 259faba3f0
commit b5564572bc
791 changed files with 30326 additions and 43202 deletions
+39 -57
View File
@@ -13,7 +13,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/id"
"github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/repository/authrequest"
@@ -77,29 +76,26 @@ func TestCommands_AddAuthRequest(t *testing.T) {
eventstore: eventstoreExpect(t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
"loginClient",
"clientID",
"redirectURI",
"state",
"nonce",
[]string{"openid"},
[]string{"audience"},
domain.OIDCResponseTypeCode,
&domain.OIDCCodeChallenge{
Challenge: "challenge",
Method: domain.CodeChallengeMethodS256,
},
[]domain.Prompt{domain.PromptNone},
[]string{"en", "de"},
gu.Ptr(time.Duration(0)),
gu.Ptr("loginHint"),
gu.Ptr("hintUserID"),
),
),
}),
authrequest.NewAddedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
"loginClient",
"clientID",
"redirectURI",
"state",
"nonce",
[]string{"openid"},
[]string{"audience"},
domain.OIDCResponseTypeCode,
&domain.OIDCCodeChallenge{
Challenge: "challenge",
Method: domain.CodeChallengeMethodS256,
},
[]domain.Prompt{domain.PromptNone},
[]string{"en", "de"},
gu.Ptr(time.Duration(0)),
gu.Ptr("loginHint"),
gu.Ptr("hintUserID"),
),
),
),
idGenerator: mock.NewIDGeneratorExpectIDs(t, "id"),
},
@@ -456,15 +452,13 @@ func TestCommands_LinkSessionToAuthRequest(t *testing.T) {
),
),
expectPush(
[]*repository.Event{eventFromEventPusherWithInstanceID(
"instanceID",
authrequest.NewSessionLinkedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
"sessionID",
"userID",
testNow,
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
),
)}),
authrequest.NewSessionLinkedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
"sessionID",
"userID",
testNow,
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
),
),
),
tokenVerifier: func(ctx context.Context, sessionToken, sessionID, tokenID string) (err error) {
return nil
@@ -535,15 +529,13 @@ func TestCommands_LinkSessionToAuthRequest(t *testing.T) {
),
),
expectPush(
[]*repository.Event{eventFromEventPusherWithInstanceID(
"instanceID",
authrequest.NewSessionLinkedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
"sessionID",
"userID",
testNow,
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
),
)}),
authrequest.NewSessionLinkedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
"sessionID",
"userID",
testNow,
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
),
),
),
tokenVerifier: func(ctx context.Context, sessionToken, sessionID, tokenID string) (err error) {
return nil
@@ -659,11 +651,9 @@ func TestCommands_FailAuthRequest(t *testing.T) {
),
),
expectPush(
[]*repository.Event{eventFromEventPusherWithInstanceID(
"instanceID",
authrequest.NewFailedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
domain.OIDCErrorReasonLoginRequired),
)}),
authrequest.NewFailedEvent(mockCtx, &authrequest.NewAggregate("V2_id", "instanceID").Aggregate,
domain.OIDCErrorReasonLoginRequired),
),
),
},
args{
@@ -802,11 +792,7 @@ func TestCommands_AddAuthRequestCode(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
authrequest.NewCodeAddedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
),
},
authrequest.NewCodeAddedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
),
),
},
@@ -937,11 +923,7 @@ func TestCommands_ExchangeAuthCode(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
authrequest.NewCodeExchangedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
),
},
authrequest.NewCodeExchangedEvent(mockCtx, &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
),
),
},
+1 -1
View File
@@ -16,7 +16,7 @@ func writeModelToObjectDetails(writeModel *eventstore.WriteModel) *domain.Object
func pushedEventsToObjectDetails(events []eventstore.Event) *domain.ObjectDetails {
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().ResourceOwner,
}
}
+39 -60
View File
@@ -14,7 +14,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/repository/deviceauth"
@@ -73,16 +72,12 @@ func TestCommands_AddDeviceAuth(t *testing.T) {
name: "success",
fields: fields{
eventstore: eventstoreExpect(t, expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instance1", deviceauth.NewAddedEvent(
ctx,
deviceauth.NewAggregate("1999", "instance1"),
"client_id", "123", "456", now,
[]string{"a", "b", "c"},
)),
},
uniqueConstraintsFromEventConstraintWithInstanceID("instance1", unique[0]),
uniqueConstraintsFromEventConstraintWithInstanceID("instance1", unique[1]),
deviceauth.NewAddedEvent(
ctx,
deviceauth.NewAggregate("1999", "instance1"),
"client_id", "123", "456", now,
[]string{"a", "b", "c"},
),
)),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "1999"),
},
@@ -103,17 +98,13 @@ func TestCommands_AddDeviceAuth(t *testing.T) {
name: "push error",
fields: fields{
eventstore: eventstoreExpect(t, expectPushFailed(pushErr,
[]*repository.Event{
eventFromEventPusherWithInstanceID("instance1", deviceauth.NewAddedEvent(
ctx,
deviceauth.NewAggregate("1999", "instance1"),
"client_id", "123", "456", now,
[]string{"a", "b", "c"},
)),
},
uniqueConstraintsFromEventConstraintWithInstanceID("instance1", unique[0]),
uniqueConstraintsFromEventConstraintWithInstanceID("instance1", unique[1]),
)),
deviceauth.NewAddedEvent(
ctx,
deviceauth.NewAggregate("1999", "instance1"),
"client_id", "123", "456", now,
[]string{"a", "b", "c"},
)),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "1999"),
},
args: args{
@@ -135,8 +126,8 @@ func TestCommands_AddDeviceAuth(t *testing.T) {
}
gotID, gotDetails, err := c.AddDeviceAuth(tt.args.ctx, tt.args.clientID, tt.args.deviceCode, tt.args.userCode, tt.args.expires, tt.args.scopes)
require.ErrorIs(t, err, tt.wantErr)
assert.Equal(t, gotID, tt.wantID)
assert.Equal(t, gotDetails, tt.wantDetails)
assert.Equal(t, tt.wantID, gotID)
assert.Equal(t, tt.wantDetails, gotDetails)
})
}
}
@@ -201,11 +192,9 @@ func TestCommands_ApproveDeviceAuth(t *testing.T) {
),
)),
expectPushFailed(pushErr,
[]*repository.Event{eventFromEventPusherWithInstanceID(
"instance1", deviceauth.NewApprovedEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"), "subj",
),
)},
deviceauth.NewApprovedEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"), "subj",
),
),
),
},
@@ -225,11 +214,11 @@ func TestCommands_ApproveDeviceAuth(t *testing.T) {
[]string{"a", "b", "c"},
),
)),
expectPush([]*repository.Event{eventFromEventPusherWithInstanceID(
"instance1", deviceauth.NewApprovedEvent(
expectPush(
deviceauth.NewApprovedEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"), "subj",
),
)}),
),
),
},
args: args{ctx, "1999", "subj"},
@@ -310,12 +299,10 @@ func TestCommands_CancelDeviceAuth(t *testing.T) {
),
)),
expectPushFailed(pushErr,
[]*repository.Event{eventFromEventPusherWithInstanceID(
"instance1", deviceauth.NewCanceledEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"),
domain.DeviceAuthCanceledDenied,
),
)},
deviceauth.NewCanceledEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"),
domain.DeviceAuthCanceledDenied,
),
),
),
},
@@ -335,12 +322,12 @@ func TestCommands_CancelDeviceAuth(t *testing.T) {
[]string{"a", "b", "c"},
),
)),
expectPush([]*repository.Event{eventFromEventPusherWithInstanceID(
"instance1", deviceauth.NewCanceledEvent(
expectPush(
deviceauth.NewCanceledEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"),
domain.DeviceAuthCanceledDenied,
),
)}),
),
),
},
args: args{ctx, "1999", domain.DeviceAuthCanceledDenied},
@@ -361,12 +348,12 @@ func TestCommands_CancelDeviceAuth(t *testing.T) {
[]string{"a", "b", "c"},
),
)),
expectPush([]*repository.Event{eventFromEventPusherWithInstanceID(
"instance1", deviceauth.NewCanceledEvent(
expectPush(
deviceauth.NewCanceledEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"),
domain.DeviceAuthCanceledExpired,
),
)}),
),
),
},
args: args{ctx, "1999", domain.DeviceAuthCanceledExpired},
@@ -423,14 +410,10 @@ func TestCommands_RemoveDeviceAuth(t *testing.T) {
),
)),
expectPushFailed(pushErr,
[]*repository.Event{eventFromEventPusherWithInstanceID(
"instance1", deviceauth.NewRemovedEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"),
"client_id", "123", "456",
),
)},
uniqueConstraintsFromEventConstraintWithInstanceID("instance1", unique[0]),
uniqueConstraintsFromEventConstraintWithInstanceID("instance1", unique[1]),
deviceauth.NewRemovedEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"),
"client_id", "123", "456",
),
),
),
},
@@ -451,14 +434,10 @@ func TestCommands_RemoveDeviceAuth(t *testing.T) {
),
)),
expectPush(
[]*repository.Event{eventFromEventPusherWithInstanceID(
"instance1", deviceauth.NewRemovedEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"),
"client_id", "123", "456",
),
)},
uniqueConstraintsFromEventConstraintWithInstanceID("instance1", unique[0]),
uniqueConstraintsFromEventConstraintWithInstanceID("instance1", unique[1]),
deviceauth.NewRemovedEvent(
ctx, deviceauth.NewAggregate("1999", "instance1"),
"client_id", "123", "456",
),
),
),
},
+60 -71
View File
@@ -165,19 +165,17 @@ func TestCommands_CreateIntent(t *testing.T) {
)),
),
expectPush(
eventPusherToEvents(
func() eventstore.Command {
success, _ := url.Parse("https://success.url")
failure, _ := url.Parse("https://failure.url")
return idpintent.NewStartedEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
success,
failure,
"idp",
)
}(),
),
func() eventstore.Command {
success, _ := url.Parse("https://success.url")
failure, _ := url.Parse("https://failure.url")
return idpintent.NewStartedEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
success,
failure,
"idp",
)
}(),
),
),
idGenerator: mock.ExpectID(t, "id"),
@@ -545,13 +543,13 @@ func TestCommands_AuthFromProvider_SAML(t *testing.T) {
),
),
expectRandomPush(
eventPusherToEvents(
[]eventstore.Command{
idpintent.NewSAMLRequestEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
"request",
),
),
},
),
),
},
@@ -667,8 +665,8 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
idpConfigEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
eventstore: eventstoreExpect(t,
expectPush(
eventPusherToEvents(
idpintent.NewSucceededEvent(
func() eventstore.Command {
event := idpintent.NewSucceededEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
[]byte(`{"sub":"id","preferred_username":"username"}`),
@@ -682,8 +680,9 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
Crypted: []byte("accessToken"),
},
"idToken",
),
),
)
return event
}(),
),
),
},
@@ -768,21 +767,19 @@ func TestCommands_SucceedSAMLIDPIntent(t *testing.T) {
idpConfigEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
eventstore: eventstoreExpect(t,
expectPush(
eventPusherToEvents(
idpintent.NewSAMLSucceededEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
[]byte(`{"sub":"id","preferred_username":"username"}`),
"id",
"username",
"",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("<Assertion xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"id\" IssueInstant=\"0001-01-01T00:00:00Z\" Version=\"\"><Issuer xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" NameQualifier=\"\" SPNameQualifier=\"\" Format=\"\" SPProvidedID=\"\"></Issuer></Assertion>"),
},
),
idpintent.NewSAMLSucceededEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
[]byte(`{"sub":"id","preferred_username":"username"}`),
"id",
"username",
"",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("<Assertion xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"id\" IssueInstant=\"0001-01-01T00:00:00Z\" Version=\"\"><Issuer xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" NameQualifier=\"\" SPNameQualifier=\"\" Format=\"\" SPProvidedID=\"\"></Issuer></Assertion>"),
},
),
),
),
@@ -808,21 +805,19 @@ func TestCommands_SucceedSAMLIDPIntent(t *testing.T) {
idpConfigEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
eventstore: eventstoreExpect(t,
expectPush(
eventPusherToEvents(
idpintent.NewSAMLSucceededEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
[]byte(`{"sub":"id","preferred_username":"username"}`),
"id",
"username",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("<Assertion xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"id\" IssueInstant=\"0001-01-01T00:00:00Z\" Version=\"\"><Issuer xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" NameQualifier=\"\" SPNameQualifier=\"\" Format=\"\" SPProvidedID=\"\"></Issuer></Assertion>"),
},
),
idpintent.NewSAMLSucceededEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
[]byte(`{"sub":"id","preferred_username":"username"}`),
"id",
"username",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("<Assertion xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"id\" IssueInstant=\"0001-01-01T00:00:00Z\" Version=\"\"><Issuer xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" NameQualifier=\"\" SPNameQualifier=\"\" Format=\"\" SPProvidedID=\"\"></Issuer></Assertion>"),
},
),
),
),
@@ -880,12 +875,10 @@ func TestCommands_RequestSAMLIDPIntent(t *testing.T) {
fields{
eventstore: eventstoreExpect(t,
expectPush(
eventPusherToEvents(
idpintent.NewSAMLRequestEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
"request",
),
idpintent.NewSAMLRequestEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
"request",
),
),
),
@@ -955,16 +948,14 @@ func TestCommands_SucceedLDAPIDPIntent(t *testing.T) {
idpConfigEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
eventstore: eventstoreExpect(t,
expectPush(
eventPusherToEvents(
idpintent.NewLDAPSucceededEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
[]byte(`{"id":"id","preferredUsername":"username","preferredLanguage":"und"}`),
"id",
"username",
"",
map[string][]string{"id": {"id"}},
),
idpintent.NewLDAPSucceededEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
[]byte(`{"id":"id","preferredUsername":"username","preferredLanguage":"und"}`),
"id",
"username",
"",
map[string][]string{"id": {"id"}},
),
),
),
@@ -1030,12 +1021,10 @@ func TestCommands_FailIDPIntent(t *testing.T) {
fields{
eventstore: eventstoreExpect(t,
expectPush(
eventPusherToEvents(
idpintent.NewFailedEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
"reason",
),
idpintent.NewFailedEvent(
context.Background(),
&idpintent.NewAggregate("id", "ro").Aggregate,
"reason",
),
),
),
+1 -1
View File
@@ -2027,7 +2027,7 @@ func (wm *IDPTypeWriteModel) Reduce() error {
return wm.WriteModel.Reduce()
}
func (wm *IDPTypeWriteModel) reduceAdded(id string, t domain.IDPType, agg eventstore.Aggregate) {
func (wm *IDPTypeWriteModel) reduceAdded(id string, t domain.IDPType, agg *eventstore.Aggregate) {
if wm.ID != id {
return
}
+4 -10
View File
@@ -159,10 +159,8 @@ func (s *InstanceSetup) generateIDs(idGenerator id.Generator) (err error) {
}
s.zitadel.consoleAppID, err = idGenerator.Next()
if err != nil {
return err
}
return nil
return err
}
func (c *Commands) SetUpInstance(ctx context.Context, setup *InstanceSetup) (string, string, *MachineKey, *domain.ObjectDetails, error) {
@@ -171,10 +169,6 @@ func (c *Commands) SetUpInstance(ctx context.Context, setup *InstanceSetup) (str
return "", "", nil, nil, err
}
if err = c.eventstore.NewInstance(ctx, instanceID); err != nil {
return "", "", nil, nil, err
}
ctx = authz.SetCtxData(authz.WithRequestedDomain(authz.WithInstanceID(ctx, instanceID), c.externalDomain), authz.CtxData{OrgID: instanceID, ResourceOwner: instanceID})
orgID, err := c.idGenerator.Next()
@@ -464,7 +458,7 @@ func (c *Commands) SetUpInstance(ctx context.Context, setup *InstanceSetup) (str
return instanceID, token, machineKey, &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: orgID,
}, nil
}
@@ -695,7 +689,7 @@ func (c *Commands) RemoveInstance(ctx context.Context, id string) (*domain.Objec
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
File diff suppressed because it is too large Load Diff
@@ -7,10 +7,10 @@ import (
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
)
@@ -56,76 +56,60 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageGreeting,
"Greeting",
language.English,
),
),
eventFromEventPusher(
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageSubject,
"Subject",
language.English,
),
),
eventFromEventPusher(
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageTitle,
"Title",
language.English,
),
),
eventFromEventPusher(
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessagePreHeader,
"PreHeader",
language.English,
),
),
eventFromEventPusher(
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageText,
"Text",
language.English,
),
),
eventFromEventPusher(
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageButtonText,
"ButtonText",
language.English,
),
),
eventFromEventPusher(
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageFooterText,
"Footer",
language.English,
),
),
},
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageGreeting,
"Greeting",
language.English,
),
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageSubject,
"Subject",
language.English,
),
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageTitle,
"Title",
language.English,
),
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessagePreHeader,
"PreHeader",
language.English,
),
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageText,
"Text",
language.English,
),
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageButtonText,
"ButtonText",
language.English,
),
instance.NewCustomTextSetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"Template",
domain.MessageFooterText,
"Footer",
language.English,
),
),
),
},
args: args{
ctx: context.Background(),
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
instanceID: "INSTANCE",
config: &domain.CustomMessageText{
MessageTextType: "Template",
@@ -157,10 +141,9 @@ func TestCommandSide_SetDefaultMessageText(t *testing.T) {
}
if tt.res.err != nil && !tt.res.err(err) {
t.Errorf("got wrong err: %v ", err)
t.FailNow()
}
if tt.res.err == nil {
assert.Equal(t, tt.res.want, got)
}
assert.Equal(t, tt.res.want, got)
})
}
}
@@ -5,9 +5,8 @@ import (
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/repository/settings"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/settings"
)
type InstanceDebugNotificationFileWriteModel struct {
@@ -15,11 +14,13 @@ type InstanceDebugNotificationFileWriteModel struct {
}
func NewInstanceDebugNotificationFileWriteModel(ctx context.Context) *InstanceDebugNotificationFileWriteModel {
instanceID := authz.GetInstance(ctx).InstanceID()
return &InstanceDebugNotificationFileWriteModel{
DebugNotificationWriteModel{
WriteModel: eventstore.WriteModel{
AggregateID: authz.GetInstance(ctx).InstanceID(),
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
AggregateID: instanceID,
ResourceOwner: instanceID,
InstanceID: instanceID,
},
},
}
@@ -4,16 +4,15 @@ import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/notification/channels/fs"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/settings"
"github.com/stretchr/testify/assert"
)
func TestCommandSide_AddDefaultDebugNotificationProviderFile(t *testing.T) {
@@ -28,6 +27,7 @@ func TestCommandSide_AddDefaultDebugNotificationProviderFile(t *testing.T) {
want *domain.ObjectDetails
err func(error) bool
}
ctx := authz.WithInstanceID(context.Background(), "INSTANCE")
tests := []struct {
name string
fields fields
@@ -41,7 +41,7 @@ func TestCommandSide_AddDefaultDebugNotificationProviderFile(t *testing.T) {
t,
expectFilter(
eventFromEventPusher(
instance.NewDebugNotificationProviderFileAddedEvent(context.Background(),
instance.NewDebugNotificationProviderFileAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
@@ -50,7 +50,7 @@ func TestCommandSide_AddDefaultDebugNotificationProviderFile(t *testing.T) {
),
},
args: args{
ctx: context.Background(),
ctx: ctx,
provider: &fs.Config{
Compact: true,
Enabled: true,
@@ -67,20 +67,15 @@ func TestCommandSide_AddDefaultDebugNotificationProviderFile(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDebugNotificationProviderFileAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
},
instance.NewDebugNotificationProviderFileAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
),
},
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
ctx: authz.WithInstanceID(ctx, "INSTANCE"),
provider: &fs.Config{
Compact: true,
},
@@ -215,13 +210,8 @@ func TestCommandSide_ChangeDebugNotificationProviderFile(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
newDefaultDebugNotificationFileChangedEvent(context.Background(),
false),
),
},
newDefaultDebugNotificationFileChangedEvent(context.Background(),
false),
),
),
},
@@ -305,13 +295,8 @@ func TestCommandSide_RemoveDebugNotificationProviderFile(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDebugNotificationProviderFileRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate),
),
},
instance.NewDebugNotificationProviderFileRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate),
),
),
},
@@ -5,9 +5,8 @@ import (
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/repository/settings"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/settings"
)
type InstanceDebugNotificationLogWriteModel struct {
@@ -15,11 +14,13 @@ type InstanceDebugNotificationLogWriteModel struct {
}
func NewInstanceDebugNotificationLogWriteModel(ctx context.Context) *InstanceDebugNotificationLogWriteModel {
instanceID := authz.GetInstance(ctx).InstanceID()
return &InstanceDebugNotificationLogWriteModel{
DebugNotificationWriteModel{
WriteModel: eventstore.WriteModel{
AggregateID: authz.GetInstance(ctx).InstanceID(),
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
AggregateID: instanceID,
ResourceOwner: instanceID,
InstanceID: instanceID,
},
},
}
@@ -4,16 +4,15 @@ import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/notification/channels/fs"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/settings"
"github.com/stretchr/testify/assert"
)
func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
@@ -28,6 +27,7 @@ func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
want *domain.ObjectDetails
err func(error) bool
}
ctx := authz.WithInstanceID(context.Background(), "INSTANCE")
tests := []struct {
name string
fields fields
@@ -42,7 +42,7 @@ func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
expectFilter(
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
instance.NewDebugNotificationProviderLogAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
@@ -51,7 +51,7 @@ func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
),
},
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
ctx: authz.WithInstanceID(ctx, "INSTANCE"),
provider: &fs.Config{
Compact: true,
Enabled: true,
@@ -68,20 +68,15 @@ func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
},
instance.NewDebugNotificationProviderLogAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
),
},
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
ctx: authz.WithInstanceID(ctx, "INSTANCE"),
provider: &fs.Config{
Compact: true,
},
@@ -99,20 +94,15 @@ func TestCommandSide_AddDefaultDebugNotificationProviderLog(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
},
instance.NewDebugNotificationProviderLogAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
),
},
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
ctx: authz.WithInstanceID(ctx, "INSTANCE"),
provider: &fs.Config{
Compact: true,
Enabled: true,
@@ -156,6 +146,7 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
want *domain.ObjectDetails
err func(error) bool
}
ctx := authz.WithInstanceID(context.Background(), "INSTANCE")
tests := []struct {
name string
fields fields
@@ -171,7 +162,7 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
),
},
args: args{
ctx: context.Background(),
ctx: ctx,
provider: &fs.Config{
Compact: true,
Enabled: true,
@@ -188,7 +179,7 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
t,
expectFilter(
eventFromEventPusher(
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
instance.NewDebugNotificationProviderLogAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
@@ -197,7 +188,7 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
),
},
args: args{
ctx: context.Background(),
ctx: ctx,
provider: &fs.Config{
Compact: true,
Enabled: false,
@@ -215,25 +206,20 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
expectFilter(
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
instance.NewDebugNotificationProviderLogAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
newDefaultDebugNotificationLogChangedEvent(context.Background(),
false),
),
},
newDefaultDebugNotificationLogChangedEvent(ctx,
false),
),
),
},
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
ctx: authz.WithInstanceID(ctx, "INSTANCE"),
provider: &fs.Config{
Compact: false,
Enabled: false,
@@ -252,25 +238,20 @@ func TestCommandSide_ChangeDebugNotificationProviderLog(t *testing.T) {
t,
expectFilter(
eventFromEventPusher(
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
instance.NewDebugNotificationProviderLogAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
newDefaultDebugNotificationLogChangedEvent(context.Background(),
false),
),
},
newDefaultDebugNotificationLogChangedEvent(ctx,
false),
),
),
},
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
ctx: authz.WithInstanceID(ctx, "INSTANCE"),
provider: &fs.Config{
Compact: false,
Enabled: true,
@@ -313,6 +294,7 @@ func TestCommandSide_RemoveDebugNotificationProviderLog(t *testing.T) {
want *domain.ObjectDetails
err func(error) bool
}
ctx := authz.WithInstanceID(context.Background(), "INSTANCE")
tests := []struct {
name string
fields fields
@@ -328,7 +310,7 @@ func TestCommandSide_RemoveDebugNotificationProviderLog(t *testing.T) {
),
},
args: args{
ctx: context.Background(),
ctx: ctx,
},
res: res{
err: caos_errs.IsNotFound,
@@ -342,25 +324,20 @@ func TestCommandSide_RemoveDebugNotificationProviderLog(t *testing.T) {
expectFilter(
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDebugNotificationProviderLogAddedEvent(context.Background(),
instance.NewDebugNotificationProviderLogAddedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDebugNotificationProviderLogRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate),
),
},
instance.NewDebugNotificationProviderLogRemovedEvent(ctx,
&instance.NewAggregate("INSTANCE").Aggregate),
),
),
},
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
ctx: authz.WithInstanceID(ctx, "INSTANCE"),
},
res: res{
want: &domain.ObjectDetails{
+3 -3
View File
@@ -32,7 +32,7 @@ func (c *Commands) AddInstanceDomain(ctx context.Context, instanceDomain string)
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
@@ -50,7 +50,7 @@ func (c *Commands) SetPrimaryInstanceDomain(ctx context.Context, instanceDomain
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
@@ -68,7 +68,7 @@ func (c *Commands) RemoveInstanceDomain(ctx context.Context, instanceDomain stri
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
+28 -40
View File
@@ -9,13 +9,11 @@ import (
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/project"
)
func TestCommandSide_AddInstanceDomain(t *testing.T) {
@@ -167,20 +165,17 @@ func TestCommandSide_AddInstanceDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDomainAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"domain.ch",
false,
)),
eventFromEventPusherWithInstanceID(
"INSTANCE",
newOIDCAppChangedEventInstanceDomain(context.Background(), "consoleApplicationID", "projectID", "org1"),
),
},
uniqueConstraintsFromEventConstraint(instance.NewAddInstanceDomainUniqueConstraint("domain.ch")),
instance.NewDomainAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"domain.ch",
false,
),
newOIDCAppChangedEventInstanceDomain(
context.Background(),
"consoleApplicationID",
"projectID",
"org1",
),
),
),
externalSecure: true,
@@ -205,13 +200,11 @@ func TestCommandSide_AddInstanceDomain(t *testing.T) {
got, err := r.AddInstanceDomain(tt.args.ctx, tt.args.domain)
if tt.res.err == nil {
assert.NoError(t, err)
}
if tt.res.err != nil && !tt.res.err(err) {
} else if !tt.res.err(err) {
t.Errorf("got wrong err: %v ", err)
return
}
if tt.res.err == nil {
assert.Equal(t, tt.res.want, got)
}
assert.Equal(t, tt.res.want, got)
})
}
}
@@ -281,14 +274,10 @@ func TestCommandSide_SetPrimaryInstanceDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDomainPrimarySetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"domain.ch",
)),
},
instance.NewDomainPrimarySetEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"domain.ch",
),
),
),
},
@@ -387,15 +376,10 @@ func TestCommandSide_RemoveInstanceDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDomainRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"domain.ch",
)),
},
uniqueConstraintsFromEventConstraint(instance.NewRemoveInstanceDomainUniqueConstraint("domain.ch")),
instance.NewDomainRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"domain.ch",
),
),
),
},
@@ -458,8 +442,12 @@ func newOIDCAppChangedEventInstanceDomain(ctx context.Context, appID, projectID,
project.ChangeRedirectURIs([]string{"https://test.ch", "https://domain.ch/ui/console/auth/callback"}),
project.ChangePostLogoutRedirectURIs([]string{"https://test.ch/logout", "https://domain.ch/ui/console/signedout"}),
}
aggregate := project.NewAggregate(projectID, resourceOwner).Aggregate
aggregate.InstanceID = "INSTANCE"
event, _ := project.NewOIDCConfigChangedEvent(ctx,
&project.NewAggregate(projectID, resourceOwner).Aggregate,
&aggregate,
appID,
changes,
)
+8 -17
View File
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/id"
"github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/repository/feature"
@@ -81,14 +80,10 @@ func TestCommands_SetBooleanInstanceFeature(t *testing.T) {
eventstore: expectEventstore(
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
feature.NewSetEvent[feature.Boolean](context.Background(), &feature.NewAggregate("featureID", "instanceID").Aggregate,
feature.EventTypeFromFeature(domain.FeatureLoginDefaultOrg),
feature.Boolean{Boolean: true},
),
),
},
feature.NewSetEvent[feature.Boolean](context.Background(), &feature.NewAggregate("featureID", "instanceID").Aggregate,
feature.EventTypeFromFeature(domain.FeatureLoginDefaultOrg),
feature.Boolean{Boolean: true},
),
),
),
idGenerator: mock.ExpectID(t, "featureID"),
@@ -117,14 +112,10 @@ func TestCommands_SetBooleanInstanceFeature(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
feature.NewSetEvent[feature.Boolean](context.Background(), &feature.NewAggregate("featureID", "instanceID").Aggregate,
feature.EventTypeFromFeature(domain.FeatureLoginDefaultOrg),
feature.Boolean{Boolean: false},
),
),
},
feature.NewSetEvent[feature.Boolean](context.Background(), &feature.NewAggregate("featureID", "instanceID").Aggregate,
feature.EventTypeFromFeature(domain.FeatureLoginDefaultOrg),
feature.Boolean{Boolean: false},
),
),
),
},
@@ -21,6 +21,7 @@ func NewInstanceIDPConfigWriteModel(ctx context.Context, configID string) *Insta
WriteModel: eventstore.WriteModel{
AggregateID: authz.GetInstance(ctx).InstanceID(),
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
InstanceID: authz.GetInstance(ctx).InstanceID(),
},
ConfigID: configID,
},
+43 -67
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -61,40 +60,31 @@ func TestCommandSide_AddDefaultIDPConfig(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewIDPConfigAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1",
"name1",
domain.IDPConfigTypeOIDC,
domain.IDPConfigStylingTypeGoogle,
true,
),
),
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewIDPOIDCConfigAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"clientid1",
"config1",
"issuer",
"authorization-endpoint",
"token-endpoint",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("secret"),
},
domain.OIDCMappingFieldEmail,
domain.OIDCMappingFieldEmail,
"scope",
),
),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", idpconfig.NewAddIDPConfigNameUniqueConstraint("name1", "INSTANCE")),
instance.NewIDPConfigAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1",
"name1",
domain.IDPConfigTypeOIDC,
domain.IDPConfigStylingTypeGoogle,
true,
),
instance.NewIDPOIDCConfigAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"clientid1",
"config1",
"issuer",
"authorization-endpoint",
"token-endpoint",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("secret"),
},
domain.OIDCMappingFieldEmail,
domain.OIDCMappingFieldEmail,
"scope",
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "config1"),
@@ -139,31 +129,22 @@ func TestCommandSide_AddDefaultIDPConfig(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewIDPConfigAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1",
"name1",
domain.IDPConfigTypeOIDC,
domain.IDPConfigStylingTypeGoogle,
false,
),
),
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewIDPJWTConfigAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1",
"jwt-endpoint",
"issuer",
"keys-endpoint",
"auth",
),
),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", idpconfig.NewAddIDPConfigNameUniqueConstraint("name1", "INSTANCE")),
instance.NewIDPConfigAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1",
"name1",
domain.IDPConfigTypeOIDC,
domain.IDPConfigStylingTypeGoogle,
false,
),
instance.NewIDPJWTConfigAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1",
"jwt-endpoint",
"issuer",
"keys-endpoint",
"auth",
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "config1"),
@@ -305,13 +286,7 @@ func TestCommandSide_ChangeDefaultIDPConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultIDPConfigChangedEvent(context.Background(), "config1", "name1", "name2", domain.IDPConfigStylingTypeUnspecified, false),
),
},
uniqueConstraintsFromEventConstraint(idpconfig.NewRemoveIDPConfigNameUniqueConstraint("name1", "INSTANCE")),
uniqueConstraintsFromEventConstraint(idpconfig.NewAddIDPConfigNameUniqueConstraint("name2", "INSTANCE")),
newDefaultIDPConfigChangedEvent(context.Background(), "config1", "name1", "name2", domain.IDPConfigStylingTypeUnspecified, false),
),
),
},
@@ -329,6 +304,7 @@ func TestCommandSide_ChangeDefaultIDPConfig(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
IDPConfigID: "config1",
Name: "name2",
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/idpconfig"
"github.com/zitadel/zitadel/internal/repository/instance"
@@ -194,17 +193,13 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultIDPJWTConfigChangedEvent(context.Background(),
"config1",
"jwt-endpoint-changed",
"issuer-changed",
"keys-endpoint-changed",
"auth-changed",
),
),
},
newDefaultIDPJWTConfigChangedEvent(context.Background(),
"config1",
"jwt-endpoint-changed",
"issuer-changed",
"keys-endpoint-changed",
"auth-changed",
),
),
),
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -225,6 +220,7 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
IDPConfigID: "config1",
JWTEndpoint: "jwt-endpoint-changed",
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/idpconfig"
"github.com/zitadel/zitadel/internal/repository/instance"
@@ -224,26 +223,22 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultIDPOIDCConfigChangedEvent(context.Background(),
"config1",
"clientid-changed",
"issuer-changed",
"authorization-endpoint-changed",
"token-endpoint-changed",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("secret-changed"),
},
domain.OIDCMappingFieldPreferredLoginName,
domain.OIDCMappingFieldPreferredLoginName,
[]string{"scope", "scope2"},
),
),
},
newDefaultIDPOIDCConfigChangedEvent(context.Background(),
"config1",
"clientid-changed",
"issuer-changed",
"authorization-endpoint-changed",
"token-endpoint-changed",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("secret-changed"),
},
domain.OIDCMappingFieldPreferredLoginName,
domain.OIDCMappingFieldPreferredLoginName,
[]string{"scope", "scope2"},
),
),
),
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -268,6 +263,7 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
IDPConfigID: "config1",
ClientID: "clientid-changed",
File diff suppressed because it is too large Load Diff
+21 -36
View File
@@ -7,16 +7,13 @@ import (
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
"github.com/zitadel/zitadel/internal/repository/user"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/member"
"github.com/zitadel/zitadel/internal/repository/user"
)
func TestCommandSide_AddIAMMember(t *testing.T) {
@@ -159,14 +156,11 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
),
expectFilter(),
expectPushFailed(caos_errs.ThrowAlreadyExists(nil, "ERROR", "internal"),
[]*repository.Event{
eventFromEventPusherWithInstanceID("INSTANCE", instance.NewMemberAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"user1",
[]string{"IAM_OWNER"}...,
)),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", member.NewAddMemberUniqueConstraint("INSTANCE", "user1")),
instance.NewMemberAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"user1",
[]string{"IAM_OWNER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -208,16 +202,11 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewMemberAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"user1",
[]string{"IAM_OWNER"}...,
)),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", member.NewAddMemberUniqueConstraint("INSTANCE", "user1")),
instance.NewMemberAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"user1",
[]string{"IAM_OWNER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -388,13 +377,11 @@ func TestCommandSide_ChangeIAMMember(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(instance.NewMemberChangedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"user1",
[]string{"IAM_OWNER", "IAM_OWNER_VIEWER"}...,
)),
},
instance.NewMemberChangedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"user1",
[]string{"IAM_OWNER", "IAM_OWNER_VIEWER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -418,6 +405,7 @@ func TestCommandSide_ChangeIAMMember(t *testing.T) {
ObjectRoot: models.ObjectRoot{
ResourceOwner: "INSTANCE",
AggregateID: "INSTANCE",
InstanceID: "INSTANCE",
},
UserID: "user1",
Roles: []string{"IAM_OWNER", "IAM_OWNER_VIEWER"},
@@ -510,13 +498,10 @@ func TestCommandSide_RemoveIAMMember(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(instance.NewMemberRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"user1",
)),
},
uniqueConstraintsFromEventConstraint(member.NewRemoveMemberUniqueConstraint("INSTANCE", "user1")),
instance.NewMemberRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"user1",
),
),
),
},
+2 -2
View File
@@ -94,7 +94,7 @@ func (c *Commands) AddOIDCSettings(ctx context.Context, settings *domain.OIDCSet
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
@@ -112,7 +112,7 @@ func (c *Commands) ChangeOIDCSettings(ctx context.Context, settings *domain.OIDC
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
+14 -25
View File
@@ -8,11 +8,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
)
@@ -72,19 +70,14 @@ func TestCommandSide_AddOIDCConfig(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewOIDCSettingsAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
time.Hour*1,
time.Hour*1,
time.Hour*1,
time.Hour*1,
),
),
},
instance.NewOIDCSettingsAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
time.Hour*1,
time.Hour*1,
time.Hour*1,
time.Hour*1,
),
),
),
},
@@ -372,16 +365,12 @@ func TestCommandSide_ChangeOIDCConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("INSTANCE",
newOIDCConfigChangedEvent(
context.Background(),
time.Hour*2,
time.Hour*2,
time.Hour*2,
time.Hour*2),
),
},
newOIDCConfigChangedEvent(
context.Background(),
time.Hour*2,
time.Hour*2,
time.Hour*2,
time.Hour*2),
),
),
},
+1 -1
View File
@@ -38,7 +38,7 @@ func (c *Commands) ChangeDefaultDomainPolicy(ctx context.Context, userLoginMustB
// returning the values of the first event as this is the one from the instance
return &domain.ObjectDetails{
Sequence: pushedEvents[0].Sequence(),
EventDate: pushedEvents[0].CreationDate(),
EventDate: pushedEvents[0].CreatedAt(),
ResourceOwner: pushedEvents[0].Aggregate().ResourceOwner,
}, nil
}
+21 -39
View File
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -72,17 +71,12 @@ func TestCommandSide_AddDefaultDomainPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewDomainPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
true,
true,
),
),
},
instance.NewDomainPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
true,
true,
),
),
),
},
@@ -302,33 +296,21 @@ func TestCommandSide_ChangeDefaultDomainPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("INSTANCE",
newDefaultDomainPolicyChangedEvent(context.Background(), false, false, false),
),
eventFromEventPusherWithInstanceID("INSTANCE",
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"user1",
"[email protected]",
false,
user.UsernameChangedEventWithPolicyChange(),
),
),
eventFromEventPusherWithInstanceID("INSTANCE",
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org3").Aggregate,
"user1",
"[email protected]",
false,
user.UsernameChangedEventWithPolicyChange(),
),
),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", user.NewRemoveUsernameUniqueConstraint("user1", "org1", true)),
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", user.NewAddUsernameUniqueConstraint("[email protected]", "org1", false)),
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", user.NewRemoveUsernameUniqueConstraint("user1", "org3", true)),
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", user.NewAddUsernameUniqueConstraint("[email protected]", "org3", false)),
newDefaultDomainPolicyChangedEvent(context.Background(), false, false, false),
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"user1",
"[email protected]",
false,
user.UsernameChangedEventWithPolicyChange(),
),
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org3").Aggregate,
"user1",
"[email protected]",
false,
user.UsernameChangedEventWithPolicyChange(),
),
),
),
},
+71 -125
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -98,25 +97,20 @@ func TestCommandSide_AddDefaultLabelPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewLabelPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
true,
true,
true,
),
),
},
instance.NewLabelPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
true,
true,
true,
),
),
),
},
@@ -280,23 +274,19 @@ func TestCommandSide_ChangeDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultLabelPolicyChangedEvent(
context.Background(),
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
false,
false,
false),
),
},
newDefaultLabelPolicyChangedEvent(
context.Background(),
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
false,
false,
false),
),
),
},
@@ -321,6 +311,7 @@ func TestCommandSide_ChangeDefaultLabelPolicy(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
PrimaryColor: "#000000",
BackgroundColor: "#000000",
@@ -412,14 +403,9 @@ func TestCommandSide_ActivateDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewLabelPolicyActivatedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
),
),
},
instance.NewLabelPolicyActivatedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
),
),
),
},
@@ -559,14 +545,10 @@ func TestCommandSide_AddLogoDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyLogoAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"logo",
),
),
},
instance.NewLabelPolicyLogoAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"logo",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -712,14 +694,10 @@ func TestCommandSide_RemoveLogoDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyLogoRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
},
instance.NewLabelPolicyLogoRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
),
},
@@ -860,14 +838,10 @@ func TestCommandSide_AddIconDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyIconAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"icon",
),
),
},
instance.NewLabelPolicyIconAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"icon",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -974,14 +948,10 @@ func TestCommandSide_RemoveIconDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyIconRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
},
instance.NewLabelPolicyIconRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
),
},
@@ -1125,14 +1095,10 @@ func TestCommandSide_AddLogoDarkDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"logo",
),
),
},
instance.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"logo",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -1278,14 +1244,10 @@ func TestCommandSide_RemoveLogoDarkDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyLogoDarkRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
},
instance.NewLabelPolicyLogoDarkRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
),
},
@@ -1426,14 +1388,10 @@ func TestCommandSide_AddIconDarkDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyIconDarkAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"icon",
),
),
},
instance.NewLabelPolicyIconDarkAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"icon",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -1579,14 +1537,10 @@ func TestCommandSide_RemoveIconDarkDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyIconDarkRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
},
instance.NewLabelPolicyIconDarkRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
),
},
@@ -1727,14 +1681,10 @@ func TestCommandSide_AddFontDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyFontAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"font",
),
),
},
instance.NewLabelPolicyFontAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"font",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -1880,14 +1830,10 @@ func TestCommandSide_RemoveFontDefaultLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLabelPolicyFontRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
},
instance.NewLabelPolicyFontRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"key",
),
),
),
},
+1 -5
View File
@@ -198,11 +198,7 @@ func (c *Commands) defaultLoginPolicyWriteModelByID(ctx context.Context, writeMo
ctx, span := tracing.NewSpan(ctx)
defer func() { span.EndWithError(err) }()
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
if err != nil {
return err
}
return nil
return c.eventstore.FilterToQueryReducer(ctx, writeModel)
}
func (c *Commands) getDefaultLoginPolicy(ctx context.Context) (*domain.LoginPolicy, error) {
@@ -18,6 +18,7 @@ func NewInstanceIdentityProviderWriteModel(ctx context.Context, idpConfigID stri
WriteModel: eventstore.WriteModel{
AggregateID: authz.GetInstance(ctx).InstanceID(),
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
InstanceID: authz.GetInstance(ctx).InstanceID(),
},
IDPConfigID: idpConfigID,
},
+62 -128
View File
@@ -5,17 +5,16 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/policy"
"github.com/zitadel/zitadel/internal/repository/user"
"github.com/stretchr/testify/assert"
)
func TestCommandSide_ChangeDefaultLoginPolicy(t *testing.T) {
@@ -143,29 +142,24 @@ func TestCommandSide_ChangeDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
newDefaultLoginPolicyChangedEvent(context.Background(),
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
domain.PasswordlessTypeNotAllowed,
"",
time.Hour*10,
time.Hour*20,
time.Hour*30,
time.Hour*40,
time.Hour*50),
),
},
newDefaultLoginPolicyChangedEvent(context.Background(),
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
domain.PasswordlessTypeNotAllowed,
"",
time.Hour*10,
time.Hour*20,
time.Hour*30,
time.Hour*40,
time.Hour*50),
),
),
},
@@ -416,14 +410,9 @@ func TestCommandSide_AddIDPProviderDefaultLoginPolicy(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewIdentityProviderAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1"),
),
},
instance.NewIdentityProviderAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1"),
),
),
},
@@ -651,13 +640,9 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewIdentityProviderRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1"),
),
},
instance.NewIdentityProviderRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1"),
),
),
},
@@ -711,13 +696,9 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewIdentityProviderRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1"),
),
},
instance.NewIdentityProviderRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1"),
),
),
},
@@ -786,18 +767,12 @@ func TestCommandSide_RemoveIDPProviderDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewIdentityProviderRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1"),
),
eventFromEventPusher(
user.NewUserIDPLinkCascadeRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"config1", "externaluser1")),
},
uniqueConstraintsFromEventConstraint(user.NewRemoveUserIDPLinkUniqueConstraint("config1", "externaluser1")),
instance.NewIdentityProviderRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"config1"),
user.NewUserIDPLinkCascadeRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"config1", "externaluser1"),
),
),
},
@@ -905,14 +880,9 @@ func TestCommandSide_AddSecondFactorDefaultLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeTOTP),
),
},
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeTOTP),
),
),
},
@@ -933,14 +903,9 @@ func TestCommandSide_AddSecondFactorDefaultLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPEmail),
),
},
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPEmail),
),
),
},
@@ -961,14 +926,9 @@ func TestCommandSide_AddSecondFactorDefaultLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
},
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
),
},
@@ -996,14 +956,9 @@ func TestCommandSide_AddSecondFactorDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
},
instance.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
),
},
@@ -1187,13 +1142,9 @@ func TestCommandSide_RemoveSecondFactorDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeTOTP),
),
},
instance.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeTOTP),
),
),
},
@@ -1221,13 +1172,9 @@ func TestCommandSide_RemoveSecondFactorDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPEmail),
),
},
instance.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPEmail),
),
),
},
@@ -1255,13 +1202,9 @@ func TestCommandSide_RemoveSecondFactorDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
},
instance.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
),
},
@@ -1381,14 +1324,9 @@ func TestCommandSide_AddMultiFactorDefaultLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.MultiFactorTypeU2FWithPIN),
),
},
instance.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.MultiFactorTypeU2FWithPIN),
),
),
},
@@ -1514,13 +1452,9 @@ func TestCommandSide_RemoveMultiFactorDefaultLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.MultiFactorTypeU2FWithPIN),
),
},
instance.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.MultiFactorTypeU2FWithPIN),
),
),
},
@@ -21,6 +21,7 @@ func NewInstanceMailTemplateWriteModel(ctx context.Context) *InstanceMailTemplat
WriteModel: eventstore.WriteModel{
AggregateID: authz.GetInstance(ctx).InstanceID(),
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
InstanceID: authz.GetInstance(ctx).InstanceID(),
},
},
}
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -80,15 +79,11 @@ func TestCommandSide_AddDefaultMailTemplatePolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewMailTemplateAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
[]byte("template"),
),
),
},
instance.NewMailTemplateAddedEvent(
authz.WithInstanceID(context.Background(), "INSTANCE"),
&instance.NewAggregate("INSTANCE").Aggregate,
[]byte("template"),
),
),
),
},
@@ -219,11 +214,7 @@ func TestCommandSide_ChangeDefaultMailTemplatePolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultMailTemplatePolicyChangedEvent(context.Background(), []byte("template-change")),
),
},
newDefaultMailTemplatePolicyChangedEvent(context.Background(), []byte("template-change")),
),
),
},
@@ -238,6 +229,7 @@ func TestCommandSide_ChangeDefaultMailTemplatePolicy(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
Template: []byte("template-change"),
},
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/policy"
)
@@ -64,14 +63,10 @@ func TestCommandSide_AddDefaultNotificationPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewNotificationPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
},
instance.NewNotificationPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
),
},
@@ -93,14 +88,10 @@ func TestCommandSide_AddDefaultNotificationPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewNotificationPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
},
instance.NewNotificationPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
),
),
),
},
@@ -209,12 +200,9 @@ func TestCommandSide_ChangeDefaultNotificationPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultNotificationPolicyChangedEvent(context.Background(),
true,
)),
},
newDefaultNotificationPolicyChangedEvent(context.Background(),
true,
),
),
),
},
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -67,16 +66,11 @@ func TestCommandSide_AddDefaultPasswordAgePolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewPasswordAgePolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
365,
10,
),
),
},
instance.NewPasswordAgePolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
365,
10,
),
),
),
},
@@ -190,11 +184,7 @@ func TestCommandSide_ChangeDefaultPasswordAgePolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultPasswordAgePolicyChangedEvent(context.Background(), 125, 5),
),
},
newDefaultPasswordAgePolicyChangedEvent(context.Background(), 125, 5),
),
),
},
@@ -210,6 +200,7 @@ func TestCommandSide_ChangeDefaultPasswordAgePolicy(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
MaxAgeDays: 125,
ExpireWarnDays: 5,
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -92,16 +91,11 @@ func TestCommandSide_AddDefaultPasswordComplexityPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
8,
true, true, true, true,
),
),
},
instance.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
8,
true, true, true, true,
),
),
),
},
@@ -245,11 +239,7 @@ func TestCommandSide_ChangeDefaultPasswordComplexityPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultPasswordComplexityPolicyChangedEvent(context.Background(), 10, false, false, false, false),
),
},
newDefaultPasswordComplexityPolicyChangedEvent(context.Background(), 10, false, false, false, false),
),
),
},
@@ -268,6 +258,7 @@ func TestCommandSide_ChangeDefaultPasswordComplexityPolicy(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
MinLength: 10,
HasUppercase: false,
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -67,16 +66,11 @@ func TestCommandSide_AddDefaultLockoutPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewLockoutPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
10,
true,
),
),
},
instance.NewLockoutPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
10,
true,
),
),
),
},
@@ -190,11 +184,7 @@ func TestCommandSide_ChangeDefaultLockoutPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultLockoutPolicyChangedEvent(context.Background(), 20, false),
),
},
newDefaultLockoutPolicyChangedEvent(context.Background(), 20, false),
),
),
},
@@ -210,6 +200,7 @@ func TestCommandSide_ChangeDefaultLockoutPolicy(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
MaxPasswordAttempts: 20,
ShowLockOutFailures: false,
@@ -7,11 +7,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -74,18 +72,13 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewPrivacyPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"TOSLink",
"PrivacyLink",
"HelpLink",
"[email protected]",
),
),
},
instance.NewPrivacyPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"TOSLink",
"PrivacyLink",
"HelpLink",
"[email protected]",
),
),
),
},
@@ -127,18 +120,13 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewPrivacyPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"",
"",
"",
"",
),
),
},
instance.NewPrivacyPolicyAddedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"",
"",
"",
"",
),
),
),
},
@@ -282,16 +270,12 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDefaultPrivacyPolicyChangedEvent(context.Background(),
"TOSLinkChanged",
"PrivacyLinkChanged",
"HelpLinkChanged",
"[email protected]",
),
),
},
newDefaultPrivacyPolicyChangedEvent(context.Background(),
"TOSLinkChanged",
"PrivacyLinkChanged",
"HelpLinkChanged",
"[email protected]",
),
),
),
},
@@ -309,6 +293,7 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
ObjectRoot: models.ObjectRoot{
AggregateID: "INSTANCE",
ResourceOwner: "INSTANCE",
InstanceID: "INSTANCE",
},
TOSLink: "TOSLinkChanged",
PrivacyLink: "PrivacyLinkChanged",
+1 -1
View File
@@ -23,7 +23,7 @@ func (c *Commands) SetSecurityPolicy(ctx context.Context, enabled bool, allowedO
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
@@ -28,6 +28,7 @@ func NewInstanceSecretGeneratorConfigWriteModel(ctx context.Context, GeneratorTy
WriteModel: eventstore.WriteModel{
AggregateID: authz.GetInstance(ctx).InstanceID(),
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
InstanceID: authz.GetInstance(ctx).InstanceID(),
},
GeneratorType: GeneratorType,
}
+1 -1
View File
@@ -25,7 +25,7 @@ func (c *Commands) AddSecretGeneratorConfig(ctx context.Context, typ domain.Secr
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: agg.ResourceOwner,
}, nil
}
+45 -73
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
)
@@ -95,23 +94,17 @@ func TestCommandSide_AddSecretGenerator(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSecretGeneratorAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecretGeneratorTypeInitCode,
4,
time.Hour*1,
true,
true,
true,
true,
),
),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", instance.NewAddSecretGeneratorTypeUniqueConstraint(domain.SecretGeneratorTypeInitCode)),
instance.NewSecretGeneratorAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecretGeneratorTypeInitCode,
4,
time.Hour*1,
true,
true,
true,
true,
),
),
),
},
@@ -193,23 +186,17 @@ func TestCommandSide_ChangeSecretGenerator(t *testing.T) {
eventstore: expectEventstore(
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSecretGeneratorAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecretGeneratorTypeInitCode,
4,
time.Hour*1,
true,
true,
true,
true,
),
),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", instance.NewAddSecretGeneratorTypeUniqueConstraint(domain.SecretGeneratorTypeInitCode)),
instance.NewSecretGeneratorAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecretGeneratorTypeInitCode,
4,
time.Hour*1,
true,
true,
true,
true,
),
),
),
},
@@ -256,23 +243,17 @@ func TestCommandSide_ChangeSecretGenerator(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSecretGeneratorAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecretGeneratorTypeInitCode,
4,
time.Hour*1,
true,
true,
true,
true,
),
),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", instance.NewAddSecretGeneratorTypeUniqueConstraint(domain.SecretGeneratorTypeInitCode)),
instance.NewSecretGeneratorAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecretGeneratorTypeInitCode,
4,
time.Hour*1,
true,
true,
true,
true,
),
),
),
},
@@ -351,19 +332,15 @@ func TestCommandSide_ChangeSecretGenerator(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("INSTANCE",
newSecretGeneratorChangedEvent(context.Background(),
domain.SecretGeneratorTypeInitCode,
8,
time.Hour*2,
false,
false,
false,
false,
),
),
},
newSecretGeneratorChangedEvent(context.Background(),
domain.SecretGeneratorTypeInitCode,
8,
time.Hour*2,
false,
false,
false,
false,
),
),
),
},
@@ -511,14 +488,9 @@ func TestCommandSide_RemoveSecretGenerator(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewSecretGeneratorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecretGeneratorTypeInitCode),
),
},
uniqueConstraintsFromEventConstraint(instance.NewRemoveSecretGeneratorTypeUniqueConstraint(domain.SecretGeneratorTypeInitCode)),
instance.NewSecretGeneratorRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
domain.SecretGeneratorTypeInitCode),
),
),
},
+12 -26
View File
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
)
@@ -133,15 +132,10 @@ func TestCommandSide_UpdateInstance(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewInstanceChangedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"INSTANCE_CHANGED",
),
),
},
instance.NewInstanceChangedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"INSTANCE_CHANGED",
),
),
),
},
@@ -271,22 +265,14 @@ func TestCommandSide_RemoveInstance(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewInstanceRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"INSTANCE",
[]string{
"instance.domain",
"custom.domain",
},
),
),
},
uniqueConstraintsFromEventConstraint(instance.NewRemoveInstanceDomainUniqueConstraint("instance.domain")),
uniqueConstraintsFromEventConstraint(instance.NewRemoveInstanceDomainUniqueConstraint("custom.domain")),
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", eventstore.NewRemoveInstanceUniqueConstraints()),
instance.NewInstanceRemovedEvent(context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"INSTANCE",
[]string{
"instance.domain",
"custom.domain",
},
),
),
),
},
+43 -105
View File
@@ -40,7 +40,12 @@ func eventstoreExpect(t *testing.T, expects ...expect) *eventstore.Eventstore {
for _, e := range expects {
e(m)
}
es := eventstore.NewEventstore(eventstore.TestConfig(m))
es := eventstore.NewEventstore(
&eventstore.Config{
Querier: m.MockQuerier,
Pusher: m.MockPusher,
},
)
iam_repo.RegisterEventMappers(es)
org.RegisterEventMappers(es)
usr_repo.RegisterEventMappers(es)
@@ -72,89 +77,43 @@ func eventPusherToEvents(eventsPushes ...eventstore.Command) []*repository.Event
}
events[i] = &repository.Event{
AggregateID: event.Aggregate().ID,
AggregateType: repository.AggregateType(event.Aggregate().Type),
AggregateType: event.Aggregate().Type,
ResourceOwner: sql.NullString{String: event.Aggregate().ResourceOwner, Valid: event.Aggregate().ResourceOwner != ""},
EditorService: event.EditorService(),
EditorUser: event.EditorUser(),
Type: repository.EventType(event.Type()),
Version: repository.Version(event.Aggregate().Version),
EditorUser: event.Creator(),
Typ: event.Type(),
Version: event.Aggregate().Version,
Data: data,
Constraints: event.UniqueConstraints(),
}
}
return events
}
type testRepo struct {
events []*repository.Event
uniqueConstraints []*repository.UniqueConstraint
sequence uint64
err error
t *testing.T
}
func (repo *testRepo) Health(ctx context.Context) error {
return nil
}
func (repo *testRepo) Push(ctx context.Context, events []*repository.Event, uniqueConstraints ...*repository.UniqueConstraint) error {
repo.events = append(repo.events, events...)
repo.uniqueConstraints = append(repo.uniqueConstraints, uniqueConstraints...)
return nil
}
func (repo *testRepo) Filter(ctx context.Context, searchQuery *repository.SearchQuery) ([]*repository.Event, error) {
events := make([]*repository.Event, 0, len(repo.events))
for _, event := range repo.events {
for _, filter := range searchQuery.Filters {
for _, f := range filter {
if f.Field == repository.FieldAggregateType {
if event.AggregateType != f.Value {
continue
}
}
}
}
events = append(events, event)
}
return repo.events, nil
}
func filterAggregateType(aggregateType string) {
}
func (repo *testRepo) LatestSequence(ctx context.Context, queryFactory *repository.SearchQuery) (uint64, error) {
if repo.err != nil {
return 0, repo.err
}
return repo.sequence, nil
}
func expectPush(events []*repository.Event, uniqueConstraints ...*repository.UniqueConstraint) expect {
func expectPush(commands ...eventstore.Command) expect {
return func(m *mock.MockRepository) {
m.ExpectPush(events, uniqueConstraints...)
m.ExpectPush(commands)
}
}
func expectPushFailed(err error, events []*repository.Event, uniqueConstraints ...*repository.UniqueConstraint) expect {
func expectPushFailed(err error, commands ...eventstore.Command) expect {
return func(m *mock.MockRepository) {
m.ExpectPushFailed(err, events, uniqueConstraints...)
m.ExpectPushFailed(err, commands)
}
}
func expectRandomPush(events []*repository.Event, uniqueConstraints ...*repository.UniqueConstraint) expect {
func expectRandomPush(events []eventstore.Command) expect {
return func(m *mock.MockRepository) {
m.ExpectRandomPush(events, uniqueConstraints...)
m.ExpectRandomPush(events)
}
}
func expectRandomPushFailed(err error, events []*repository.Event, uniqueConstraints ...*repository.UniqueConstraint) expect {
func expectRandomPushFailed(err error, events []eventstore.Command) expect {
return func(m *mock.MockRepository) {
m.ExpectRandomPushFailed(err, events, uniqueConstraints...)
m.ExpectRandomPushFailed(err, events)
}
}
func expectFilter(events ...*repository.Event) expect {
func expectFilter(events ...eventstore.Event) expect {
return func(m *mock.MockRepository) {
m.ExpectFilterEvents(events...)
}
@@ -180,39 +139,35 @@ func expectFilterOrgMemberNotFound() expect {
func eventFromEventPusher(event eventstore.Command) *repository.Event {
data, _ := eventstore.EventData(event)
return &repository.Event{
ID: "",
Sequence: 0,
PreviousAggregateSequence: 0,
PreviousAggregateTypeSequence: 0,
CreationDate: time.Time{},
Type: repository.EventType(event.Type()),
Data: data,
EditorService: event.EditorService(),
EditorUser: event.EditorUser(),
Version: repository.Version(event.Aggregate().Version),
AggregateID: event.Aggregate().ID,
AggregateType: repository.AggregateType(event.Aggregate().Type),
ResourceOwner: sql.NullString{String: event.Aggregate().ResourceOwner, Valid: event.Aggregate().ResourceOwner != ""},
InstanceID: event.Aggregate().InstanceID,
ID: "",
Seq: 0,
CreationDate: time.Time{},
Typ: event.Type(),
Data: data,
EditorUser: event.Creator(),
Version: event.Aggregate().Version,
AggregateID: event.Aggregate().ID,
AggregateType: event.Aggregate().Type,
ResourceOwner: sql.NullString{String: event.Aggregate().ResourceOwner, Valid: event.Aggregate().ResourceOwner != ""},
Constraints: event.UniqueConstraints(),
}
}
func eventFromEventPusherWithInstanceID(instanceID string, event eventstore.Command) *repository.Event {
data, _ := eventstore.EventData(event)
return &repository.Event{
ID: "",
Sequence: 0,
PreviousAggregateSequence: 0,
PreviousAggregateTypeSequence: 0,
CreationDate: time.Time{},
Type: repository.EventType(event.Type()),
Data: data,
EditorService: event.EditorService(),
EditorUser: event.EditorUser(),
Version: repository.Version(event.Aggregate().Version),
AggregateID: event.Aggregate().ID,
AggregateType: repository.AggregateType(event.Aggregate().Type),
ResourceOwner: sql.NullString{String: event.Aggregate().ResourceOwner, Valid: event.Aggregate().ResourceOwner != ""},
InstanceID: instanceID,
ID: "",
Seq: 0,
CreationDate: time.Time{},
Typ: event.Type(),
Data: data,
EditorUser: event.Creator(),
Version: event.Aggregate().Version,
AggregateID: event.Aggregate().ID,
AggregateType: event.Aggregate().Type,
ResourceOwner: sql.NullString{String: event.Aggregate().ResourceOwner, Valid: event.Aggregate().ResourceOwner != ""},
InstanceID: instanceID,
}
}
@@ -222,23 +177,6 @@ func eventFromEventPusherWithCreationDateNow(event eventstore.Command) *reposito
return e
}
func uniqueConstraintsFromEventConstraint(constraint *eventstore.EventUniqueConstraint) *repository.UniqueConstraint {
return &repository.UniqueConstraint{
UniqueType: constraint.UniqueType,
UniqueField: constraint.UniqueField,
ErrorMessage: constraint.ErrorMessage,
Action: repository.UniqueConstraintAction(constraint.Action)}
}
func uniqueConstraintsFromEventConstraintWithInstanceID(instanceID string, constraint *eventstore.EventUniqueConstraint) *repository.UniqueConstraint {
return &repository.UniqueConstraint{
InstanceID: instanceID,
UniqueType: constraint.UniqueType,
UniqueField: constraint.UniqueField,
ErrorMessage: constraint.ErrorMessage,
Action: repository.UniqueConstraintAction(constraint.Action)}
}
func GetMockSecretGenerator(t *testing.T) crypto.Generator {
ctrl := gomock.NewController(t)
alg := crypto.CreateMockEncryptionAlg(ctrl)
+22 -51
View File
@@ -16,7 +16,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/id"
"github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/repository/authrequest"
@@ -184,19 +183,11 @@ func TestCommands_AddOIDCSessionAccessToken(t *testing.T) {
),
expectFilter(), // token lifetime
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"userID", "sessionID", "clientID", []string{"audience"}, []string{"openid"}, []domain.UserAuthMethodType{domain.UserAuthMethodTypePassword}, testNow),
),
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewAccessTokenAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"at_accessTokenID", []string{"openid"}, time.Hour),
),
eventFromEventPusherWithInstanceID("instanceID",
authrequest.NewSucceededEvent(context.Background(), &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
),
},
oidcsession.NewAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"userID", "sessionID", "clientID", []string{"audience"}, []string{"openid"}, []domain.UserAuthMethodType{domain.UserAuthMethodTypePassword}, testNow),
oidcsession.NewAccessTokenAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"at_accessTokenID", []string{"openid"}, time.Hour),
authrequest.NewSucceededEvent(context.Background(), &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
),
),
idGenerator: mock.NewIDGeneratorExpectIDs(t, "oidcSessionID", "accessTokenID"),
@@ -385,23 +376,13 @@ func TestCommands_AddOIDCSessionRefreshAndAccessToken(t *testing.T) {
),
expectFilter(), // token lifetime
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"userID", "sessionID", "clientID", []string{"audience"}, []string{"openid", "offline_access"}, []domain.UserAuthMethodType{domain.UserAuthMethodTypePassword}, testNow),
),
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewAccessTokenAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"at_accessTokenID", []string{"openid", "offline_access"}, time.Hour),
),
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewRefreshTokenAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"rt_refreshTokenID", 7*24*time.Hour, 24*time.Hour),
),
eventFromEventPusherWithInstanceID("instanceID",
authrequest.NewSucceededEvent(context.Background(), &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
),
},
oidcsession.NewAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"userID", "sessionID", "clientID", []string{"audience"}, []string{"openid", "offline_access"}, []domain.UserAuthMethodType{domain.UserAuthMethodTypePassword}, testNow),
oidcsession.NewAccessTokenAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"at_accessTokenID", []string{"openid", "offline_access"}, time.Hour),
oidcsession.NewRefreshTokenAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"rt_refreshTokenID", 7*24*time.Hour, 24*time.Hour),
authrequest.NewSucceededEvent(context.Background(), &authrequest.NewAggregate("V2_authRequestID", "instanceID").Aggregate),
),
),
idGenerator: mock.NewIDGeneratorExpectIDs(t, "oidcSessionID", "accessTokenID", "refreshTokenID"),
@@ -575,16 +556,10 @@ func TestCommands_ExchangeOIDCSessionRefreshAndAccessToken(t *testing.T) {
),
expectFilter(), // token lifetime
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewAccessTokenAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"at_accessTokenID", []string{"openid", "offline_access"}, time.Hour),
),
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewRefreshTokenRenewedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"rt_refreshTokenID2", 24*time.Hour),
),
},
oidcsession.NewAccessTokenAddedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"at_accessTokenID", []string{"openid", "offline_access"}, time.Hour),
oidcsession.NewRefreshTokenRenewedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate,
"rt_refreshTokenID2", 24*time.Hour),
),
),
idGenerator: mock.NewIDGeneratorExpectIDs(t, "accessTokenID", "refreshTokenID2"),
@@ -906,11 +881,9 @@ func TestCommands_RevokeOIDCSessionToken(t *testing.T) {
"rt_refreshTokenID", 7*24*time.Hour, 24*time.Hour),
),
),
expectPush([]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewRefreshTokenRevokedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate),
),
}),
expectPush(
oidcsession.NewRefreshTokenRevokedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate),
),
),
keyAlgorithm: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
},
@@ -985,11 +958,9 @@ func TestCommands_RevokeOIDCSessionToken(t *testing.T) {
"rt_refreshTokenID", 7*24*time.Hour, 24*time.Hour),
),
),
expectPush([]*repository.Event{
eventFromEventPusherWithInstanceID("instanceID",
oidcsession.NewAccessTokenRevokedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate),
),
}),
expectPush(
oidcsession.NewAccessTokenRevokedEvent(context.Background(), &oidcsession.NewAggregate("V2_oidcSessionID", "org1").Aggregate),
),
),
keyAlgorithm: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
},
+2 -2
View File
@@ -167,7 +167,7 @@ func (c *orgSetupCommands) push(ctx context.Context) (_ *CreatedOrg, err error)
return &CreatedOrg{
ObjectDetails: &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: c.aggregate.ID,
},
CreatedAdmins: c.createdAdmins(),
@@ -424,7 +424,7 @@ func (c *Commands) RemoveOrg(ctx context.Context, id string) (*domain.ObjectDeta
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
+53 -96
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
"github.com/zitadel/zitadel/internal/id/mock"
@@ -60,18 +59,13 @@ func TestCommands_AddAction(t *testing.T) {
eventstore: eventstoreExpect(t,
expectPushFailed(
errors.ThrowPreconditionFailed(nil, "id", "name already exists"),
[]*repository.Event{
eventFromEventPusher(
action.NewAddedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
"name",
"name() {};",
0,
false,
),
),
},
uniqueConstraintsFromEventConstraint(action.NewAddActionNameUniqueConstraint("name", "org1")),
action.NewAddedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
"name",
"name() {};",
0,
false,
),
),
),
idGenerator: mock.ExpectID(t, "id1"),
@@ -93,18 +87,13 @@ func TestCommands_AddAction(t *testing.T) {
fields{
eventstore: eventstoreExpect(t,
expectPush(
[]*repository.Event{
eventFromEventPusher(
action.NewAddedEvent(context.Background(),
&action.NewAggregate("id2", "org1").Aggregate,
"name2",
"name2() {};",
0,
false,
),
),
},
uniqueConstraintsFromEventConstraint(action.NewAddActionNameUniqueConstraint("name2", "org1")),
action.NewAddedEvent(context.Background(),
&action.NewAggregate("id2", "org1").Aggregate,
"name2",
"name2() {};",
0,
false,
),
),
),
idGenerator: mock.ExpectID(t, "id2"),
@@ -253,22 +242,16 @@ func TestCommands_ChangeAction(t *testing.T) {
),
expectPushFailed(
errors.ThrowPreconditionFailed(nil, "id", "name already exists"),
[]*repository.Event{
eventFromEventPusher(
func() *action.ChangedEvent {
event, _ := action.NewChangedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
[]action.ActionChanges{
action.ChangeName("name2", "name"),
action.ChangeScript("name2() {};"),
},
)
return event
}(),
),
},
uniqueConstraintsFromEventConstraint(action.NewRemoveActionNameUniqueConstraint("name", "org1")),
uniqueConstraintsFromEventConstraint(action.NewAddActionNameUniqueConstraint("name2", "org1")),
func() *action.ChangedEvent {
event, _ := action.NewChangedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
[]action.ActionChanges{
action.ChangeName("name2", "name"),
action.ChangeScript("name2() {};"),
},
)
return event
}(),
),
),
},
@@ -303,22 +286,16 @@ func TestCommands_ChangeAction(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
func() *action.ChangedEvent {
event, _ := action.NewChangedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
[]action.ActionChanges{
action.ChangeName("name2", "name"),
action.ChangeScript("name2() {};"),
},
)
return event
}(),
),
},
uniqueConstraintsFromEventConstraint(action.NewRemoveActionNameUniqueConstraint("name", "org1")),
uniqueConstraintsFromEventConstraint(action.NewAddActionNameUniqueConstraint("name2", "org1")),
func() *action.ChangedEvent {
event, _ := action.NewChangedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
[]action.ActionChanges{
action.ChangeName("name2", "name"),
action.ChangeScript("name2() {};"),
},
)
return event
}(),
),
),
},
@@ -455,13 +432,9 @@ func TestCommands_DeactivateAction(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
action.NewDeactivatedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
),
),
},
action.NewDeactivatedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
),
),
),
},
@@ -592,13 +565,9 @@ func TestCommands_ReactivateAction(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
action.NewReactivatedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
),
),
},
action.NewReactivatedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
),
),
),
},
@@ -699,15 +668,10 @@ func TestCommands_DeleteAction(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
action.NewRemovedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
"name",
),
),
},
uniqueConstraintsFromEventConstraint(action.NewRemoveActionNameUniqueConstraint("name", "org1")),
action.NewRemovedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
"name",
),
),
),
},
@@ -738,22 +702,15 @@ func TestCommands_DeleteAction(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
action.NewRemovedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
"name",
),
),
eventFromEventPusher(
org.NewTriggerActionsCascadeRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication,
"id1",
),
),
},
uniqueConstraintsFromEventConstraint(action.NewRemoveActionNameUniqueConstraint("name", "org1")),
action.NewRemovedEvent(context.Background(),
&action.NewAggregate("id1", "org1").Aggregate,
"name",
),
org.NewTriggerActionsCascadeRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication,
"id1",
),
),
),
},
File diff suppressed because it is too large Load Diff
+108 -133
View File
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/org"
)
@@ -71,71 +70,61 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageGreeting,
"Greeting",
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageSubject,
"Subject",
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageTitle,
"Title",
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessagePreHeader,
"PreHeader",
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageText,
"Text",
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageButtonText,
"ButtonText",
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageFooterText,
"Footer",
language.English,
),
),
},
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageGreeting,
"Greeting",
language.English,
),
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageSubject,
"Subject",
language.English,
),
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageTitle,
"Title",
language.English,
),
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessagePreHeader,
"PreHeader",
language.English,
),
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageText,
"Text",
language.English,
),
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageButtonText,
"ButtonText",
language.English,
),
org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageFooterText,
"Footer",
language.English,
),
),
),
},
@@ -231,64 +220,54 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageGreeting,
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageSubject,
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageTitle,
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessagePreHeader,
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageText,
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageButtonText,
language.English,
),
),
eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageFooterText,
language.English,
),
),
},
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageGreeting,
language.English,
),
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageSubject,
language.English,
),
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageTitle,
language.English,
),
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessagePreHeader,
language.English,
),
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageText,
language.English,
),
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageButtonText,
language.English,
),
org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
domain.MessageFooterText,
language.English,
),
),
),
},
@@ -472,15 +451,11 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewCustomTextTemplateRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
language.English,
),
),
},
org.NewCustomTextTemplateRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"Template",
language.English,
),
),
),
},
+60 -87
View File
@@ -15,7 +15,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -366,12 +365,10 @@ func TestCommandSide_AddOrgDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
)),
},
org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
),
),
),
},
@@ -572,19 +569,17 @@ func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
domain.OrgDomainValidationTypeDNS,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
)),
},
org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
domain.OrgDomainValidationTypeDNS,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
),
),
),
secretGenerator: GetMockSecretGenerator(t),
@@ -624,19 +619,17 @@ func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
domain.OrgDomainValidationTypeHTTP,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
)),
},
org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
domain.OrgDomainValidationTypeHTTP,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
),
),
),
secretGenerator: GetMockSecretGenerator(t),
@@ -875,12 +868,10 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainVerificationFailedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
)),
},
org.NewDomainVerificationFailedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
),
),
),
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -933,13 +924,10 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("domain.ch")),
org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
),
),
),
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -995,13 +983,10 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("domain.ch")),
org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
),
),
),
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -1078,21 +1063,16 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
&org.NewAggregate("org2").Aggregate,
false, false, false))),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
)),
eventFromEventPusher(user.NewDomainClaimedEvent(context.Background(),
&user.NewAggregate("user1", "org2").Aggregate,
"[email protected].ch",
"[email protected]",
false,
)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("domain.ch")),
uniqueConstraintsFromEventConstraint(user.NewRemoveUsernameUniqueConstraint("[email protected]", "org2", false)),
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("[email protected]", "org2", false)),
org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
),
user.NewDomainClaimedEvent(context.Background(),
&user.NewAggregate("user1", "org2").Aggregate,
"[email protected]",
"username@domain.ch",
false,
),
),
),
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -1283,12 +1263,10 @@ func TestCommandSide_SetPrimaryDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
)),
},
org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch",
),
),
),
},
@@ -1476,12 +1454,10 @@ func TestCommandSide_RemoveOrgDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch", false,
)),
},
org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch", false,
),
),
),
},
@@ -1526,13 +1502,10 @@ func TestCommandSide_RemoveOrgDomain(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch", true,
)),
},
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgDomainUniqueConstraint("domain.ch")),
org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"domain.ch", true,
),
),
),
},
+8 -12
View File
@@ -79,11 +79,9 @@ func TestCommands_ClearFlow(t *testing.T) {
),
),
expectPush(
eventPusherToEvents(
org.NewFlowClearedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication,
),
org.NewFlowClearedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication,
),
),
),
@@ -241,13 +239,11 @@ func TestCommands_SetTriggerActions(t *testing.T) {
),
),
expectPush(
eventPusherToEvents(
org.NewTriggerActionsSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication,
domain.TriggerTypePostAuthentication,
[]string{"actionID1"},
),
org.NewTriggerActionsSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication,
domain.TriggerTypePostAuthentication,
[]string{"actionID1"},
),
),
),
+59 -87
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -91,38 +90,31 @@ func TestCommandSide_AddIDPConfig(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
"name1",
domain.IDPConfigTypeOIDC,
domain.IDPConfigStylingTypeGoogle,
true,
),
),
eventFromEventPusher(
org.NewIDPOIDCConfigAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"clientid1",
"config1",
"issuer",
"authorization-endpoint",
"token-endpoint",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("secret"),
},
domain.OIDCMappingFieldEmail,
domain.OIDCMappingFieldEmail,
"scope",
),
),
},
uniqueConstraintsFromEventConstraint(idpconfig.NewAddIDPConfigNameUniqueConstraint("name1", "org1")),
org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
"name1",
domain.IDPConfigTypeOIDC,
domain.IDPConfigStylingTypeGoogle,
true,
),
org.NewIDPOIDCConfigAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"clientid1",
"config1",
"issuer",
"authorization-endpoint",
"token-endpoint",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("secret"),
},
domain.OIDCMappingFieldEmail,
domain.OIDCMappingFieldEmail,
"scope",
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "config1"),
@@ -167,29 +159,22 @@ func TestCommandSide_AddIDPConfig(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
"name1",
domain.IDPConfigTypeOIDC,
domain.IDPConfigStylingTypeGoogle,
false,
),
),
eventFromEventPusher(
org.NewIDPJWTConfigAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
"jwt-endpoint",
"issuer",
"keys-endpoint",
"auth",
),
),
},
uniqueConstraintsFromEventConstraint(idpconfig.NewAddIDPConfigNameUniqueConstraint("name1", "org1")),
org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
"name1",
domain.IDPConfigTypeOIDC,
domain.IDPConfigStylingTypeGoogle,
false,
),
org.NewIDPJWTConfigAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
"jwt-endpoint",
"issuer",
"keys-endpoint",
"auth",
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "config1"),
@@ -350,13 +335,7 @@ func TestCommandSide_ChangeIDPConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newIDPConfigChangedEvent(context.Background(), "org1", "config1", "name1", "name2", domain.IDPConfigStylingTypeUnspecified),
),
},
uniqueConstraintsFromEventConstraint(idpconfig.NewRemoveIDPConfigNameUniqueConstraint("name1", "org1")),
uniqueConstraintsFromEventConstraint(idpconfig.NewAddIDPConfigNameUniqueConstraint("name2", "org1")),
newIDPConfigChangedEvent(context.Background(), "org1", "config1", "name1", "name2", domain.IDPConfigStylingTypeUnspecified),
),
),
},
@@ -474,14 +453,11 @@ func TestCommands_RemoveIDPConfig(t *testing.T) {
),
),
expectPush(
eventPusherToEvents(
org.NewIDPConfigRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"idp1",
"name1",
),
org.NewIDPConfigRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"idp1",
"name1",
),
uniqueConstraintsFromEventConstraint(idpconfig.NewRemoveIDPConfigNameUniqueConstraint("name1", "org1")),
),
),
},
@@ -540,24 +516,20 @@ func TestCommands_RemoveIDPConfig(t *testing.T) {
),
),
expectPush(
eventPusherToEvents(
org.NewIDPConfigRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"idp1",
"name1",
),
org.NewIdentityProviderCascadeRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"idp1",
),
user.NewUserIDPLinkCascadeRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"idp1",
"id1",
),
org.NewIDPConfigRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"idp1",
"name1",
),
org.NewIdentityProviderCascadeRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"idp1",
),
user.NewUserIDPLinkCascadeRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"idp1",
"id1",
),
uniqueConstraintsFromEventConstraint(idpconfig.NewRemoveIDPConfigNameUniqueConstraint("name1", "org1")),
uniqueConstraintsFromEventConstraint(user.NewRemoveUserIDPLinkUniqueConstraint("idp1", "id1")),
),
),
},
+8 -13
View File
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/idpconfig"
"github.com/zitadel/zitadel/internal/repository/org"
@@ -211,18 +210,14 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newIDPJWTConfigChangedEvent(context.Background(),
"org1",
"config1",
"jwt-endpoint-changed",
"issuer-changed",
"keys-endpoint-changed",
"auth-changed",
),
),
},
newIDPJWTConfigChangedEvent(context.Background(),
"org1",
"config1",
"jwt-endpoint-changed",
"issuer-changed",
"keys-endpoint-changed",
"auth-changed",
),
),
),
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
+17 -22
View File
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/idpconfig"
"github.com/zitadel/zitadel/internal/repository/org"
@@ -241,27 +240,23 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newIDPOIDCConfigChangedEvent(context.Background(),
"org1",
"config1",
"clientid-changed",
"issuer-changed",
"authorization-endpoint-changed",
"token-endpoint-changed",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("secret-changed"),
},
domain.OIDCMappingFieldPreferredLoginName,
domain.OIDCMappingFieldPreferredLoginName,
[]string{"scope", "scope2"},
),
),
},
newIDPOIDCConfigChangedEvent(context.Background(),
"org1",
"config1",
"clientid-changed",
"issuer-changed",
"authorization-endpoint-changed",
"token-endpoint-changed",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("secret-changed"),
},
domain.OIDCMappingFieldPreferredLoginName,
domain.OIDCMappingFieldPreferredLoginName,
[]string{"scope", "scope2"},
),
),
),
secretCrypto: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
File diff suppressed because it is too large Load Diff
+19 -32
View File
@@ -12,9 +12,7 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/member"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/repository/user"
@@ -432,14 +430,11 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
),
expectFilter(),
expectPushFailed(errors.ThrowAlreadyExists(nil, "ERROR", "internal"),
[]*repository.Event{
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"user1",
[]string{"ORG_OWNER"}...,
)),
},
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("org1", "user1")),
org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"user1",
[]string{"ORG_OWNER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -481,14 +476,11 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"user1",
[]string{"ORG_OWNER"}...,
)),
},
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("org1", "user1")),
org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"user1",
[]string{"ORG_OWNER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -671,13 +663,11 @@ func TestCommandSide_ChangeOrgMember(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewMemberChangedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"user1",
[]string{"ORG_OWNER", "ORG_OWNER_VIEWER"}...,
)),
},
org.NewMemberChangedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"user1",
[]string{"ORG_OWNER", "ORG_OWNER_VIEWER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -818,13 +808,10 @@ func TestCommandSide_RemoveOrgMember(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewProjectMemberRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
)),
},
uniqueConstraintsFromEventConstraint(member.NewRemoveMemberUniqueConstraint("project1", "user1")),
project.NewProjectMemberRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
),
),
),
},
+27 -48
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/org"
)
@@ -95,15 +94,11 @@ func TestCommandSide_SetOrgMetadata(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
[]byte("value"),
),
),
},
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
[]byte("value"),
),
),
),
},
@@ -244,22 +239,16 @@ func TestCommandSide_BulkSetOrgMetadata(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
[]byte("value"),
),
),
eventFromEventPusher(
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key1",
[]byte("value1"),
),
),
},
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
[]byte("value"),
),
org.NewMetadataSetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key1",
[]byte("value1"),
),
),
),
},
@@ -399,14 +388,10 @@ func TestCommandSide_OrgRemoveMetadata(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewMetadataRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
},
org.NewMetadataRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
),
},
@@ -597,20 +582,14 @@ func TestCommandSide_BulkRemoveOrgMetadata(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewMetadataRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
eventFromEventPusher(
org.NewMetadataRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key1",
),
),
},
org.NewMetadataRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
org.NewMetadataRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key1",
),
),
),
},
+54 -94
View File
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -100,16 +99,12 @@ func TestCommandSide_AddDomainPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
),
),
},
org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
),
),
),
},
@@ -202,38 +197,26 @@ func TestCommandSide_AddDomainPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
),
),
eventFromEventPusher(
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"[email protected]",
"user1",
true,
user.UsernameChangedEventWithPolicyChange(),
),
),
eventFromEventPusher(
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user2", "org1").Aggregate,
"[email protected]",
"[email protected]",
true,
user.UsernameChangedEventWithPolicyChange(),
),
),
},
uniqueConstraintsFromEventConstraint(user.NewRemoveUsernameUniqueConstraint("[email protected]", "org1", false)),
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("user1", "org1", true)),
uniqueConstraintsFromEventConstraint(user.NewRemoveUsernameUniqueConstraint("[email protected]", "org1", false)),
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("[email protected]", "org1", true)),
org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
),
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"[email protected]",
"user1",
true,
user.UsernameChangedEventWithPolicyChange(),
),
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user2", "org1").Aggregate,
"[email protected]",
"[email protected]",
true,
user.UsernameChangedEventWithPolicyChange(),
),
),
),
},
@@ -371,14 +354,10 @@ func TestCommandSide_ChangeDomainPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDomainPolicyChangedEvent(context.Background(), "org1",
policy.ChangeValidateOrgDomains(false),
policy.ChangeSMTPSenderAddressMatchesInstanceDomain(false),
),
),
},
newDomainPolicyChangedEvent(context.Background(), "org1",
policy.ChangeValidateOrgDomains(false),
policy.ChangeSMTPSenderAddressMatchesInstanceDomain(false),
),
),
),
},
@@ -440,26 +419,18 @@ func TestCommandSide_ChangeDomainPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newDomainPolicyChangedEvent(context.Background(), "org1",
policy.ChangeUserLoginMustBeDomain(false),
policy.ChangeValidateOrgDomains(false),
policy.ChangeSMTPSenderAddressMatchesInstanceDomain(false),
),
),
eventFromEventPusher(
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"user1",
"[email protected]",
false,
user.UsernameChangedEventWithPolicyChange(),
),
),
},
uniqueConstraintsFromEventConstraint(user.NewRemoveUsernameUniqueConstraint("user1", "org1", true)),
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("[email protected]", "org1", false)),
newDomainPolicyChangedEvent(context.Background(), "org1",
policy.ChangeUserLoginMustBeDomain(false),
policy.ChangeValidateOrgDomains(false),
policy.ChangeSMTPSenderAddressMatchesInstanceDomain(false),
),
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"user1",
"[email protected]",
false,
user.UsernameChangedEventWithPolicyChange(),
),
),
),
},
@@ -570,12 +541,8 @@ func TestCommandSide_RemoveDomainPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewDomainPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewDomainPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
@@ -644,23 +611,16 @@ func TestCommandSide_RemoveDomainPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewDomainPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
eventFromEventPusher(
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"user1",
"[email protected]",
false,
user.UsernameChangedEventWithPolicyChange(),
),
),
},
uniqueConstraintsFromEventConstraint(user.NewRemoveUsernameUniqueConstraint("user1", "org1", true)),
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("[email protected]", "org1", false)),
org.NewDomainPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
),
user.NewUsernameChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"user1",
"[email protected]",
false,
user.UsernameChangedEventWithPolicyChange(),
),
),
),
},
+72 -129
View File
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -109,24 +108,20 @@ func TestCommandSide_AddLabelPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
true,
true,
true,
),
),
},
org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
"#ffffff",
true,
true,
true,
),
),
),
},
@@ -315,24 +310,20 @@ func TestCommandSide_ChangeLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newLabelPolicyChangedEvent(
context.Background(),
"org1",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
false,
false,
false),
),
},
newLabelPolicyChangedEvent(
context.Background(),
"org1",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
"#000000",
false,
false,
false),
),
),
},
@@ -464,12 +455,8 @@ func TestCommandSide_ActivateLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyActivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewLabelPolicyActivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
@@ -568,12 +555,8 @@ func TestCommandSide_RemoveLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewLabelPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
static: mock.NewMockStorage(gomock.NewController(t)).ExpectRemoveObjectsNoError(),
@@ -735,14 +718,10 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyLogoAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"logo",
),
),
},
org.NewLabelPolicyLogoAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"logo",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -869,14 +848,10 @@ func TestCommandSide_RemoveLogoLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyLogoRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
},
org.NewLabelPolicyLogoRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
),
},
@@ -1045,14 +1020,10 @@ func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyIconAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"icon",
),
),
},
org.NewLabelPolicyIconAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"icon",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -1177,14 +1148,10 @@ func TestCommandSide_RemoveIconLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyIconRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
},
org.NewLabelPolicyIconRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
),
},
@@ -1352,14 +1319,10 @@ func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"logo",
),
),
},
org.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"logo",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -1486,14 +1449,10 @@ func TestCommandSide_RemoveLogoDarkLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyLogoDarkRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
},
org.NewLabelPolicyLogoDarkRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
),
},
@@ -1662,14 +1621,10 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyIconDarkAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"icon",
),
),
},
org.NewLabelPolicyIconDarkAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"icon",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -1792,14 +1747,10 @@ func TestCommandSide_RemoveIconDarkLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyIconDarkRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
},
org.NewLabelPolicyIconDarkRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
),
},
@@ -1959,14 +1910,10 @@ func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyFontAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"font",
),
),
},
org.NewLabelPolicyFontAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"font",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -2089,14 +2036,10 @@ func TestCommandSide_RemoveFontLabelPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLabelPolicyFontRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
},
org.NewLabelPolicyFontRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"key",
),
),
),
},
+8 -21
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -87,15 +86,11 @@ func TestCommandSide_AddPasswordLockoutPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLockoutPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
10,
true,
),
),
},
org.NewLockoutPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
10,
true,
),
),
),
},
@@ -238,11 +233,7 @@ func TestCommandSide_ChangePasswordLockoutPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newPasswordLockoutPolicyChangedEvent(context.Background(), "org1", 5, false),
),
},
newPasswordLockoutPolicyChangedEvent(context.Background(), "org1", 5, false),
),
),
},
@@ -348,12 +339,8 @@ func TestCommandSide_RemovePasswordLockoutPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLockoutPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewLockoutPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
+140 -219
View File
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
@@ -107,30 +106,26 @@ func TestCommandSide_AddLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
domain.PasswordlessTypeAllowed,
"https://example.com/redirect",
time.Hour*1,
time.Hour*2,
time.Hour*3,
time.Hour*4,
time.Hour*5,
),
),
},
org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
domain.PasswordlessTypeAllowed,
"https://example.com/redirect",
time.Hour*1,
time.Hour*2,
time.Hour*3,
time.Hour*4,
time.Hour*5,
),
),
),
},
@@ -205,42 +200,34 @@ func TestCommandSide_AddLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
domain.PasswordlessTypeAllowed,
"https://example.com/redirect",
time.Hour*1,
time.Hour*2,
time.Hour*3,
time.Hour*4,
time.Hour*5,
),
),
eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeTOTP,
),
),
eventFromEventPusher(
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN,
),
),
},
org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
domain.PasswordlessTypeAllowed,
"https://example.com/redirect",
time.Hour*1,
time.Hour*2,
time.Hour*3,
time.Hour*4,
time.Hour*5,
),
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeTOTP,
),
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN,
),
),
),
},
@@ -336,37 +323,31 @@ func TestCommandSide_AddLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
domain.PasswordlessTypeAllowed,
"https://example.com/redirect",
time.Hour*1,
time.Hour*2,
time.Hour*3,
time.Hour*4,
time.Hour*5,
),
),
eventFromEventPusher(
org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
domain.IdentityProviderTypeSystem,
),
),
},
org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
domain.PasswordlessTypeAllowed,
"https://example.com/redirect",
time.Hour*1,
time.Hour*2,
time.Hour*3,
time.Hour*4,
time.Hour*5,
),
org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
domain.IdentityProviderTypeSystem,
),
),
),
},
@@ -561,30 +542,26 @@ func TestCommandSide_ChangeLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newLoginPolicyChangedEvent(context.Background(),
"org1",
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
domain.PasswordlessTypeNotAllowed,
"",
&duration10,
&duration20,
&duration30,
&duration40,
&duration50,
),
),
},
newLoginPolicyChangedEvent(context.Background(),
"org1",
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
domain.PasswordlessTypeNotAllowed,
"",
&duration10,
&duration20,
&duration30,
&duration40,
&duration50,
),
),
),
},
@@ -714,12 +691,8 @@ func TestCommandSide_RemoveLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewLoginPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
@@ -981,14 +954,10 @@ func TestCommandSide_AddIDPProviderLoginPolicy(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
domain.IdentityProviderTypeOrg),
),
},
org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
domain.IdentityProviderTypeOrg),
),
),
},
@@ -1247,13 +1216,9 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1"),
),
},
org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1"),
),
),
},
@@ -1311,13 +1276,9 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1"),
),
},
org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1"),
),
),
},
@@ -1390,18 +1351,14 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1"),
),
eventFromEventPusher(
user.NewUserIDPLinkCascadeRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"config1", "externaluser1")),
},
uniqueConstraintsFromEventConstraint(user.NewRemoveUserIDPLinkUniqueConstraint("config1", "externaluser1")),
org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"config1",
),
user.NewUserIDPLinkCascadeRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"config1", "externaluser1",
),
),
),
},
@@ -1527,13 +1484,9 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeTOTP),
),
},
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeTOTP),
),
),
},
@@ -1553,13 +1506,9 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPEmail),
),
},
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPEmail),
),
),
},
@@ -1579,13 +1528,9 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
},
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
),
},
@@ -1612,13 +1557,9 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
},
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
),
},
@@ -1821,13 +1762,9 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeTOTP),
),
},
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeTOTP),
),
),
},
@@ -1856,13 +1793,9 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPEmail),
),
},
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPEmail),
),
),
},
@@ -1891,13 +1824,9 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
},
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTPSMS),
),
),
},
@@ -2009,13 +1938,9 @@ func TestCommandSide_AddMultiFactorLoginPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN),
),
},
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN),
),
),
},
@@ -2158,13 +2083,9 @@ func TestCommandSide_RemoveMultiFactorLoginPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN),
),
},
org.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN),
),
),
},
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -84,14 +83,10 @@ func TestCommandSide_AddMailTemplate(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewMailTemplateAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
[]byte("template"),
),
),
},
org.NewMailTemplateAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
[]byte("template"),
),
),
),
},
@@ -227,11 +222,7 @@ func TestCommandSide_ChangeMailTemplate(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newMailTemplateChangedEvent(context.Background(), "org1", "template2"),
),
},
newMailTemplateChangedEvent(context.Background(), "org1", "template2"),
),
),
},
@@ -334,12 +325,8 @@ func TestCommandSide_RemoveMailTemplate(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewMailTemplateRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewMailTemplateRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
)
@@ -80,14 +79,10 @@ func TestCommandSide_AddNotificationPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewNotificationPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
),
),
},
org.NewNotificationPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
),
),
),
},
@@ -109,14 +104,10 @@ func TestCommandSide_AddNotificationPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewNotificationPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
false,
),
),
},
org.NewNotificationPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
false,
),
),
),
},
@@ -240,11 +231,7 @@ func TestCommandSide_ChangeNotificationPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newNotificationPolicyChangedEvent(context.Background(), "org1", false),
),
},
newNotificationPolicyChangedEvent(context.Background(), "org1", false),
),
),
},
@@ -341,12 +328,8 @@ func TestCommandSide_RemoveNotificationPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewNotificationPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewNotificationPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -87,15 +86,11 @@ func TestCommandSide_AddPasswordAgePolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewPasswordAgePolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
10,
365,
),
),
},
org.NewPasswordAgePolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
10,
365,
),
),
),
},
@@ -238,11 +233,7 @@ func TestCommandSide_ChangePasswordAgePolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newPasswordAgePolicyChangedEvent(context.Background(), "org1", 150, 5),
),
},
newPasswordAgePolicyChangedEvent(context.Background(), "org1", 150, 5),
),
),
},
@@ -348,12 +339,8 @@ func TestCommandSide_RemovePasswordAgePolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewPasswordAgePolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewPasswordAgePolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -93,15 +92,11 @@ func TestCommandSide_AddPasswordComplexityPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
8,
true, true, true, true,
),
),
},
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
8,
true, true, true, true,
),
),
),
},
@@ -259,11 +254,7 @@ func TestCommandSide_ChangePasswordComplexityPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newPasswordComplexityPolicyChangedEvent(context.Background(), "org1", 10, false, false, false, false),
),
},
newPasswordComplexityPolicyChangedEvent(context.Background(), "org1", 10, false, false, false, false),
),
),
},
@@ -375,12 +366,8 @@ func TestCommandSide_RemovePasswordComplexityPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewPasswordComplexityPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewPasswordComplexityPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
+18 -39
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/policy"
@@ -93,17 +92,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"TOSLink",
"PrivacyLink",
"HelpLink",
"[email protected]",
),
),
},
org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"TOSLink",
"PrivacyLink",
"HelpLink",
"[email protected]",
),
),
),
},
@@ -158,17 +153,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"",
"",
"",
"",
),
),
},
org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
"",
"",
"",
"",
),
),
),
},
@@ -341,11 +332,7 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newPrivacyPolicyChangedEvent(context.Background(), "org1", "TOSLinkChange", "PrivacyLinkChange", "HelpLinkChange", "[email protected]"),
),
},
newPrivacyPolicyChangedEvent(context.Background(), "org1", "TOSLinkChange", "PrivacyLinkChange", "HelpLinkChange", "[email protected]"),
),
),
},
@@ -389,11 +376,7 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newPrivacyPolicyChangedEvent(context.Background(), "org1", "", "", "", ""),
),
},
newPrivacyPolicyChangedEvent(context.Background(), "org1", "", "", "", ""),
),
),
},
@@ -505,12 +488,8 @@ func TestCommandSide_RemovePrivacyPolicy(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewPrivacyPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
},
org.NewPrivacyPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate),
),
),
},
+254 -317
View File
@@ -15,11 +15,9 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/repository/member"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/repository/user"
@@ -196,31 +194,31 @@ func TestCommandSide_AddOrg(t *testing.T) {
),
expectFilterOrgMemberNotFound(),
expectPushFailed(errors.ThrowAlreadyExists(nil, "id", "internal"),
[]*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"Org")),
eventFromEventPusher(org.NewDomainAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain")),
eventFromEventPusher(org.NewDomainVerifiedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain")),
eventFromEventPusher(org.NewDomainPrimarySetEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain")),
eventFromEventPusher(org.NewMemberAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"user1", domain.RoleOrgOwner)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("org.iam-domain")),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("org2", "user1")),
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"Org",
),
org.NewDomainAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewDomainVerifiedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewDomainPrimarySetEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewMemberAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"user1", domain.RoleOrgOwner,
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
@@ -264,31 +262,31 @@ func TestCommandSide_AddOrg(t *testing.T) {
),
expectFilterOrgMemberNotFound(),
expectPushFailed(errors.ThrowInternal(nil, "id", "internal"),
[]*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"Org")),
eventFromEventPusher(org.NewDomainAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain")),
eventFromEventPusher(org.NewDomainVerifiedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain")),
eventFromEventPusher(org.NewDomainPrimarySetEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain")),
eventFromEventPusher(org.NewMemberAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"user1", domain.RoleOrgOwner)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("org.iam-domain")),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("org2", "user1")),
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"Org",
),
org.NewDomainAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewDomainVerifiedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewDomainPrimarySetEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewMemberAddedEvent(
context.Background(),
&org.NewAggregate("org2").Aggregate,
"user1", domain.RoleOrgOwner,
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
@@ -332,31 +330,26 @@ func TestCommandSide_AddOrg(t *testing.T) {
),
expectFilterOrgMemberNotFound(),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"Org",
)),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate, "org.iam-domain",
)),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"user1",
domain.RoleOrgOwner,
)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("org.iam-domain")),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("org2", "user1")),
org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"Org",
),
org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate, "org.iam-domain",
),
org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"user1",
domain.RoleOrgOwner,
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
@@ -408,31 +401,26 @@ func TestCommandSide_AddOrg(t *testing.T) {
),
expectFilterOrgMemberNotFound(),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"Org",
)),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate, "org.iam-domain",
)),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"user1",
domain.RoleOrgOwner,
)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("org.iam-domain")),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("org2", "user1")),
org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"Org",
),
org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate, "org.iam-domain",
),
org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"org.iam-domain",
),
org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org2").Aggregate,
"user1",
domain.RoleOrgOwner,
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
@@ -586,12 +574,9 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
expectFilter(),
expectPushFailed(
errors.ThrowInternal(nil, "id", "message"),
[]*repository.Event{
eventFromEventPusher(org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org", "neworg")),
},
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")),
org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org", "neworg",
),
),
),
},
@@ -634,20 +619,18 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org", "neworg")),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org.zitadel.ch", true)),
},
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("neworg.zitadel.ch")),
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgDomainUniqueConstraint("org.zitadel.ch")),
org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org", "neworg",
),
org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
),
org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
),
org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org.zitadel.ch", true,
),
),
),
},
@@ -693,22 +676,21 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org", "neworg")),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org.zitadel.ch", true)),
},
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("neworg.zitadel.ch")),
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgDomainUniqueConstraint("org.zitadel.ch")),
org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org", "neworg",
),
org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
),
org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
),
org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
),
org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate, "org.zitadel.ch", true,
),
),
),
},
@@ -812,10 +794,9 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
),
expectPushFailed(
errors.ThrowInternal(nil, "id", "message"),
[]*repository.Event{
eventFromEventPusher(org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate)),
},
org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
),
),
),
},
@@ -840,11 +821,9 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
)),
},
org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
),
),
),
},
@@ -871,6 +850,7 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
})
}
}
func TestCommandSide_ReactivateOrg(t *testing.T) {
type fields struct {
eventstore *eventstore.Eventstore
@@ -948,11 +928,9 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
),
expectPushFailed(
errors.ThrowInternal(nil, "id", "message"),
[]*repository.Event{
eventFromEventPusher(org.NewOrgReactivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
)),
},
org.NewOrgReactivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
),
),
),
},
@@ -981,10 +959,9 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgReactivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate)),
},
org.NewOrgReactivatedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
),
),
),
},
@@ -1117,14 +1094,9 @@ func TestCommandSide_RemoveOrg(t *testing.T) {
expectFilter(),
expectPushFailed(
errors.ThrowInternal(nil, "id", "message"),
[]*repository.Event{
eventFromEventPusher(
org.NewOrgRemovedEvent(
context.Background(), &org.NewAggregate("org1").Aggregate, "org", []string{}, false, []string{}, []*domain.UserIDPLink{}, []string{},
),
),
},
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
org.NewOrgRemovedEvent(
context.Background(), &org.NewAggregate("org1").Aggregate, "org", []string{}, false, []string{}, []*domain.UserIDPLink{}, []string{},
),
),
),
},
@@ -1164,14 +1136,9 @@ func TestCommandSide_RemoveOrg(t *testing.T) {
expectFilter(),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewOrgRemovedEvent(
context.Background(), &org.NewAggregate("org1").Aggregate, "org", []string{}, false, []string{}, []*domain.UserIDPLink{}, []string{},
),
),
},
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
org.NewOrgRemovedEvent(
context.Background(), &org.NewAggregate("org1").Aggregate, "org", []string{}, false, []string{}, []*domain.UserIDPLink{}, []string{},
),
),
),
},
@@ -1199,7 +1166,7 @@ func TestCommandSide_RemoveOrg(t *testing.T) {
eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
false,
true,
true,
),
@@ -1217,7 +1184,7 @@ func TestCommandSide_RemoveOrg(t *testing.T) {
language.German,
domain.GenderMale,
"email1",
true,
false,
),
), eventFromEventPusher(
user.NewMachineAddedEvent(context.Background(),
@@ -1225,7 +1192,7 @@ func TestCommandSide_RemoveOrg(t *testing.T) {
"user2",
"name",
"description",
true,
false,
domain.OIDCTokenTypeBearer,
),
),
@@ -1255,26 +1222,13 @@ func TestCommandSide_RemoveOrg(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
org.NewOrgRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "org",
[]string{"user1", "user2"},
false,
[]string{"domain1", "domain2"},
[]*domain.UserIDPLink{{IDPConfigID: "config1", ExternalUserID: "id1", DisplayName: "display1"}, {IDPConfigID: "config2", ExternalUserID: "id2", DisplayName: "display2"}},
[]string{"entity1", "entity2"},
),
),
},
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
uniqueConstraintsFromEventConstraint(user.NewRemoveUsernameUniqueConstraint("user1", "org1", true)),
uniqueConstraintsFromEventConstraint(user.NewRemoveUsernameUniqueConstraint("user2", "org1", true)),
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgDomainUniqueConstraint("domain1")),
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgDomainUniqueConstraint("domain2")),
uniqueConstraintsFromEventConstraint(user.NewRemoveUserIDPLinkUniqueConstraint("config1", "id1")),
uniqueConstraintsFromEventConstraint(user.NewRemoveUserIDPLinkUniqueConstraint("config2", "id2")),
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("entity1")),
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("entity2")),
org.NewOrgRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "org",
[]string{"user1", "user2"},
false,
[]string{"domain1", "domain2"},
[]*domain.UserIDPLink{{IDPConfigID: "config1", ExternalUserID: "id1", DisplayName: "display1"}, {IDPConfigID: "config2", ExternalUserID: "id2", DisplayName: "display2"}},
[]string{"entity1", "entity2"},
),
),
),
},
@@ -1428,64 +1382,58 @@ func TestCommandSide_SetUpOrg(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"Org",
)),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
)),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"username",
"firstname",
"lastname",
"",
"firstname lastname",
language.English,
domain.GenderUnspecified,
"[email protected]",
true,
),
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"Org",
)),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
)),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"username",
"firstname",
"lastname",
"",
"firstname lastname",
language.English,
domain.GenderUnspecified,
"[email protected]",
true,
),
eventFromEventPusher(
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
),
),
eventFromEventPusher(
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
),
eventFromEventPusher(
user.NewHumanInitialCodeAddedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("userinit"),
},
1*time.Hour,
),
),
eventFromEventPusher(
user.NewHumanInitialCodeAddedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("userinit"),
},
1*time.Hour,
),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"userID",
domain.RoleOrgOwner,
)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("org.iam-domain")),
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("username", "orgID", true)),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("orgID", "userID")),
),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"userID",
domain.RoleOrgOwner,
)),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID", "userID"),
@@ -1547,31 +1495,26 @@ func TestCommandSide_SetUpOrg(t *testing.T) {
),
expectFilter(), // org member check
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"Org",
)),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
)),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"userID",
domain.RoleOrgOwner,
)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("org.iam-domain")),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("orgID", "userID")),
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"Org",
)),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
)),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"userID",
domain.RoleOrgOwner,
)),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID"),
@@ -1632,50 +1575,44 @@ func TestCommandSide_SetUpOrg(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"Org",
)),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
)),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(
user.NewMachineAddedEvent(context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"username",
"name",
"description",
true,
domain.OIDCTokenTypeBearer,
),
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"Org",
)),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
)),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"org.iam-domain",
)),
eventFromEventPusher(
user.NewMachineAddedEvent(context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"username",
"name",
"description",
true,
domain.OIDCTokenTypeBearer,
),
eventFromEventPusher(
user.NewPersonalAccessTokenAddedEvent(context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
testNow.Add(time.Hour),
[]string{openid.ScopeOpenID},
),
),
eventFromEventPusher(
user.NewPersonalAccessTokenAddedEvent(context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
testNow.Add(time.Hour),
[]string{openid.ScopeOpenID},
),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"userID",
domain.RoleOrgOwner,
)),
},
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgDomainUniqueConstraint("org.iam-domain")),
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("username", "orgID", true)),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("orgID", "userID")),
),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("orgID").Aggregate,
"userID",
domain.RoleOrgOwner,
)),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID", "userID", "tokenID"),
+2 -2
View File
@@ -167,10 +167,10 @@ type testCommand struct {
eventstore.BaseEvent
}
func (c *testCommand) Data() interface{} {
func (c *testCommand) Payload() interface{} {
return nil
}
func (c *testCommand) UniqueConstraints() []*eventstore.EventUniqueConstraint {
func (c *testCommand) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
+1 -1
View File
@@ -282,7 +282,7 @@ func (c *Commands) RemoveProject(ctx context.Context, projectID, resourceOwner s
return nil, err
}
uniqueConstraints := make([]*eventstore.EventUniqueConstraint, len(samlEntityIDsAgg.EntityIDs))
uniqueConstraints := make([]*eventstore.UniqueConstraint, len(samlEntityIDsAgg.EntityIDs))
for i, entityID := range samlEntityIDsAgg.EntityIDs {
uniqueConstraints[i] = project.NewRemoveSAMLConfigEntityIDUniqueConstraint(entityID.EntityID)
}
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -248,29 +247,22 @@ func TestCommandSide_AddAPIApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
),
eventFromEventPusher(
project.NewAPIConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"client1@project",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
domain.APIAuthMethodTypeBasic),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddApplicationUniqueConstraint("app", "project1")),
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
project.NewAPIConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"client1@project",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
domain.APIAuthMethodTypeBasic),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "app1", "client1"),
@@ -316,24 +308,17 @@ func TestCommandSide_AddAPIApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
),
eventFromEventPusher(
project.NewAPIConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"client1@project",
nil,
domain.APIAuthMethodTypePrivateKeyJWT),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddApplicationUniqueConstraint("app", "project1")),
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
project.NewAPIConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"client1@project",
nil,
domain.APIAuthMethodTypePrivateKeyJWT),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "app1", "client1"),
@@ -540,15 +525,11 @@ func TestCommandSide_ChangeAPIApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newAPIAppChangedEvent(context.Background(),
"app1",
"project1",
"org1",
domain.APIAuthMethodTypePrivateKeyJWT),
),
},
newAPIAppChangedEvent(context.Background(),
"app1",
"project1",
"org1",
domain.APIAuthMethodTypePrivateKeyJWT),
),
),
},
@@ -698,19 +679,16 @@ func TestCommandSide_ChangeAPIApplicationSecret(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewAPIConfigSecretChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
}),
),
},
project.NewAPIConfigSecretChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
),
),
),
},
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -294,44 +293,37 @@ func TestCommandSide_AddOIDCApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
),
eventFromEventPusher(
project.NewOIDCConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
domain.OIDCVersionV1,
"app1",
"client1@project",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
[]string{"https://test.ch"},
[]domain.OIDCResponseType{domain.OIDCResponseTypeCode},
[]domain.OIDCGrantType{domain.OIDCGrantTypeAuthorizationCode},
domain.OIDCApplicationTypeWeb,
domain.OIDCAuthMethodTypePost,
[]string{"https://test.ch/logout"},
true,
domain.OIDCTokenTypeBearer,
true,
true,
true,
time.Second*1,
[]string{"https://sub.test.ch"},
true,
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddApplicationUniqueConstraint("app", "project1")),
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
project.NewOIDCConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
domain.OIDCVersionV1,
"app1",
"client1@project",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
[]string{"https://test.ch"},
[]domain.OIDCResponseType{domain.OIDCResponseTypeCode},
[]domain.OIDCGrantType{domain.OIDCGrantTypeAuthorizationCode},
domain.OIDCApplicationTypeWeb,
domain.OIDCAuthMethodTypePost,
[]string{"https://test.ch/logout"},
true,
domain.OIDCTokenTypeBearer,
true,
true,
true,
time.Second*1,
[]string{"https://sub.test.ch"},
true,
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "app1", "client1"),
@@ -643,14 +635,10 @@ func TestCommandSide_ChangeOIDCApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newOIDCAppChangedEvent(context.Background(),
"app1",
"project1",
"org1"),
),
},
newOIDCAppChangedEvent(context.Background(),
"app1",
"project1",
"org1"),
),
),
},
@@ -844,19 +832,16 @@ func TestCommandSide_ChangeOIDCApplicationSecret(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewOIDCConfigSecretChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
}),
),
},
project.NewOIDCConfigSecretChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
),
),
),
},
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -185,26 +184,18 @@ func TestCommandSide_AddSAMLApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
),
eventFromEventPusher(
project.NewSAMLConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"https://test.com/saml/metadata",
testMetadata,
"",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddApplicationUniqueConstraint("app", "project1")),
uniqueConstraintsFromEventConstraint(project.NewAddSAMLConfigEntityIDUniqueConstraint("https://test.com/saml/metadata")),
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
project.NewSAMLConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"https://test.com/saml/metadata",
testMetadata,
"",
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "app1"),
@@ -251,26 +242,18 @@ func TestCommandSide_AddSAMLApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
),
eventFromEventPusher(
project.NewSAMLConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"https://test.com/saml/metadata",
testMetadata,
"http://localhost:8080/saml/metadata",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddApplicationUniqueConstraint("app", "project1")),
uniqueConstraintsFromEventConstraint(project.NewAddSAMLConfigEntityIDUniqueConstraint("https://test.com/saml/metadata")),
project.NewApplicationAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
),
project.NewSAMLConfigAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"https://test.com/saml/metadata",
testMetadata,
"http://localhost:8080/saml/metadata",
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "app1"),
@@ -584,20 +567,14 @@ func TestCommandSide_ChangeSAMLApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newSAMLAppChangedEventMetadataURL(context.Background(),
"app1",
"project1",
"org1",
"https://test.com/saml/metadata",
"https://test2.com/saml/metadata",
testMetadataChangedEntityID,
),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test.com/saml/metadata")),
uniqueConstraintsFromEventConstraint(project.NewAddSAMLConfigEntityIDUniqueConstraint("https://test2.com/saml/metadata")),
newSAMLAppChangedEventMetadataURL(context.Background(),
"app1",
"project1",
"org1",
"https://test.com/saml/metadata",
"https://test2.com/saml/metadata",
testMetadataChangedEntityID,
),
),
),
httpClient: newTestClient(http.StatusOK, testMetadataChangedEntityID),
@@ -656,20 +633,14 @@ func TestCommandSide_ChangeSAMLApplication(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newSAMLAppChangedEventMetadata(context.Background(),
"app1",
"project1",
"org1",
"https://test.com/saml/metadata",
"https://test2.com/saml/metadata",
testMetadataChangedEntityID,
),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test.com/saml/metadata")),
uniqueConstraintsFromEventConstraint(project.NewAddSAMLConfigEntityIDUniqueConstraint("https://test2.com/saml/metadata")),
newSAMLAppChangedEventMetadata(context.Background(),
"app1",
"project1",
"org1",
"https://test.com/saml/metadata",
"https://test2.com/saml/metadata",
testMetadataChangedEntityID,
),
),
),
httpClient: nil,
+26 -42
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/project"
)
@@ -153,16 +152,12 @@ func TestCommandSide_ChangeApplication(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewApplicationChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
"app changed",
)),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveApplicationUniqueConstraint("app", "project1")),
uniqueConstraintsFromEventConstraint(project.NewAddApplicationUniqueConstraint("app changed", "project1")),
project.NewApplicationChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
"app changed",
),
),
),
},
@@ -314,12 +309,10 @@ func TestCommandSide_DeactivateApplication(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewApplicationDeactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
)),
},
project.NewApplicationDeactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
),
),
),
},
@@ -468,12 +461,10 @@ func TestCommandSide_ReactivateApplication(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewApplicationReactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
)),
},
project.NewApplicationReactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
),
),
),
},
@@ -608,16 +599,12 @@ func TestCommandSide_RemoveApplication(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewApplicationRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
"https://test.com/saml/metadata",
)),
}, /**/
uniqueConstraintsFromEventConstraint(project.NewRemoveApplicationUniqueConstraint("app", "project1")),
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test.com/saml/metadata")),
project.NewApplicationRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
"https://test.com/saml/metadata",
),
),
),
},
@@ -648,15 +635,12 @@ func TestCommandSide_RemoveApplication(t *testing.T) {
// app is not saml, or no saml config available
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewApplicationRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
"",
)),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveApplicationUniqueConstraint("app", "project1")),
project.NewApplicationRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"app1",
"app",
"",
),
),
),
},
+23 -35
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/repository/user"
@@ -179,15 +178,12 @@ func TestCommandSide_AddProjectGrantMember(t *testing.T) {
),
expectFilter(),
expectPushFailed(caos_errs.ThrowAlreadyExists(nil, "ERROR", "internal"),
[]*repository.Event{
eventFromEventPusher(project.NewProjectGrantMemberAddedEvent(context.Background(),
&project.NewAggregate("project1", "").Aggregate,
"user1",
"projectgrant1",
[]string{"PROJECT_GRANT_OWNER"}...,
)),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectGrantMemberUniqueConstraint("project1", "user1", "projectgrant1")),
project.NewProjectGrantMemberAddedEvent(context.Background(),
&project.NewAggregate("project1", "").Aggregate,
"user1",
"projectgrant1",
[]string{"PROJECT_GRANT_OWNER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -234,15 +230,12 @@ func TestCommandSide_AddProjectGrantMember(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewProjectGrantMemberAddedEvent(context.Background(),
&project.NewAggregate("project1", "").Aggregate,
"user1",
"projectgrant1",
[]string{"PROJECT_GRANT_OWNER"}...,
)),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectGrantMemberUniqueConstraint("project1", "user1", "projectgrant1")),
project.NewProjectGrantMemberAddedEvent(context.Background(),
&project.NewAggregate("project1", "").Aggregate,
"user1",
"projectgrant1",
[]string{"PROJECT_GRANT_OWNER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -435,14 +428,12 @@ func TestCommandSide_ChangeProjectGrantMember(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewProjectGrantMemberChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
"projectgrant1",
[]string{"PROJECT_GRANT_OWNER", "PROJECT_GRANT_VIEWER"}...,
)),
},
project.NewProjectGrantMemberChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
"projectgrant1",
[]string{"PROJECT_GRANT_OWNER", "PROJECT_GRANT_VIEWER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -603,14 +594,11 @@ func TestCommandSide_RemoveProjectGrantMember(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewProjectGrantMemberRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
"projectgrant1",
)),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectGrantMemberUniqueConstraint("project1", "user1", "projectgrant1")),
project.NewProjectGrantMemberRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
"projectgrant1",
),
),
),
},
+54 -78
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -176,15 +175,12 @@ func TestCommandSide_AddProjectGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
"grantedorg1",
[]string{"key1"},
)),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectGrantUniqueConstraint("grantedorg1", "project1")),
project.NewGrantAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
"grantedorg1",
[]string{"key1"},
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "projectgrant1"),
@@ -513,13 +509,11 @@ func TestCommandSide_ChangeProjectGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
[]string{"key1", "key2"},
)),
},
project.NewGrantChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
[]string{"key1", "key2"},
),
),
),
},
@@ -594,13 +588,11 @@ func TestCommandSide_ChangeProjectGrant(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
[]string{"key1"},
)),
},
project.NewGrantChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
[]string{"key1"},
),
),
),
},
@@ -685,17 +677,15 @@ func TestCommandSide_ChangeProjectGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
[]string{"key1"},
)),
eventFromEventPusher(usergrant.NewUserGrantCascadeChangedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
[]string{"key1"},
)),
},
project.NewGrantChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
[]string{"key1"},
),
usergrant.NewUserGrantCascadeChangedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
[]string{"key1"},
),
),
),
},
@@ -903,12 +893,10 @@ func TestCommandSide_DeactivateProjectGrant(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantDeactivateEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
)),
},
project.NewGrantDeactivateEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
),
),
),
},
@@ -1102,12 +1090,10 @@ func TestCommandSide_ReactivateProjectGrant(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantReactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
)),
},
project.NewGrantReactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
),
),
),
},
@@ -1264,14 +1250,11 @@ func TestCommandSide_RemoveProjectGrant(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
"grantedorg1",
)),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectGrantUniqueConstraint("grantedorg1", "project1")),
project.NewGrantRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
"grantedorg1",
),
),
),
},
@@ -1311,14 +1294,11 @@ func TestCommandSide_RemoveProjectGrant(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
"grantedorg1",
)),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectGrantUniqueConstraint("grantedorg1", "project1")),
project.NewGrantRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
"grantedorg1",
),
),
),
},
@@ -1365,21 +1345,17 @@ func TestCommandSide_RemoveProjectGrant(t *testing.T) {
"projectgrant1",
[]string{"key1"}))),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewGrantRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
"grantedorg1",
)),
eventFromEventPusher(usergrant.NewUserGrantCascadeRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"projectgrant1",
)),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectGrantUniqueConstraint("grantedorg1", "project1")),
uniqueConstraintsFromEventConstraint(usergrant.NewRemoveUserGrantUniqueConstraint("org1", "user1", "project1", "projectgrant1")),
project.NewGrantRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
"grantedorg1",
),
usergrant.NewUserGrantCascadeRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"projectgrant1",
),
),
),
},
+19 -32
View File
@@ -9,9 +9,7 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/member"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/repository/user"
"golang.org/x/text/language"
@@ -181,14 +179,11 @@ func TestCommandSide_AddProjectMember(t *testing.T) {
),
expectFilter(),
expectPushFailed(caos_errs.ThrowAlreadyExists(nil, "ERROR", "internal"),
[]*repository.Event{
eventFromEventPusher(project.NewProjectMemberAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{"PROJECT_OWNER"}...,
)),
},
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("project1", "user1")),
project.NewProjectMemberAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{"PROJECT_OWNER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -235,14 +230,11 @@ func TestCommandSide_AddProjectMember(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewProjectMemberAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{"PROJECT_OWNER"}...,
)),
},
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("project1", "user1")),
project.NewProjectMemberAddedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{"PROJECT_OWNER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -435,13 +427,11 @@ func TestCommandSide_ChangeProjectMember(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewProjectMemberChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{"PROJECT_OWNER", "PROJECT_VIEWER"}...,
)),
},
project.NewProjectMemberChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{"PROJECT_OWNER", "PROJECT_VIEWER"}...,
),
),
),
zitadelRoles: []authz.RoleMapping{
@@ -583,13 +573,10 @@ func TestCommandSide_RemoveProjectMember(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewProjectMemberRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
)),
},
uniqueConstraintsFromEventConstraint(member.NewRemoveMemberUniqueConstraint("project1", "user1")),
project.NewProjectMemberRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
),
),
),
},
+72 -126
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/repository/usergrant"
@@ -115,17 +114,13 @@ func TestCommandSide_AddProjectRole(t *testing.T) {
),
),
expectPushFailed(caos_errs.ThrowAlreadyExists(nil, "id", "internal"),
[]*repository.Event{
eventFromEventPusher(project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
"key",
"group",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectRoleUniqueConstraint("key1", "project1")),
project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
"key",
"group",
),
),
),
},
@@ -160,17 +155,13 @@ func TestCommandSide_AddProjectRole(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
"key",
"group",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectRoleUniqueConstraint("key1", "project1")),
project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
"key",
"group",
),
),
),
},
@@ -325,26 +316,20 @@ func TestCommandSide_BulkAddProjectRole(t *testing.T) {
),
),
expectPushFailed(caos_errs.ThrowAlreadyExists(nil, "id", "internal"),
[]*repository.Event{
eventFromEventPusher(project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
"key",
"group",
),
),
eventFromEventPusher(project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key2",
"key2",
"group",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectRoleUniqueConstraint("key1", "project1")),
uniqueConstraintsFromEventConstraint(project.NewAddProjectRoleUniqueConstraint("key2", "project1")),
project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
"key",
"group",
),
project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key2",
"key2",
"group",
),
),
),
},
@@ -384,26 +369,20 @@ func TestCommandSide_BulkAddProjectRole(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
"key",
"group",
),
),
eventFromEventPusher(project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key2",
"key2",
"group",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectRoleUniqueConstraint("key1", "project1")),
uniqueConstraintsFromEventConstraint(project.NewAddProjectRoleUniqueConstraint("key2", "project1")),
project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
"key",
"group",
),
project.NewRoleAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key2",
"key2",
"group",
),
),
),
},
@@ -641,11 +620,7 @@ func TestCommandSide_ChangeProjectRole(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newRoleChangedEvent(context.Background(), "project1", "org1", "key1", "keychanged", "groupchanged"),
),
},
newRoleChangedEvent(context.Background(), "project1", "org1", "key1", "keychanged", "groupchanged"),
),
),
},
@@ -815,15 +790,10 @@ func TestCommandSide_RemoveProjectRole(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectRoleUniqueConstraint("key1", "project1")),
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
),
),
},
@@ -856,15 +826,10 @@ func TestCommandSide_RemoveProjectRole(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectRoleUniqueConstraint("key1", "project1")),
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
),
),
},
@@ -907,22 +872,15 @@ func TestCommandSide_RemoveProjectRole(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
),
eventFromEventPusher(
project.NewGrantCascadeChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
[]string{},
),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectRoleUniqueConstraint("key1", "project1")),
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
project.NewGrantCascadeChangedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"projectgrant1",
[]string{},
),
),
),
},
@@ -956,15 +914,10 @@ func TestCommandSide_RemoveProjectRole(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectRoleUniqueConstraint("key1", "project1")),
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
),
),
},
@@ -1006,21 +959,14 @@ func TestCommandSide_RemoveProjectRole(t *testing.T) {
[]string{"key1"})),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
),
eventFromEventPusher(
usergrant.NewUserGrantCascadeChangedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
[]string{},
),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectRoleUniqueConstraint("key1", "project1")),
project.NewRoleRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"key1",
),
usergrant.NewUserGrantCascadeChangedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
[]string{},
),
),
),
},
+68 -215
View File
@@ -9,11 +9,9 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/repository/member"
"github.com/zitadel/zitadel/internal/repository/project"
)
@@ -60,24 +58,18 @@ func TestCommandSide_AddProject(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectPushFailed(errors.ThrowAlreadyExists(nil, "ERROR", "internl"),
[]*repository.Event{
eventFromEventPusher(project.NewProjectAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project", true, true, true,
domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
),
),
eventFromEventPusher(project.NewProjectMemberAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{domain.RoleProjectOwner}...,
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectNameUniqueConstraint("project", "org1")),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("project1", "user1")),
project.NewProjectAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project", true, true, true,
domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
),
project.NewProjectMemberAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{domain.RoleProjectOwner}...,
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "project1"),
@@ -104,24 +96,18 @@ func TestCommandSide_AddProject(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectPush(
[]*repository.Event{
eventFromEventPusher(project.NewProjectAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project", true, true, true,
domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
),
),
eventFromEventPusher(project.NewProjectMemberAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{domain.RoleProjectOwner}...,
),
),
},
uniqueConstraintsFromEventConstraint(project.NewAddProjectNameUniqueConstraint("project", "org1")),
uniqueConstraintsFromEventConstraint(member.NewAddMemberUniqueConstraint("project1", "user1")),
project.NewProjectAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project", true, true, true,
domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
),
project.NewProjectMemberAddedEvent(
context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"user1",
[]string{domain.RoleProjectOwner}...,
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "project1"),
@@ -334,21 +320,16 @@ func TestCommandSide_ChangeProject(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newProjectChangedEvent(context.Background(),
"project1",
"org1",
"project",
"project-new",
false,
false,
false,
domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectNameUniqueConstraint("project", "org1")),
uniqueConstraintsFromEventConstraint(project.NewAddProjectNameUniqueConstraint("project-new", "org1")),
newProjectChangedEvent(context.Background(),
"project1",
"org1",
"project",
"project-new",
false,
false,
false,
domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy,
),
),
),
},
@@ -394,19 +375,16 @@ func TestCommandSide_ChangeProject(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newProjectChangedEvent(context.Background(),
"project1",
"org1",
"project",
"",
false,
false,
false,
domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy),
),
},
newProjectChangedEvent(context.Background(),
"project1",
"org1",
"",
"",
false,
false,
false,
domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy,
),
),
),
},
@@ -598,12 +576,8 @@ func TestCommandSide_DeactivateProject(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewProjectDeactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate),
),
},
project.NewProjectDeactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate),
),
),
},
@@ -778,12 +752,8 @@ func TestCommandSide_ReactivateProject(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewProjectReactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate),
),
},
project.NewProjectReactivatedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate),
),
),
},
@@ -932,15 +902,10 @@ func TestCommandSide_RemoveProject(t *testing.T) {
// no saml application events
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewProjectRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project",
nil),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectNameUniqueConstraint("project", "org1")),
project.NewProjectRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project",
nil),
),
),
},
@@ -985,18 +950,13 @@ func TestCommandSide_RemoveProject(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewProjectRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project",
[]*eventstore.EventUniqueConstraint{
project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test.com/saml/metadata"),
}),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectNameUniqueConstraint("project", "org1")),
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test.com/saml/metadata")),
project.NewProjectRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project",
[]*eventstore.UniqueConstraint{
project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test.com/saml/metadata"),
},
),
),
),
},
@@ -1069,22 +1029,15 @@ func TestCommandSide_RemoveProject(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
project.NewProjectRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project",
[]*eventstore.EventUniqueConstraint{
project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test1.com/saml/metadata"),
project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test2.com/saml/metadata"),
project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test3.com/saml/metadata"),
}),
),
},
uniqueConstraintsFromEventConstraint(project.NewRemoveProjectNameUniqueConstraint("project", "org1")),
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test1.com/saml/metadata")),
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test2.com/saml/metadata")),
uniqueConstraintsFromEventConstraint(project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test3.com/saml/metadata")),
project.NewProjectRemovedEvent(context.Background(),
&project.NewAggregate("project1", "org1").Aggregate,
"project",
[]*eventstore.UniqueConstraint{
project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test1.com/saml/metadata"),
project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test2.com/saml/metadata"),
project.NewRemoveSAMLConfigEntityIDUniqueConstraint("https://test3.com/saml/metadata"),
},
),
),
),
},
@@ -1219,103 +1172,3 @@ func TestAddProject(t *testing.T) {
})
}
}
// func TestExistsProject(t *testing.T) {
// type args struct {
// filter preparation.FilterToQueryReducer
// id string
// resourceOwner string
// }
// tests := []struct {
// name string
// args args
// wantExists bool
// wantErr bool
// }{
// {
// name: "no events",
// args: args{
// filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
// return []eventstore.Event{}, nil
// },
// id: "id",
// resourceOwner: "ro",
// },
// wantExists: false,
// wantErr: false,
// },
// {
// name: "project added",
// args: args{
// filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
// return []eventstore.Event{
// project.NewProjectAddedEvent(
// context.Background(),
// &project.NewAggregate("id", "ro").Aggregate,
// "name",
// false,
// false,
// false,
// domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy,
// ),
// }, nil
// },
// id: "id",
// resourceOwner: "ro",
// },
// wantExists: true,
// wantErr: false,
// },
// {
// name: "project removed",
// args: args{
// filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
// return []eventstore.Event{
// project.NewProjectAddedEvent(
// context.Background(),
// &project.NewAggregate("id", "ro").Aggregate,
// "name",
// false,
// false,
// false,
// domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy,
// ),
// project.NewProjectRemovedEvent(
// context.Background(),
// &project.NewAggregate("id", "ro").Aggregate,
// "name",
// ),
// }, nil
// },
// id: "id",
// resourceOwner: "ro",
// },
// wantExists: false,
// wantErr: false,
// },
// {
// name: "error durring filter",
// args: args{
// filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
// return nil, errors.ThrowInternal(nil, "PROJE-Op26p", "Errors.Internal")
// },
// id: "id",
// resourceOwner: "ro",
// },
// wantExists: false,
// wantErr: true,
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// gotExists, err := projectWriteModel(context.Background(), tt.args.filter, tt.args.id, tt.args.resourceOwner)
// if (err != nil) != tt.wantErr {
// t.Errorf("ExistsUser() error = %v, wantErr %v", err, tt.wantErr)
// return
// }
// if gotExists != tt.wantExists {
// t.Errorf("ExistsUser() = %v, want %v", gotExists, tt.wantExists)
// }
// })
// }
// }
+2 -2
View File
@@ -37,8 +37,8 @@ func newQuotaWriteModel(instanceId, resourceOwner string, unit quota.Unit) *quot
func (wm *quotaWriteModel) Query() *eventstore.SearchQueryBuilder {
query := eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
ResourceOwner(wm.ResourceOwner).
AddQuery().
InstanceID(wm.InstanceID).
AddQuery().
AggregateTypes(quota.AggregateType).
EventTypes(
quota.AddedEventType,
@@ -51,7 +51,7 @@ func (wm *quotaWriteModel) Query() *eventstore.SearchQueryBuilder {
func (wm *quotaWriteModel) Reduce() error {
for _, event := range wm.Events {
wm.ChangeDate = event.CreationDate()
wm.ChangeDate = event.CreatedAt()
switch e := event.(type) {
case *quota.SetEvent:
wm.rollingAggregateID = e.Aggregate().ID
+50 -67
View File
@@ -9,7 +9,6 @@ import (
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/repository/quota"
@@ -68,14 +67,16 @@ func TestQuotaReport_ReportQuotaUsage(t *testing.T) {
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
dueNotifications: []*quota.NotificationDueEvent{
{
Unit: QuotaRequestsAllAuthenticated.Enum(),
ID: "id",
CallURL: "url",
PeriodStart: time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
Threshold: 1000,
Usage: 250,
},
quota.NewNotificationDueEvent(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
},
},
res: res{},
@@ -87,20 +88,15 @@ func TestQuotaReport_ReportQuotaUsage(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewNotificationDueEvent(context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
),
},
quota.NewNotificationDueEvent(context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
),
),
},
@@ -143,32 +139,24 @@ func TestQuotaReport_ReportQuotaUsage(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewNotificationDueEvent(context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id1",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
),
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewNotificationDueEvent(context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id3",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
),
},
quota.NewNotificationDueEvent(context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id1",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
quota.NewNotificationDueEvent(context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id3",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
),
),
},
@@ -250,25 +238,20 @@ func TestQuotaReport_UsageNotificationSent(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewNotifiedEvent(
context.Background(),
"quota1",
quota.NewNotificationDueEvent(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id1",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
),
quota.NewNotifiedEvent(
context.Background(),
"quota1",
quota.NewNotificationDueEvent(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
"id1",
"url",
time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
1000,
250,
),
},
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "quota1"),
+90 -127
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errors "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/repository/quota"
@@ -108,24 +107,19 @@ func TestQuota_AddQuota(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
quota.SetEventType,
),
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(make([]*quota.SetEventNotification, 0)),
),
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
quota.SetEventType,
),
},
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(make([]*quota.SetEventNotification, 0)),
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "quota1"),
@@ -178,24 +172,19 @@ func TestQuota_AddQuota(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota2", "INSTANCE").Aggregate,
quota.SetEventType,
),
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(make([]*quota.SetEventNotification, 0)),
),
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota2", "INSTANCE").Aggregate,
quota.SetEventType,
),
},
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(make([]*quota.SetEventNotification, 0)),
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "quota2"),
@@ -224,31 +213,26 @@ func TestQuota_AddQuota(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
quota.SetEventType,
),
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(
[]*quota.SetEventNotification{{
ID: "notification1",
Percent: 20,
Repeat: false,
CallURL: "https://url.com",
}},
),
),
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
quota.SetEventType,
),
},
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(
[]*quota.SetEventNotification{{
ID: "notification1",
Percent: 20,
Repeat: false,
CallURL: "https://url.com",
}},
),
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "quota1", "notification1"),
@@ -389,24 +373,19 @@ func TestQuota_SetQuota(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
quota.SetEventType,
),
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(make([]*quota.SetEventNotification, 0)),
),
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
quota.SetEventType,
),
},
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(make([]*quota.SetEventNotification, 0)),
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "quota1"),
@@ -459,24 +438,19 @@ func TestQuota_SetQuota(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota2", "INSTANCE").Aggregate,
quota.SetEventType,
),
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(make([]*quota.SetEventNotification, 0)),
),
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota2", "INSTANCE").Aggregate,
quota.SetEventType,
),
},
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(make([]*quota.SetEventNotification, 0)),
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "quota2"),
@@ -505,31 +479,26 @@ func TestQuota_SetQuota(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
quota.SetEventType,
),
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(
[]*quota.SetEventNotification{{
ID: "notification1",
Percent: 20,
Repeat: false,
CallURL: "https://url.com",
}},
),
),
quota.NewSetEvent(
eventstore.NewBaseEventForPush(
context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
quota.SetEventType,
),
},
QuotaRequestsAllAuthenticated.Enum(),
quota.ChangeFrom(time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)),
quota.ChangeResetInterval(30*24*time.Hour),
quota.ChangeAmount(1000),
quota.ChangeLimit(true),
quota.ChangeNotifications(
[]*quota.SetEventNotification{{
ID: "notification1",
Percent: 20,
Repeat: false,
CallURL: "https://url.com",
}},
),
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "quota1", "notification1"),
@@ -678,16 +647,10 @@ func TestQuota_RemoveQuota(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
quota.NewRemovedEvent(context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
),
),
},
uniqueConstraintsFromEventConstraintWithInstanceID("INSTANCE", quota.NewRemoveQuotaNameUniqueConstraint(quota.RequestsAllAuthenticated)),
quota.NewRemovedEvent(context.Background(),
&quota.NewAggregate("quota1", "INSTANCE").Aggregate,
QuotaRequestsAllAuthenticated.Enum(),
),
),
),
},
+2 -6
View File
@@ -265,9 +265,7 @@ func TestCommands_OTPSMSSent(t *testing.T) {
),
),
expectPush(
eventPusherToEvents(
session.NewOTPSMSSentEvent(context.Background(), &session.NewAggregate("sessionID", "instanceID").Aggregate),
),
session.NewOTPSMSSentEvent(context.Background(), &session.NewAggregate("sessionID", "instanceID").Aggregate),
),
),
},
@@ -669,9 +667,7 @@ func TestCommands_OTPEmailSent(t *testing.T) {
),
),
expectPush(
eventPusherToEvents(
session.NewOTPEmailSentEvent(context.Background(), &session.NewAggregate("sessionID", "instanceID").Aggregate),
),
session.NewOTPEmailSentEvent(context.Background(), &session.NewAggregate("sessionID", "instanceID").Aggregate),
),
),
},
+24 -28
View File
@@ -204,11 +204,9 @@ func TestCommands_CreateSession(t *testing.T) {
[]expect{
expectFilter(),
expectPush(
eventPusherToEvents(
session.NewAddedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate),
session.NewTokenSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"tokenID",
),
session.NewAddedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate),
session.NewTokenSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"tokenID",
),
),
},
@@ -438,15 +436,17 @@ func TestCommands_updateSession(t *testing.T) {
fields{
eventstore: eventstoreExpect(t,
expectPush(
eventPusherToEvents(
session.NewUserCheckedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"userID", testNow),
session.NewPasswordCheckedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
testNow),
session.NewMetadataSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
map[string][]byte{"key": []byte("value")}),
session.NewTokenSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"tokenID"),
session.NewUserCheckedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"userID", testNow,
),
session.NewPasswordCheckedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
testNow,
),
session.NewMetadataSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
map[string][]byte{"key": []byte("value")},
),
session.NewTokenSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"tokenID",
),
),
),
@@ -620,16 +620,14 @@ func TestCommands_updateSession(t *testing.T) {
fields{
eventstore: eventstoreExpect(t,
expectPush(
eventPusherToEvents(
session.NewUserCheckedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"userID", testNow),
session.NewIntentCheckedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
testNow),
session.NewMetadataSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
map[string][]byte{"key": []byte("value")}),
session.NewTokenSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"tokenID"),
),
session.NewUserCheckedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"userID", testNow),
session.NewIntentCheckedEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
testNow),
session.NewMetadataSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
map[string][]byte{"key": []byte("value")}),
session.NewTokenSetEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate,
"tokenID"),
),
),
},
@@ -930,8 +928,7 @@ func TestCommands_TerminateSession(t *testing.T) {
),
expectPushFailed(
caos_errs.ThrowInternal(nil, "id", "pushed failed"),
eventPusherToEvents(
session.NewTerminateEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate)),
session.NewTerminateEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate),
),
),
tokenVerifier: func(ctx context.Context, sessionToken, sessionID, tokenID string) (err error) {
@@ -960,8 +957,7 @@ func TestCommands_TerminateSession(t *testing.T) {
),
),
expectPush(
eventPusherToEvents(
session.NewTerminateEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate)),
session.NewTerminateEvent(context.Background(), &session.NewAggregate("sessionID", "org1").Aggregate),
),
),
tokenVerifier: func(ctx context.Context, sessionToken, sessionID, tokenID string) (err error) {
+1
View File
@@ -28,6 +28,7 @@ func NewIAMSMSConfigWriteModel(instanceID, id string) *IAMSMSConfigWriteModel {
WriteModel: eventstore.WriteModel{
AggregateID: instanceID,
ResourceOwner: instanceID,
InstanceID: instanceID,
},
ID: id,
}
+34 -54
View File
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
"github.com/zitadel/zitadel/internal/notification/channels/twilio"
@@ -46,22 +45,19 @@ func TestCommandSide_AddSMSConfigTwilio(t *testing.T) {
t,
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(instance.NewSMSConfigTwilioAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"providerid",
"sid",
"senderName",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("token"),
},
),
),
},
instance.NewSMSConfigTwilioAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"providerid",
"sid",
"senderName",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("token"),
},
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "providerid"),
@@ -218,16 +214,12 @@ func TestCommandSide_ChangeSMSConfigTwilio(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newSMSConfigTwilioChangedEvent(
context.Background(),
"providerid",
"sid2",
"senderName2",
),
),
},
newSMSConfigTwilioChangedEvent(
context.Background(),
"providerid",
"sid2",
"senderName2",
),
),
),
},
@@ -335,15 +327,11 @@ func TestCommandSide_ActivateSMSConfigTwilio(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewSMSConfigTwilioActivatedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"providerid",
),
),
},
instance.NewSMSConfigTwilioActivatedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"providerid",
),
),
),
},
@@ -453,15 +441,11 @@ func TestCommandSide_DeactivateSMSConfigTwilio(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewSMSConfigDeactivatedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"providerid",
),
),
},
instance.NewSMSConfigDeactivatedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"providerid",
),
),
),
},
@@ -564,15 +548,11 @@ func TestCommandSide_RemoveSMSConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
instance.NewSMSConfigRemovedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"providerid",
),
),
},
instance.NewSMSConfigRemovedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
"providerid",
),
),
),
},
+4 -4
View File
@@ -28,7 +28,7 @@ func (c *Commands) AddSMTPConfig(ctx context.Context, config *smtp.Config) (*dom
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
@@ -46,7 +46,7 @@ func (c *Commands) ChangeSMTPConfig(ctx context.Context, config *smtp.Config) (*
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
@@ -76,7 +76,7 @@ func (c *Commands) ChangeSMTPConfigPassword(ctx context.Context, password string
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
@@ -94,7 +94,7 @@ func (c *Commands) RemoveSMTPConfig(ctx context.Context) (*domain.ObjectDetails,
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().InstanceID,
}, nil
}
+80 -116
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/notification/channels/smtp"
"github.com/zitadel/zitadel/internal/repository/instance"
)
@@ -143,27 +142,22 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSMTPConfigAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
"[email protected]",
"name",
"",
"host:587",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
},
instance.NewSMTPConfigAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
"[email protected]",
"name",
"",
"host:587",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
),
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -208,27 +202,22 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSMTPConfigAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
"[email protected]",
"name",
"[email protected]",
"host:587",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
},
instance.NewSMTPConfigAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
"[email protected]",
"name",
"[email protected]",
"host:587",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
),
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -318,27 +307,22 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSMTPConfigAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
"[email protected]",
"name",
"",
"[2001:db8::1]:2525",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
},
instance.NewSMTPConfigAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
"[email protected]",
"name",
"",
"[2001:db8::1]:2525",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
),
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -576,20 +560,15 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
newSMTPConfigChangedEvent(
context.Background(),
false,
"[email protected]",
"name2",
"[email protected]",
"host2:587",
"user2",
),
),
},
newSMTPConfigChangedEvent(
context.Background(),
false,
"[email protected]",
"name2",
"[email protected]",
"host2:587",
"user2",
),
),
),
},
@@ -690,20 +669,15 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
newSMTPConfigChangedEvent(
context.Background(),
false,
"[email protected]",
"name2",
"[email protected]",
"[2001:db8::1]:2525",
"user2",
),
),
},
newSMTPConfigChangedEvent(
context.Background(),
false,
"[email protected]",
"name2",
"[email protected]",
"[2001:db8::1]:2525",
"user2",
),
),
),
},
@@ -802,21 +776,16 @@ func TestCommandSide_ChangeSMTPConfigPassword(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSMTPConfigPasswordChangedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
},
instance.NewSMTPConfigPasswordChangedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
),
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -906,15 +875,10 @@ func TestCommandSide_RemoveSMTPConfig(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSMTPConfigRemovedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
),
),
},
instance.NewSMTPConfigRemovedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
),
),
),
},
+2 -2
View File
@@ -256,7 +256,7 @@ func (rm *UniqueConstraintReadModel) getUniqueConstraint(aggregateID, objectID,
return nil
}
func (rm *UniqueConstraintReadModel) addUniqueConstraint(aggregateID, objectID string, constraint *eventstore.EventUniqueConstraint) {
func (rm *UniqueConstraintReadModel) addUniqueConstraint(aggregateID, objectID string, constraint *eventstore.UniqueConstraint) {
migrateUniqueConstraint := &domain.UniqueConstraintMigration{
AggregateID: aggregateID,
ObjectID: objectID,
@@ -267,7 +267,7 @@ func (rm *UniqueConstraintReadModel) addUniqueConstraint(aggregateID, objectID s
rm.UniqueConstraints = append(rm.UniqueConstraints, migrateUniqueConstraint)
}
func (rm *UniqueConstraintReadModel) changeUniqueConstraint(aggregateID, objectID string, constraint *eventstore.EventUniqueConstraint) {
func (rm *UniqueConstraintReadModel) changeUniqueConstraint(aggregateID, objectID string, constraint *eventstore.UniqueConstraint) {
for i, uniqueConstraint := range rm.UniqueConstraints {
if uniqueConstraint.AggregateID == aggregateID && uniqueConstraint.ObjectID == objectID && uniqueConstraint.UniqueType == constraint.UniqueType {
rm.UniqueConstraints[i] = &domain.UniqueConstraintMigration{
+1 -1
View File
@@ -140,7 +140,7 @@ func (c *Commands) removeRoleFromUserGrant(ctx context.Context, userGrantID stri
func (c *Commands) DeactivateUserGrant(ctx context.Context, grantID, resourceOwner string) (objectDetails *domain.ObjectDetails, err error) {
if grantID == "" || resourceOwner == "" {
return nil, caos_errs.ThrowInvalidArgument(nil, "COMMAND-M0dsf", "Errors.UserGrant.IDMissing")
return nil, caos_errs.ThrowInvalidArgument(nil, "COMMAND-N2OhG", "Errors.UserGrant.IDMissing")
}
existingUserGrant, err := c.userGrantWriteModelByID(ctx, grantID, resourceOwner)
+64 -109
View File
@@ -11,7 +11,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -437,16 +436,13 @@ func TestCommandSide_AddUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(usergrant.NewUserGrantAddedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"",
[]string{"rolekey1"},
)),
},
uniqueConstraintsFromEventConstraint(usergrant.NewAddUserGrantUniqueConstraint("org1", "user1", "project1", "")),
usergrant.NewUserGrantAddedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"",
[]string{"rolekey1"},
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "usergrant1"),
@@ -518,16 +514,13 @@ func TestCommandSide_AddUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(usergrant.NewUserGrantAddedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"projectgrant1",
[]string{"rolekey1"},
)),
},
uniqueConstraintsFromEventConstraint(usergrant.NewAddUserGrantUniqueConstraint("org1", "user1", "project1", "projectgrant1")),
usergrant.NewUserGrantAddedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"projectgrant1",
[]string{"rolekey1"},
),
),
),
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "usergrant1"),
@@ -1078,12 +1071,10 @@ func TestCommandSide_ChangeUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(usergrant.NewUserGrantChangedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
[]string{"rolekey1", "rolekey2"},
)),
},
usergrant.NewUserGrantChangedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
[]string{"rolekey1", "rolekey2"},
),
),
),
},
@@ -1174,12 +1165,10 @@ func TestCommandSide_ChangeUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(usergrant.NewUserGrantChangedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
[]string{"rolekey1", "rolekey2"},
)),
},
usergrant.NewUserGrantChangedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
[]string{"rolekey1", "rolekey2"},
),
),
),
},
@@ -1397,13 +1386,9 @@ func TestCommandSide_DeactivateUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
usergrant.NewUserGrantDeactivatedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
),
),
},
usergrant.NewUserGrantDeactivatedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
),
),
),
},
@@ -1609,13 +1594,9 @@ func TestCommandSide_ReactivateUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
usergrant.NewUserGrantReactivatedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
),
),
},
usergrant.NewUserGrantReactivatedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
),
),
),
},
@@ -1777,17 +1758,12 @@ func TestCommandSide_RemoveUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"",
),
),
},
uniqueConstraintsFromEventConstraint(usergrant.NewRemoveUserGrantUniqueConstraint("org1", "user1", "project1", "")),
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"",
),
),
),
},
@@ -1817,17 +1793,12 @@ func TestCommandSide_RemoveUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"projectgrant1",
),
),
},
uniqueConstraintsFromEventConstraint(usergrant.NewRemoveUserGrantUniqueConstraint("org1", "user1", "project1", "projectgrant1")),
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"projectgrant1",
),
),
),
},
@@ -1994,26 +1965,18 @@ func TestCommandSide_BulkRemoveUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"",
),
),
eventFromEventPusher(
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant2", "org1").Aggregate,
"user2",
"project2",
"",
),
),
},
uniqueConstraintsFromEventConstraint(usergrant.NewRemoveUserGrantUniqueConstraint("org1", "user1", "project1", "")),
uniqueConstraintsFromEventConstraint(usergrant.NewRemoveUserGrantUniqueConstraint("org1", "user2", "project2", "")),
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"",
),
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant2", "org1").Aggregate,
"user2",
"project2",
"",
),
),
),
},
@@ -2048,26 +2011,18 @@ func TestCommandSide_BulkRemoveUserGrant(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"projectgrant1",
),
),
eventFromEventPusher(
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant2", "org1").Aggregate,
"user2",
"project2",
"projectgrant2",
),
),
},
uniqueConstraintsFromEventConstraint(usergrant.NewRemoveUserGrantUniqueConstraint("org1", "user1", "project1", "projectgrant1")),
uniqueConstraintsFromEventConstraint(usergrant.NewRemoveUserGrantUniqueConstraint("org1", "user2", "project2", "projectgrant2")),
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant1", "org1").Aggregate,
"user1",
"project1",
"projectgrant1",
),
usergrant.NewUserGrantRemovedEvent(context.Background(),
&usergrant.NewAggregate("usergrant2", "org1").Aggregate,
"user2",
"project2",
"projectgrant2",
),
),
),
},
+1 -1
View File
@@ -149,7 +149,7 @@ func (c *Commands) AddHuman(ctx context.Context, resourceOwner string, human *Ad
}
human.Details = &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
EventDate: events[len(events)-1].CreatedAt(),
ResourceOwner: events[len(events)-1].Aggregate().ResourceOwner,
}
+8 -13
View File
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/user"
)
@@ -131,18 +130,14 @@ func TestCommandSide_ChangeHumanAddress(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newAddressChangedEvent(context.Background(),
"user1", "org1",
"country",
"locality",
"postalcode",
"region",
"street",
),
),
},
newAddressChangedEvent(context.Background(),
"user1", "org1",
"country",
"locality",
"postalcode",
"region",
"street",
),
),
),
},
+8 -17
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/user"
"github.com/zitadel/zitadel/internal/static"
"github.com/zitadel/zitadel/internal/static/mock"
@@ -151,14 +150,10 @@ func TestCommandSide_AddHumanAvatar(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanAvatarAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"avatar?v=test",
),
),
},
user.NewHumanAvatarAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"avatar?v=test",
),
),
),
storage: mock.NewStorage(t).ExpectPutObject(),
@@ -326,14 +321,10 @@ func TestCommandSide_RemoveHumanAvatar(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanAvatarRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"key",
),
),
},
user.NewHumanAvatarRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"key",
),
),
),
},
+92 -75
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/user"
)
@@ -181,19 +180,13 @@ func TestCommandSide_ChangeHumanEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanEmailChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"[email protected]",
),
),
eventFromEventPusher(
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanEmailChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"[email protected]",
),
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -241,13 +234,59 @@ func TestCommandSide_ChangeHumanEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
args: args{
ctx: context.Background(),
email: &domain.Email{
ObjectRoot: models.ObjectRoot{
AggregateID: "user1",
},
EmailAddress: "[email protected]",
IsEmailVerified: true,
},
resourceOwner: "org1",
},
res: res{
want: &domain.Email{
ObjectRoot: models.ObjectRoot{
AggregateID: "user1",
ResourceOwner: "org1",
},
EmailAddress: "[email protected]",
IsEmailVerified: true,
},
},
},
{
name: "email verified, ok",
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username",
"firstname",
"lastname",
"nickname",
"displayname",
language.German,
domain.GenderUnspecified,
"[email protected]",
true,
),
},
),
),
expectPush(
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -295,26 +334,20 @@ func TestCommandSide_ChangeHumanEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanEmailChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"[email protected]",
),
),
eventFromEventPusher(
user.NewHumanEmailCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
},
user.NewHumanEmailChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"[email protected]",
),
user.NewHumanEmailCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
),
},
@@ -497,13 +530,9 @@ func TestCommandSide_VerifyHumanEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanEmailVerificationFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanEmailVerificationFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -552,13 +581,9 @@ func TestCommandSide_VerifyHumanEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -755,20 +780,16 @@ func TestCommandSide_CreateVerificationCodeHumanEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanEmailCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
},
user.NewHumanEmailCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
),
},
@@ -887,13 +908,9 @@ func TestCommandSide_EmailVerificationCodeSent(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanEmailCodeSentEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanEmailCodeSentEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
+55 -86
View File
@@ -12,7 +12,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/user"
)
@@ -133,20 +132,16 @@ func TestCommandSide_ResendInitialMail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanInitialCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
},
user.NewHumanInitialCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
),
},
@@ -191,20 +186,16 @@ func TestCommandSide_ResendInitialMail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanInitialCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
},
user.NewHumanInitialCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
),
},
@@ -248,24 +239,20 @@ func TestCommandSide_ResendInitialMail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanEmailChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"[email protected]")),
eventFromEventPusher(
user.NewHumanInitialCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
},
user.NewHumanEmailChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"[email protected]",
),
user.NewHumanInitialCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
),
},
@@ -442,13 +429,9 @@ func TestCommandSide_VerifyInitCode(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanInitializedCheckFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanInitializedCheckFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -497,18 +480,12 @@ func TestCommandSide_VerifyInitCode(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanInitializedCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
eventFromEventPusher(
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanInitializedCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
user.NewHumanEmailVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -574,19 +551,15 @@ func TestCommandSide_VerifyInitCode(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanInitializedCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
eventFromEventPusher(
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
false,
"")),
},
user.NewHumanInitializedCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
false,
"",
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
@@ -695,13 +668,9 @@ func TestCommandSide_InitCodeSent(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanInitialCodeSentEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanInitialCodeSentEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
+1 -1
View File
@@ -71,7 +71,7 @@ func (c *Commands) createHumanTOTP(ctx context.Context, userID, resourceOwner st
human, err := c.getHuman(ctx, userID, resourceOwner)
if err != nil {
logging.WithError(err).WithField("traceID", tracing.TraceIDFromCtx(ctx)).Debug("unable to get human for loginname")
return nil, caos_errs.ThrowPreconditionFailed(err, "COMMAND-MM9fs", "Errors.User.NotFound")
return nil, caos_errs.ThrowPreconditionFailed(err, "COMMAND-SqyJz", "Errors.User.NotFound")
}
org, err := c.getOrg(ctx, human.ResourceOwner)
if err != nil {
+250 -354
View File
@@ -18,7 +18,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/user"
@@ -84,19 +83,17 @@ func TestCommandSide_AddHumanTOTP(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username",
"firstname",
"lastname",
"nickname",
"displayname",
language.German,
domain.GenderUnspecified,
"[email protected]",
true,
),
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username",
"firstname",
"lastname",
"nickname",
"displayname",
language.German,
domain.GenderUnspecified,
"[email protected]",
true,
),
),
expectFilter(),
@@ -117,27 +114,23 @@ func TestCommandSide_AddHumanTOTP(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username",
"firstname",
"lastname",
"nickname",
"displayname",
language.German,
domain.GenderUnspecified,
"[email protected]",
true,
),
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username",
"firstname",
"lastname",
"nickname",
"displayname",
language.German,
domain.GenderUnspecified,
"[email protected]",
true,
),
),
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(),
&user.NewAggregate("org1", "org1").Aggregate,
"org",
),
org.NewOrgAddedEvent(context.Background(),
&user.NewAggregate("org1", "org1").Aggregate,
"org",
),
),
expectFilter(),
@@ -159,54 +152,47 @@ func TestCommandSide_AddHumanTOTP(t *testing.T) {
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username",
"firstname",
"lastname",
"nickname",
"displayname",
language.German,
domain.GenderUnspecified,
"[email protected]",
true,
),
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username",
"firstname",
"lastname",
"nickname",
"displayname",
language.German,
domain.GenderUnspecified,
"[email protected]",
true,
),
),
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(),
&user.NewAggregate("org1", "org1").Aggregate,
"org",
),
org.NewOrgAddedEvent(context.Background(),
&user.NewAggregate("org1", "org1").Aggregate,
"org",
),
),
expectFilter(
eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
),
org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1").Aggregate,
true,
true,
true,
),
),
expectFilter(
eventFromEventPusher(
user.NewHumanOTPAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
}),
user.NewHumanOTPAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
),
user.NewHumanOTPVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"agent1",
),
eventFromEventPusher(
user.NewHumanOTPVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"agent1")),
),
),
},
@@ -268,7 +254,7 @@ func TestCommands_createHumanTOTP(t *testing.T) {
resourceOwner: "org1",
userID: "user1",
},
wantErr: caos_errs.ThrowPreconditionFailed(nil, "COMMAND-MM9fs", "Errors.User.NotFound"),
wantErr: caos_errs.ThrowPreconditionFailed(nil, "COMMAND-SqyJz", "Errors.User.NotFound"),
},
{
name: "org not existing, not found error",
@@ -648,12 +634,10 @@ func TestCommands_HumanCheckMFATOTPSetup(t *testing.T) {
),
),
expectPushFailed(io.ErrClosedPipe,
[]*repository.Event{eventFromEventPusher(
user.NewHumanOTPVerifiedEvent(ctx,
userAgg,
"agent1",
),
)},
user.NewHumanOTPVerifiedEvent(ctx,
userAgg,
"agent1",
),
),
),
},
@@ -674,12 +658,12 @@ func TestCommands_HumanCheckMFATOTPSetup(t *testing.T) {
user.NewHumanOTPAddedEvent(ctx, userAgg, secret),
),
),
expectPush([]*repository.Event{eventFromEventPusher(
expectPush(
user.NewHumanOTPVerifiedEvent(ctx,
userAgg,
"agent1",
),
)}),
),
),
},
args: args{
@@ -777,13 +761,9 @@ func TestCommandSide_RemoveHumanTOTP(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanOTPRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -957,13 +937,9 @@ func TestCommandSide_AddHumanOTPSMS(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPSMSAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -1032,13 +1008,9 @@ func TestCommandSide_AddHumanOTPSMSWithCheckSucceeded(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPSMSAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -1071,27 +1043,21 @@ func TestCommandSide_AddHumanOTPSMSWithCheckSucceeded(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSCheckSucceededEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
},
user.NewHumanOTPSMSAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
user.NewHumanOTPSMSCheckSucceededEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
),
},
@@ -1211,13 +1177,9 @@ func TestCommandSide_RemoveHumanOTPSMS(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSRemovedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPSMSRemovedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
checkPermission: newMockPermissionCheckAllowed(),
@@ -1339,21 +1301,17 @@ func TestCommandSide_HumanSendOTPSMS(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
nil,
),
),
},
user.NewHumanOTPSMSCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
nil,
),
),
),
userEncryption: crypto.CreateMockEncryptionAlgWithCode(gomock.NewController(t), "12345678"),
@@ -1383,21 +1341,17 @@ func TestCommandSide_HumanSendOTPSMS(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
nil,
),
),
},
user.NewHumanOTPSMSCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
nil,
),
),
),
userEncryption: crypto.CreateMockEncryptionAlgWithCode(gomock.NewController(t), "12345678"),
@@ -1439,29 +1393,25 @@ func TestCommandSide_HumanSendOTPSMS(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
},
user.NewHumanOTPSMSCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
),
userEncryption: crypto.CreateMockEncryptionAlgWithCode(gomock.NewController(t), "12345678"),
@@ -1565,13 +1515,9 @@ func TestCommandSide_HumanOTPSMSCodeSent(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSCodeSentEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPSMSCodeSentEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -1726,22 +1672,18 @@ func TestCommandSide_HumanCheckOTPSMS(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSCheckFailedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
},
user.NewHumanOTPSMSCheckFailedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
),
userEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -1798,22 +1740,18 @@ func TestCommandSide_HumanCheckOTPSMS(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPSMSCheckSucceededEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
},
user.NewHumanOTPSMSCheckSucceededEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
),
userEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -1944,13 +1882,9 @@ func TestCommandSide_AddHumanOTPEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPEmailAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -2019,13 +1953,9 @@ func TestCommandSide_AddHumanOTPEmailWithCheckSucceeded(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPEmailAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -2058,27 +1988,21 @@ func TestCommandSide_AddHumanOTPEmailWithCheckSucceeded(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailCheckSucceededEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
},
user.NewHumanOTPEmailAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
user.NewHumanOTPEmailCheckSucceededEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
),
},
@@ -2198,13 +2122,9 @@ func TestCommandSide_RemoveHumanOTPEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailRemovedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPEmailRemovedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
checkPermission: newMockPermissionCheckAllowed(),
@@ -2326,21 +2246,17 @@ func TestCommandSide_HumanSendOTPEmail(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
nil,
),
),
},
user.NewHumanOTPEmailCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
nil,
),
),
),
userEncryption: crypto.CreateMockEncryptionAlgWithCode(gomock.NewController(t), "12345678"),
@@ -2370,21 +2286,17 @@ func TestCommandSide_HumanSendOTPEmail(t *testing.T) {
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
nil,
),
),
},
user.NewHumanOTPEmailCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
nil,
),
),
),
userEncryption: crypto.CreateMockEncryptionAlgWithCode(gomock.NewController(t), "12345678"),
@@ -2426,29 +2338,25 @@ func TestCommandSide_HumanSendOTPEmail(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
},
user.NewHumanOTPEmailCodeAddedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
),
userEncryption: crypto.CreateMockEncryptionAlgWithCode(gomock.NewController(t), "12345678"),
@@ -2552,13 +2460,9 @@ func TestCommandSide_HumanOTPEmailCodeSent(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailCodeSentEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanOTPEmailCodeSentEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -2713,22 +2617,18 @@ func TestCommandSide_HumanCheckOTPEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailCheckFailedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
},
user.NewHumanOTPEmailCheckFailedEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
),
userEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
@@ -2785,22 +2685,18 @@ func TestCommandSide_HumanCheckOTPEmail(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusherWithInstanceID("inst1",
user.NewHumanOTPEmailCheckSucceededEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
},
user.NewHumanOTPEmailCheckSucceededEvent(ctx,
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "authRequestID",
UserAgentID: "userAgentID",
BrowserInfo: &user.BrowserInfo{
UserAgent: "user-agent",
AcceptLanguage: "en",
RemoteIP: net.IP{192, 0, 2, 1},
},
},
),
),
),
userEncryption: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
+1 -1
View File
@@ -175,7 +175,7 @@ func (c *Commands) RequestSetPassword(ctx context.Context, userID, resourceOwner
func (c *Commands) PasswordCodeSent(ctx context.Context, orgID, userID string) (err error) {
if userID == "" {
return caos_errs.ThrowInvalidArgument(nil, "COMMAND-MM9fs", "Errors.User.UserIDMissing")
return caos_errs.ThrowInvalidArgument(nil, "COMMAND-meEfe", "Errors.User.UserIDMissing")
}
existingPassword, err := c.passwordWriteModel(ctx, userID, orgID)
+85 -135
View File
@@ -16,7 +16,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/user"
)
@@ -158,16 +157,12 @@ func TestCommandSide_SetOneTimePassword(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
true,
"",
),
),
},
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
true,
"",
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
@@ -225,16 +220,12 @@ func TestCommandSide_SetOneTimePassword(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
false,
"",
),
),
},
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
false,
"",
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
@@ -482,16 +473,12 @@ func TestCommandSide_SetPasswordWithVerifyCode(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
false,
"",
),
),
},
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
false,
"",
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
@@ -758,16 +745,12 @@ func TestCommandSide_ChangePassword(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password1",
false,
"",
),
),
},
user.NewHumanPasswordChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password1",
false,
"",
),
),
},
res: res{
@@ -929,21 +912,17 @@ func TestCommandSide_RequestSetPassword(t *testing.T) {
&user.NewAggregate("user1", "org1").Aggregate)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
domain.NotificationTypeEmail,
),
),
},
user.NewHumanPasswordCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
domain.NotificationTypeEmail,
),
),
),
},
@@ -1057,13 +1036,9 @@ func TestCommandSide_PasswordCodeSent(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordCodeSentEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanPasswordCodeSentEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -1362,17 +1337,13 @@ func TestCommandSide_CheckPassword(t *testing.T) {
"")),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordCheckFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
),
},
user.NewHumanPasswordCheckFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
@@ -1449,22 +1420,16 @@ func TestCommandSide_CheckPassword(t *testing.T) {
"")),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordCheckFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
),
eventFromEventPusher(
user.NewUserLockedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanPasswordCheckFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
user.NewUserLockedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
@@ -1543,17 +1508,13 @@ func TestCommandSide_CheckPassword(t *testing.T) {
"")),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
),
},
user.NewHumanPasswordCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
@@ -1627,23 +1588,18 @@ func TestCommandSide_CheckPassword(t *testing.T) {
"")),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
),
eventFromEventPusher(
user.NewHumanPasswordHashUpdatedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
),
),
},
user.NewHumanPasswordCheckSucceededEvent(
context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
user.NewHumanPasswordHashUpdatedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
@@ -1727,23 +1683,17 @@ func TestCommandSide_CheckPassword(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPasswordCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
),
eventFromEventPusher(
user.NewHumanPasswordHashUpdatedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
),
),
},
user.NewHumanPasswordCheckSucceededEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&user.AuthRequestInfo{
ID: "request1",
UserAgentID: "agent1",
},
),
user.NewHumanPasswordHashUpdatedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"$plain$x$password",
),
),
),
userPasswordHasher: mockPasswordHasher("x"),
+101 -82
View File
@@ -13,7 +13,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/user"
@@ -152,19 +151,13 @@ func TestCommandSide_ChangeHumanPhone(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPhoneChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"+41719876543",
),
),
eventFromEventPusher(
user.NewHumanPhoneVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanPhoneChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"+41719876543",
),
user.NewHumanPhoneVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -218,13 +211,65 @@ func TestCommandSide_ChangeHumanPhone(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPhoneVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
user.NewHumanPhoneVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
args: args{
ctx: context.Background(),
email: &domain.Phone{
ObjectRoot: models.ObjectRoot{
AggregateID: "user1",
},
PhoneNumber: "+41711234567",
IsPhoneVerified: true,
},
resourceOwner: "org1",
},
res: res{
want: &domain.Phone{
ObjectRoot: models.ObjectRoot{
AggregateID: "user1",
ResourceOwner: "org1",
},
PhoneNumber: "+41711234567",
IsPhoneVerified: true,
},
},
},
{
name: "phone changed to verified, ok",
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username",
"firstname",
"lastname",
"nickname",
"displayname",
language.German,
domain.GenderUnspecified,
"[email protected]",
true,
),
},
),
eventFromEventPusher(
user.NewHumanPhoneChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"+41711234567",
),
),
),
expectPush(
user.NewHumanPhoneVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -272,26 +317,20 @@ func TestCommandSide_ChangeHumanPhone(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPhoneChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"+41711234567",
),
),
eventFromEventPusher(
user.NewHumanPhoneCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
},
user.NewHumanPhoneChangedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"+41711234567",
),
user.NewHumanPhoneCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("a"),
},
time.Hour*1,
),
),
),
},
@@ -480,13 +519,9 @@ func TestCommandSide_VerifyHumanPhone(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPhoneVerificationFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanPhoneVerificationFailedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -541,13 +576,9 @@ func TestCommandSide_VerifyHumanPhone(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPhoneVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanPhoneVerifiedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -720,20 +751,16 @@ func TestCommandSide_CreateVerificationCodeHumanPhone(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPhoneCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour*1,
),
),
},
user.NewHumanPhoneCodeAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("12345678"),
},
time.Hour*1,
),
),
),
userEncryption: crypto.CreateMockEncryptionAlgWithCode(gomock.NewController(t), "12345678"),
@@ -848,13 +875,9 @@ func TestCommandSide_PhoneVerificationCodeSent(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPhoneCodeSentEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanPhoneCodeSentEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
@@ -993,13 +1016,9 @@ func TestCommandSide_RemoveHumanPhone(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewHumanPhoneRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
},
user.NewHumanPhoneRemovedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
),
),
),
},
+9 -14
View File
@@ -10,7 +10,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/user"
)
@@ -125,19 +124,15 @@ func TestCommandSide_ChangeHumanProfile(t *testing.T) {
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
newProfileChangedEvent(context.Background(),
"user1", "org1",
"firstname2",
"lastname2",
"nickname2",
"displayname2",
language.English,
domain.GenderMale,
),
),
},
newProfileChangedEvent(context.Background(),
"user1", "org1",
"firstname2",
"lastname2",
"nickname2",
"displayname2",
language.English,
domain.GenderMale,
),
),
),
},
@@ -14,7 +14,6 @@ import (
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
id_mock "github.com/zitadel/zitadel/internal/id/mock"
@@ -376,13 +375,11 @@ func TestCommands_RevokeRefreshToken(t *testing.T) {
)),
),
expectPushFailed(caos_errs.ThrowInternal(nil, "ERROR", "internal"),
[]*repository.Event{
eventFromEventPusher(user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
)),
},
user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
),
),
),
},
@@ -417,13 +414,11 @@ func TestCommands_RevokeRefreshToken(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
)),
},
user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
),
),
),
},
@@ -563,18 +558,16 @@ func TestCommands_RevokeRefreshTokens(t *testing.T) {
)),
),
expectPushFailed(caos_errs.ThrowInternal(nil, "ERROR", "internal"),
[]*repository.Event{
eventFromEventPusher(user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
)),
eventFromEventPusher(user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID2",
)),
},
user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
),
user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID2",
),
),
),
},
@@ -625,18 +618,16 @@ func TestCommands_RevokeRefreshTokens(t *testing.T) {
)),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
)),
eventFromEventPusher(user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID2",
)),
},
user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID",
),
user.NewHumanRefreshTokenRemovedEvent(
context.Background(),
&user.NewAggregate("userID", "orgID").Aggregate,
"tokenID2",
),
),
),
},

Some files were not shown because too many files have changed in this diff Show More