mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 23:57:31 +00:00
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:
@@ -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@test.ch",
|
||||
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@test.ch",
|
||||
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"),
|
||||
|
Reference in New Issue
Block a user