refactor: remove commandNew struct (#3465)

* refactor: remove commandNew struct

* requested fixes
This commit is contained in:
Livio Amstutz 2022-04-20 16:59:37 +02:00 committed by GitHub
parent 1305c14e49
commit a7816a43b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
60 changed files with 2073 additions and 2262 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/crypto"
crypto_db "github.com/caos/zitadel/internal/crypto/database" crypto_db "github.com/caos/zitadel/internal/crypto/database"
"github.com/caos/zitadel/internal/eventstore" "github.com/caos/zitadel/internal/eventstore"
webauthn_helper "github.com/caos/zitadel/internal/webauthn"
) )
type DefaultInstance struct { type DefaultInstance struct {
@ -39,7 +40,19 @@ func (mig *DefaultInstance) Execute(ctx context.Context) error {
return err return err
} }
cmd := command.NewCommandV2(mig.es, mig.defaults, userAlg, mig.zitadelRoles) cmd, err := command.StartCommands(mig.es,
mig.defaults,
mig.zitadelRoles,
nil,
nil,
webauthn_helper.Config{},
nil,
nil,
nil,
nil,
userAlg,
nil,
nil)
ctx = authz.WithRequestedDomain(ctx, mig.domain) ctx = authz.WithRequestedDomain(ctx, mig.domain)
_, err = cmd.SetUpInstance(ctx, &mig.InstanceSetup) _, err = cmd.SetUpInstance(ctx, &mig.InstanceSetup)

View File

@ -117,7 +117,7 @@ func startZitadel(config *Config, masterKey string) error {
Origin: http_util.BuildHTTP(config.ExternalDomain, config.ExternalPort, config.ExternalSecure), Origin: http_util.BuildHTTP(config.ExternalDomain, config.ExternalPort, config.ExternalSecure),
DisplayName: "ZITADEL", DisplayName: "ZITADEL",
} }
commands, err := command.StartCommands(eventstoreClient, config.SystemDefaults, config.InternalAuthZ, storage, authZRepo, webAuthNConfig, keys.IDPConfig, keys.OTP, keys.SMTP, keys.SMS, keys.User, keys.DomainVerification, keys.OIDC) commands, err := command.StartCommands(eventstoreClient, config.SystemDefaults, config.InternalAuthZ.RolePermissionMappings, storage, authZRepo, webAuthNConfig, keys.IDPConfig, keys.OTP, keys.SMTP, keys.SMS, keys.User, keys.DomainVerification, keys.OIDC)
if err != nil { if err != nil {
return fmt.Errorf("cannot start commands: %w", err) return fmt.Errorf("cannot start commands: %w", err)
} }

View File

@ -34,7 +34,7 @@ func (s *Server) ListIAMMembers(ctx context.Context, req *admin_pb.ListIAMMember
} }
func (s *Server) AddIAMMember(ctx context.Context, req *admin_pb.AddIAMMemberRequest) (*admin_pb.AddIAMMemberResponse, error) { func (s *Server) AddIAMMember(ctx context.Context, req *admin_pb.AddIAMMemberRequest) (*admin_pb.AddIAMMemberResponse, error) {
member, err := s.command.AddInstanceMember(ctx, AddIAMMemberToDomain(req)) member, err := s.command.AddInstanceMember(ctx, req.UserId, req.Roles...)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -7,6 +7,7 @@ import (
"github.com/caos/zitadel/internal/api/grpc/object" "github.com/caos/zitadel/internal/api/grpc/object"
org_grpc "github.com/caos/zitadel/internal/api/grpc/org" org_grpc "github.com/caos/zitadel/internal/api/grpc/org"
"github.com/caos/zitadel/internal/command"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/query" "github.com/caos/zitadel/internal/query"
admin_pb "github.com/caos/zitadel/pkg/grpc/admin" admin_pb "github.com/caos/zitadel/pkg/grpc/admin"
@ -50,18 +51,15 @@ func (s *Server) SetUpOrg(ctx context.Context, req *admin_pb.SetUpOrgRequest) (*
if err != nil { if err != nil {
return nil, err return nil, err
} }
human := setUpOrgHumanToDomain(req.User.(*admin_pb.SetUpOrgRequest_Human_).Human) //TODO: handle machine _ = userIDs //TODO: handle userIDs
org := setUpOrgOrgToDomain(req.Org) human := setUpOrgHumanToCommand(req.User.(*admin_pb.SetUpOrgRequest_Human_).Human) //TODO: handle machine
org := setUpOrgOrgToDomain(req.Org) //TODO: handle domain
_ = org
initCodeGenerator, err := s.query.InitEncryptionGenerator(ctx, domain.SecretGeneratorTypeInitCode, s.userCodeAlg) objectDetails, err := s.command.SetUpOrg(ctx, &command.OrgSetup{
if err != nil { Name: req.Org.Name,
return nil, err Human: human,
} })
phoneCodeGenerator, err := s.query.InitEncryptionGenerator(ctx, domain.SecretGeneratorTypeVerifyPhoneCode, s.userCodeAlg)
if err != nil {
return nil, err
}
objectDetails, err := s.command.SetUpOrg(ctx, org, human, initCodeGenerator, phoneCodeGenerator, userIDs, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,57 +2,44 @@ package admin
import ( import (
"github.com/caos/logging" "github.com/caos/logging"
user_grpc "github.com/caos/zitadel/internal/api/grpc/user"
"github.com/caos/zitadel/internal/domain"
admin_grpc "github.com/caos/zitadel/pkg/grpc/admin"
"golang.org/x/text/language" "golang.org/x/text/language"
user_grpc "github.com/caos/zitadel/internal/api/grpc/user"
"github.com/caos/zitadel/internal/command"
admin_grpc "github.com/caos/zitadel/pkg/grpc/admin"
) )
func setUpOrgHumanToDomain(human *admin_grpc.SetUpOrgRequest_Human) *domain.Human { func setUpOrgHumanToCommand(human *admin_grpc.SetUpOrgRequest_Human) command.AddHuman {
return &domain.Human{ var lang language.Tag
lang, err := language.Parse(human.Profile.PreferredLanguage)
logging.OnError(err).Debug("unable to parse language")
return command.AddHuman{
Username: human.UserName, Username: human.UserName,
Profile: setUpOrgHumanProfileToDomain(human.Profile), FirstName: human.Profile.FirstName,
LastName: human.Profile.LastName,
NickName: human.Profile.NickName,
DisplayName: human.Profile.DisplayName,
PreferredLang: lang,
Gender: user_grpc.GenderToDomain(human.Profile.Gender),
Email: setUpOrgHumanEmailToDomain(human.Email), Email: setUpOrgHumanEmailToDomain(human.Email),
Phone: setUpOrgHumanPhoneToDomain(human.Phone), Phone: setUpOrgHumanPhoneToDomain(human.Phone),
Password: setUpOrgHumanPasswordToDomain(human.Password), Password: human.Password,
} }
} }
func setUpOrgHumanProfileToDomain(profile *admin_grpc.SetUpOrgRequest_Human_Profile) *domain.Profile { func setUpOrgHumanEmailToDomain(email *admin_grpc.SetUpOrgRequest_Human_Email) command.Email {
var lang language.Tag return command.Email{
lang, err := language.Parse(profile.PreferredLanguage) Address: email.Email,
logging.Log("ADMIN-tiMWs").OnError(err).Debug("unable to parse language") Verified: email.IsEmailVerified,
return &domain.Profile{
FirstName: profile.FirstName,
LastName: profile.LastName,
NickName: profile.NickName,
DisplayName: profile.DisplayName,
PreferredLanguage: lang,
Gender: user_grpc.GenderToDomain(profile.Gender),
} }
} }
func setUpOrgHumanEmailToDomain(email *admin_grpc.SetUpOrgRequest_Human_Email) *domain.Email { func setUpOrgHumanPhoneToDomain(phone *admin_grpc.SetUpOrgRequest_Human_Phone) command.Phone {
return &domain.Email{
EmailAddress: email.Email,
IsEmailVerified: email.IsEmailVerified,
}
}
func setUpOrgHumanPhoneToDomain(phone *admin_grpc.SetUpOrgRequest_Human_Phone) *domain.Phone {
if phone == nil { if phone == nil {
return nil return command.Phone{}
} }
return &domain.Phone{ return command.Phone{
PhoneNumber: phone.Phone, Number: phone.Phone,
IsPhoneVerified: phone.IsPhoneVerified, Verified: phone.IsPhoneVerified,
} }
} }
func setUpOrgHumanPasswordToDomain(password string) *domain.Password {
if password == "" {
return nil
}
return domain.NewPassword(password)
}

View File

@ -247,7 +247,7 @@ func (s *Server) ListOrgMembers(ctx context.Context, req *mgmt_pb.ListOrgMembers
} }
func (s *Server) AddOrgMember(ctx context.Context, req *mgmt_pb.AddOrgMemberRequest) (*mgmt_pb.AddOrgMemberResponse, error) { func (s *Server) AddOrgMember(ctx context.Context, req *mgmt_pb.AddOrgMemberRequest) (*mgmt_pb.AddOrgMemberResponse, error) {
addedMember, err := s.command.AddOrgMember(ctx, AddOrgMemberRequestToDomain(ctx, req)) addedMember, err := s.command.AddOrgMember(ctx, authz.GetCtxData(ctx).OrgID, req.UserId, req.Roles...)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -66,10 +66,6 @@ func SetPrimaryOrgDomainRequestToDomain(ctx context.Context, req *mgmt_pb.SetPri
} }
} }
func AddOrgMemberRequestToDomain(ctx context.Context, req *mgmt_pb.AddOrgMemberRequest) *domain.Member {
return domain.NewMember(authz.GetCtxData(ctx).OrgID, req.UserId, req.Roles...)
}
func UpdateOrgMemberRequestToDomain(ctx context.Context, req *mgmt_pb.UpdateOrgMemberRequest) *domain.Member { func UpdateOrgMemberRequestToDomain(ctx context.Context, req *mgmt_pb.UpdateOrgMemberRequest) *domain.Member {
return domain.NewMember(authz.GetCtxData(ctx).OrgID, req.UserId, req.Roles...) return domain.NewMember(authz.GetCtxData(ctx).OrgID, req.UserId, req.Roles...)
} }

View File

@ -3,8 +3,8 @@ package login
import ( import (
"net/http" "net/http"
"github.com/caos/zitadel/internal/command"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
) )
@ -65,17 +65,8 @@ func (l *Login) handleRegisterOrgCheck(w http.ResponseWriter, r *http.Request) {
l.renderRegisterOrg(w, r, authRequest, data, err) l.renderRegisterOrg(w, r, authRequest, data, err)
return return
} }
initCodeGenerator, err := l.query.InitEncryptionGenerator(r.Context(), domain.SecretGeneratorTypePasswordlessInitCode, l.userCodeAlg) _ = userIDs //TODO: handle userIDs
if err != nil { _, err = l.command.SetUpOrg(ctx, data.toCommandOrg())
l.renderRegisterOrg(w, r, authRequest, data, err)
return
}
phoneCodeGenerator, err := l.query.InitEncryptionGenerator(r.Context(), domain.SecretGeneratorTypeVerifyPhoneCode, l.userCodeAlg)
if err != nil {
l.renderRegisterOrg(w, r, authRequest, data, err)
return
}
_, err = l.command.SetUpOrg(ctx, data.toOrgDomain(), data.toUserDomain(), initCodeGenerator, phoneCodeGenerator, userIDs, true)
if err != nil { if err != nil {
l.renderRegisterOrg(w, r, authRequest, data, err) l.renderRegisterOrg(w, r, authRequest, data, err)
return return
@ -145,8 +136,21 @@ func (d registerOrgFormData) toUserDomain() *domain.Human {
} }
} }
func (d registerOrgFormData) toOrgDomain() *domain.Org { func (d registerOrgFormData) toCommandOrg() *command.OrgSetup {
return &domain.Org{ if d.Username == "" {
d.Username = d.Email
}
return &command.OrgSetup{
Name: d.RegisterOrgName, Name: d.RegisterOrgName,
Human: command.AddHuman{
Username: d.Username,
FirstName: d.Firstname,
LastName: d.Lastname,
Email: command.Email{
Address: d.Email,
},
Password: d.Password,
Register: true,
},
} }
} }

View File

@ -30,36 +30,25 @@ type Commands struct {
iamDomain string iamDomain string
zitadelRoles []authz.RoleMapping zitadelRoles []authz.RoleMapping
idpConfigSecretCrypto crypto.EncryptionAlgorithm idpConfigEncryption crypto.EncryptionAlgorithm
smtpPasswordCrypto crypto.EncryptionAlgorithm smtpEncryption crypto.EncryptionAlgorithm
smsCrypto crypto.EncryptionAlgorithm smsEncryption crypto.EncryptionAlgorithm
userEncryption crypto.EncryptionAlgorithm
userPasswordAlg crypto.HashAlgorithm userPasswordAlg crypto.HashAlgorithm
machineKeySize int machineKeySize int
applicationKeySize int applicationKeySize int
domainVerificationAlg crypto.EncryptionAlgorithm domainVerificationAlg crypto.EncryptionAlgorithm
domainVerificationGenerator crypto.Generator domainVerificationGenerator crypto.Generator
domainVerificationValidator func(domain, token, verifier string, checkType http.CheckType) error domainVerificationValidator func(domain, token, verifier string, checkType http.CheckType) error
multifactors domain.MultifactorConfigs
multifactors domain.MultifactorConfigs
webauthn *webauthn_helper.WebAuthN webauthn *webauthn_helper.WebAuthN
keySize int keySize int
keyAlgorithm crypto.EncryptionAlgorithm keyAlgorithm crypto.EncryptionAlgorithm
privateKeyLifetime time.Duration privateKeyLifetime time.Duration
publicKeyLifetime time.Duration publicKeyLifetime time.Duration
tokenVerifier orgFeatureChecker tokenVerifier orgFeatureChecker
v2 *commandNew
}
type commandNew struct {
es *eventstore.Eventstore
userPasswordAlg crypto.HashAlgorithm
phoneAlg crypto.EncryptionAlgorithm
emailAlg crypto.EncryptionAlgorithm
initCodeAlg crypto.EncryptionAlgorithm
zitadelRoles []authz.RoleMapping
id id.Generator
} }
type orgFeatureChecker interface { type orgFeatureChecker interface {
@ -68,7 +57,7 @@ type orgFeatureChecker interface {
func StartCommands(es *eventstore.Eventstore, func StartCommands(es *eventstore.Eventstore,
defaults sd.SystemDefaults, defaults sd.SystemDefaults,
authZConfig authz.Config, zitadelRoles []authz.RoleMapping,
staticStore static.Storage, staticStore static.Storage,
authZRepo authz_repo.Repository, authZRepo authz_repo.Repository,
webAuthN webauthn_helper.Config, webAuthN webauthn_helper.Config,
@ -85,16 +74,16 @@ func StartCommands(es *eventstore.Eventstore,
static: staticStore, static: staticStore,
idGenerator: id.SonyFlakeGenerator, idGenerator: id.SonyFlakeGenerator,
iamDomain: defaults.Domain, iamDomain: defaults.Domain,
zitadelRoles: authZConfig.RolePermissionMappings, zitadelRoles: zitadelRoles,
keySize: defaults.KeyConfig.Size, keySize: defaults.KeyConfig.Size,
privateKeyLifetime: defaults.KeyConfig.PrivateKeyLifetime, privateKeyLifetime: defaults.KeyConfig.PrivateKeyLifetime,
publicKeyLifetime: defaults.KeyConfig.PublicKeyLifetime, publicKeyLifetime: defaults.KeyConfig.PublicKeyLifetime,
idpConfigSecretCrypto: idpConfigEncryption, idpConfigEncryption: idpConfigEncryption,
smtpPasswordCrypto: smtpEncryption, smtpEncryption: smtpEncryption,
smsCrypto: smsEncryption, smsEncryption: smsEncryption,
userEncryption: userEncryption,
domainVerificationAlg: domainVerificationEncryption, domainVerificationAlg: domainVerificationEncryption,
keyAlgorithm: oidcEncryption, keyAlgorithm: oidcEncryption,
v2: NewCommandV2(es, defaults, userEncryption, authZConfig.RolePermissionMappings),
} }
instance_repo.RegisterEventMappers(repo.eventstore) instance_repo.RegisterEventMappers(repo.eventstore)
@ -128,31 +117,6 @@ func StartCommands(es *eventstore.Eventstore,
return repo, nil return repo, nil
} }
func NewCommandV2(
es *eventstore.Eventstore,
defaults sd.SystemDefaults,
userAlg crypto.EncryptionAlgorithm,
zitadelRoles []authz.RoleMapping,
) *commandNew {
instance_repo.RegisterEventMappers(es)
org.RegisterEventMappers(es)
usr_repo.RegisterEventMappers(es)
usr_grant_repo.RegisterEventMappers(es)
proj_repo.RegisterEventMappers(es)
keypair.RegisterEventMappers(es)
action.RegisterEventMappers(es)
return &commandNew{
es: es,
userPasswordAlg: crypto.NewBCrypt(defaults.SecretGenerators.PasswordSaltCost),
initCodeAlg: userAlg,
phoneAlg: userAlg,
emailAlg: userAlg,
zitadelRoles: zitadelRoles,
id: id.SonyFlakeGenerator,
}
}
func AppendAndReduce(object interface { func AppendAndReduce(object interface {
AppendEvents(...eventstore.Event) AppendEvents(...eventstore.Event)
Reduce() error Reduce() error

View File

@ -158,13 +158,13 @@ func (s *InstanceSetup) generateIDs() (err error) {
return nil return nil
} }
func (c *commandNew) SetUpInstance(ctx context.Context, setup *InstanceSetup) (*domain.ObjectDetails, error) { func (c *Commands) SetUpInstance(ctx context.Context, setup *InstanceSetup) (*domain.ObjectDetails, error) {
instanceID, err := id.SonyFlakeGenerator.Next() instanceID, err := id.SonyFlakeGenerator.Next()
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err = c.es.NewInstance(ctx, instanceID); err != nil { if err = c.eventstore.NewInstance(ctx, instanceID); err != nil {
return nil, err return nil, err
} }
@ -189,7 +189,7 @@ func (c *commandNew) SetUpInstance(ctx context.Context, setup *InstanceSetup) (*
setup.Org.Human.PasswordChangeRequired = true setup.Org.Human.PasswordChangeRequired = true
instanceAgg := instance.NewAggregate(instanceID) instanceAgg := instance.NewAggregate(instanceID)
orgAgg := org.NewAggregate(orgID, orgID) orgAgg := org.NewAggregate(orgID)
userAgg := user.NewAggregate(userID, orgID) userAgg := user.NewAggregate(userID, orgID)
projectAgg := project.NewAggregate(setup.Zitadel.projectID, orgID) projectAgg := project.NewAggregate(setup.Zitadel.projectID, orgID)
@ -312,9 +312,9 @@ func (c *commandNew) SetUpInstance(ctx context.Context, setup *InstanceSetup) (*
validations = append(validations, validations = append(validations,
AddOrgCommand(ctx, orgAgg, setup.Org.Name), AddOrgCommand(ctx, orgAgg, setup.Org.Name),
addHumanCommand(userAgg, &setup.Org.Human, c.userPasswordAlg, c.phoneAlg, c.emailAlg, c.initCodeAlg), AddHumanCommand(userAgg, &setup.Org.Human, c.userPasswordAlg, c.smsEncryption, c.smtpEncryption, c.userEncryption),
c.AddOrgMember(orgAgg, userID, domain.RoleOrgOwner), c.AddOrgMemberCommand(orgAgg, userID, domain.RoleOrgOwner),
c.AddInstanceMember(instanceAgg, userID, domain.RoleIAMOwner), c.AddInstanceMemberCommand(instanceAgg, userID, domain.RoleIAMOwner),
AddProjectCommand(projectAgg, zitadelProjectName, userID, false, false, false, domain.PrivateLabelingSettingUnspecified), AddProjectCommand(projectAgg, zitadelProjectName, userID, false, false, false, domain.PrivateLabelingSettingUnspecified),
SetIAMProject(instanceAgg, projectAgg.ID), SetIAMProject(instanceAgg, projectAgg.ID),
@ -359,12 +359,12 @@ func (c *commandNew) SetUpInstance(ctx context.Context, setup *InstanceSetup) (*
SetIAMConsoleID(instanceAgg, &console.ClientID, &setup.Zitadel.consoleAppID), SetIAMConsoleID(instanceAgg, &console.ClientID, &setup.Zitadel.consoleAppID),
) )
cmds, err := preparation.PrepareCommands(ctx, c.es.Filter, validations...) cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, validations...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
events, err := c.es.Push(ctx, cmds...) events, err := c.eventstore.Push(ctx, cmds...)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -37,7 +37,7 @@ func (c *Commands) AddDefaultIDPConfig(ctx context.Context, config *domain.IDPCo
), ),
} }
if config.OIDCConfig != nil { if config.OIDCConfig != nil {
clientSecret, err := crypto.Encrypt([]byte(config.OIDCConfig.ClientSecretString), c.idpConfigSecretCrypto) clientSecret, err := crypto.Encrypt([]byte(config.OIDCConfig.ClientSecretString), c.idpConfigEncryption)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -4,10 +4,10 @@ import (
"context" "context"
"testing" "testing"
"github.com/caos/zitadel/internal/api/authz"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
@ -201,7 +201,7 @@ func TestCommandSide_AddDefaultIDPConfig(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
idGenerator: tt.fields.idGenerator, idGenerator: tt.fields.idGenerator,
idpConfigSecretCrypto: tt.fields.secretCrypto, idpConfigEncryption: tt.fields.secretCrypto,
} }
got, err := r.AddDefaultIDPConfig(tt.args.ctx, tt.args.config) got, err := r.AddDefaultIDPConfig(tt.args.ctx, tt.args.config)
if tt.res.err == nil { if tt.res.err == nil {

View File

@ -239,7 +239,7 @@ func TestCommandSide_ChangeDefaultIDPJWTConfig(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
idpConfigSecretCrypto: tt.fields.secretCrypto, idpConfigEncryption: tt.fields.secretCrypto,
} }
got, err := r.ChangeDefaultIDPJWTConfig(tt.args.ctx, tt.args.config) got, err := r.ChangeDefaultIDPJWTConfig(tt.args.ctx, tt.args.config)
if tt.res.err == nil { if tt.res.err == nil {

View File

@ -31,7 +31,7 @@ func (c *Commands) ChangeDefaultIDPOIDCConfig(ctx context.Context, config *domai
config.AuthorizationEndpoint, config.AuthorizationEndpoint,
config.TokenEndpoint, config.TokenEndpoint,
config.ClientSecretString, config.ClientSecretString,
c.idpConfigSecretCrypto, c.idpConfigEncryption,
config.IDPDisplayNameMapping, config.IDPDisplayNameMapping,
config.UsernameMapping, config.UsernameMapping,
config.Scopes...) config.Scopes...)

View File

@ -285,7 +285,7 @@ func TestCommandSide_ChangeDefaultIDPOIDCConfig(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
idpConfigSecretCrypto: tt.fields.secretCrypto, idpConfigEncryption: tt.fields.secretCrypto,
} }
got, err := r.ChangeDefaultIDPOIDCConfig(tt.args.ctx, tt.args.config) got, err := r.ChangeDefaultIDPOIDCConfig(tt.args.ctx, tt.args.config)
if tt.res.err == nil { if tt.res.err == nil {

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"reflect" "reflect"
"github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/command/preparation" "github.com/caos/zitadel/internal/command/preparation"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/errors"
@ -13,7 +14,7 @@ import (
"github.com/caos/zitadel/internal/telemetry/tracing" "github.com/caos/zitadel/internal/telemetry/tracing"
) )
func (c *commandNew) AddInstanceMember(a *instance.Aggregate, userID string, roles ...string) preparation.Validation { func (c *Commands) AddInstanceMemberCommand(a *instance.Aggregate, userID string, roles ...string) preparation.Validation {
return func() (preparation.CreateCommands, error) { return func() (preparation.CreateCommands, error) {
if userID == "" { if userID == "" {
return nil, errors.ThrowInvalidArgument(nil, "INSTA-SDSfs", "Errors.Invalid.Argument") return nil, errors.ThrowInvalidArgument(nil, "INSTA-SDSfs", "Errors.Invalid.Argument")
@ -23,7 +24,7 @@ func (c *commandNew) AddInstanceMember(a *instance.Aggregate, userID string, rol
} }
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) { return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
if exists, err := ExistsUser(ctx, filter, userID, ""); err != nil || !exists { if exists, err := ExistsUser(ctx, filter, userID, ""); err != nil || !exists {
return nil, errors.ThrowNotFound(err, "INSTA-GSXOn", "Errors.User.NotFound") return nil, errors.ThrowPreconditionFailed(err, "INSTA-GSXOn", "Errors.User.NotFound")
} }
if isMember, err := IsInstanceMember(ctx, filter, a.ID, userID); err != nil || isMember { if isMember, err := IsInstanceMember(ctx, filter, a.ID, userID); err != nil || isMember {
return nil, errors.ThrowAlreadyExists(err, "INSTA-pFDwe", "Errors.Instance.Member.AlreadyExists") return nil, errors.ThrowAlreadyExists(err, "INSTA-pFDwe", "Errors.Instance.Member.AlreadyExists")
@ -69,50 +70,24 @@ func IsInstanceMember(ctx context.Context, filter preparation.FilterToQueryReduc
return isMember, nil return isMember, nil
} }
func (c *Commands) AddInstanceMember(ctx context.Context, member *domain.Member) (*domain.Member, error) { func (c *Commands) AddInstanceMember(ctx context.Context, userID string, roles ...string) (*domain.Member, error) {
if member.UserID == "" { instanceAgg := instance.NewAggregate(authz.GetInstance(ctx).InstanceID())
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-Mf83b", "Errors.IAM.MemberInvalid") cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, c.AddInstanceMemberCommand(instanceAgg, userID, roles...))
}
addedMember := NewInstanceMemberWriteModel(ctx, member.UserID)
instanceAgg := InstanceAggregateFromWriteModel(&addedMember.MemberWriteModel.WriteModel)
err := c.checkUserExists(ctx, addedMember.UserID, "")
if err != nil {
return nil, caos_errs.ThrowPreconditionFailed(err, "INSTANCE-5N9vs", "Errors.User.NotFound")
}
event, err := c.addInstanceMember(ctx, instanceAgg, addedMember, member)
if err != nil { if err != nil {
return nil, err return nil, err
} }
events, err := c.eventstore.Push(ctx, cmds...)
pushedEvents, err := c.eventstore.Push(ctx, event)
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = AppendAndReduce(addedMember, pushedEvents...) addedMember := NewInstanceMemberWriteModel(ctx, userID)
err = AppendAndReduce(addedMember, events...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return memberWriteModelToMember(&addedMember.MemberWriteModel), nil return memberWriteModelToMember(&addedMember.MemberWriteModel), nil
} }
func (c *Commands) addInstanceMember(ctx context.Context, instanceAgg *eventstore.Aggregate, addedMember *InstanceMemberWriteModel, member *domain.Member) (eventstore.Command, error) {
if !member.IsIAMValid() {
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-GR34U", "Errors.IAM.MemberInvalid")
}
if len(domain.CheckForInvalidRoles(member.Roles, domain.IAMRolePrefix, c.zitadelRoles)) > 0 {
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-4m0fS", "Errors.IAM.MemberInvalid")
}
err := c.eventstore.FilterToQueryReducer(ctx, addedMember)
if err != nil {
return nil, err
}
if addedMember.State == domain.MemberStateActive {
return nil, errors.ThrowAlreadyExists(nil, "INSTANCE-sdgQ4", "Errors.IAM.Member.AlreadyExists")
}
return instance.NewMemberAddedEvent(ctx, instanceAgg, member.UserID, member.Roles...), nil
}
//ChangeInstanceMember updates an existing member //ChangeInstanceMember updates an existing member
func (c *Commands) ChangeInstanceMember(ctx context.Context, member *domain.Member) (*domain.Member, error) { func (c *Commands) ChangeInstanceMember(ctx context.Context, member *domain.Member) (*domain.Member, error) {
if !member.IsIAMValid() { if !member.IsIAMValid() {

View File

@ -4,6 +4,11 @@ import (
"context" "context"
"testing" "testing"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
"github.com/caos/zitadel/internal/repository/user"
"github.com/caos/zitadel/internal/api/authz" "github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
@ -12,9 +17,6 @@ import (
"github.com/caos/zitadel/internal/eventstore/v1/models" "github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/repository/instance" "github.com/caos/zitadel/internal/repository/instance"
"github.com/caos/zitadel/internal/repository/member" "github.com/caos/zitadel/internal/repository/member"
"github.com/caos/zitadel/internal/repository/user"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
) )
func TestCommandSide_AddIAMMember(t *testing.T) { func TestCommandSide_AddIAMMember(t *testing.T) {
@ -24,7 +26,8 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
} }
type args struct { type args struct {
ctx context.Context ctx context.Context
member *domain.Member userID string
roles []string
} }
type res struct { type res struct {
want *domain.Member want *domain.Member
@ -45,7 +48,22 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
}, },
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
member: &domain.Member{}, },
res: res{
err: caos_errs.IsErrorInvalidArgument,
},
},
{
name: "invalid roles, error",
fields: fields{
eventstore: eventstoreExpect(
t,
),
},
args: args{
ctx: context.Background(),
userID: "user1",
roles: []string{"IAM_OWNER"},
}, },
res: res{ res: res{
err: caos_errs.IsErrorInvalidArgument, err: caos_errs.IsErrorInvalidArgument,
@ -58,52 +76,21 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
t, t,
expectFilter(), expectFilter(),
), ),
zitadelRoles: []authz.RoleMapping{
{
Role: "IAM_OWNER",
},
},
}, },
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
member: &domain.Member{ userID: "user1",
UserID: "user1", roles: []string{"IAM_OWNER"},
Roles: []string{"IAM_OWNER"},
},
}, },
res: res{ res: res{
err: caos_errs.IsPreconditionFailed, err: caos_errs.IsPreconditionFailed,
}, },
}, },
{
name: "invalid roles, error",
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username1",
"firstname1",
"lastname1",
"nickname1",
"displayname1",
language.German,
domain.GenderMale,
"email1",
true,
),
),
),
),
},
args: args{
ctx: context.Background(),
member: &domain.Member{
UserID: "user1",
Roles: []string{"IAM_OWNER"},
},
},
res: res{
err: caos_errs.IsErrorInvalidArgument,
},
},
{ {
name: "member already exists, precondition error", name: "member already exists, precondition error",
fields: fields{ fields: fields{
@ -142,10 +129,8 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
}, },
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
member: &domain.Member{ userID: "user1",
UserID: "user1", roles: []string{"IAM_OWNER"},
Roles: []string{"IAM_OWNER"},
},
}, },
res: res{ res: res{
err: caos_errs.IsErrorAlreadyExists, err: caos_errs.IsErrorAlreadyExists,
@ -192,10 +177,8 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
}, },
args: args{ args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"), ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
member: &domain.Member{ userID: "user1",
UserID: "user1", roles: []string{"IAM_OWNER"},
Roles: []string{"IAM_OWNER"},
},
}, },
res: res{ res: res{
err: caos_errs.IsErrorAlreadyExists, err: caos_errs.IsErrorAlreadyExists,
@ -245,10 +228,8 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
}, },
args: args{ args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"), ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
member: &domain.Member{ userID: "user1",
UserID: "user1", roles: []string{"IAM_OWNER"},
Roles: []string{"IAM_OWNER"},
},
}, },
res: res{ res: res{
want: &domain.Member{ want: &domain.Member{
@ -269,7 +250,7 @@ func TestCommandSide_AddIAMMember(t *testing.T) {
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
zitadelRoles: tt.fields.zitadelRoles, zitadelRoles: tt.fields.zitadelRoles,
} }
got, err := r.AddInstanceMember(tt.args.ctx, tt.args.member) got, err := r.AddInstanceMember(tt.args.ctx, tt.args.userID, tt.args.roles...)
if tt.res.err == nil { if tt.res.err == nil {
assert.NoError(t, err) assert.NoError(t, err)
} }

View File

@ -3,43 +3,72 @@ package command
import ( import (
"context" "context"
"github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/command/preparation"
"github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/instance" "github.com/caos/zitadel/internal/repository/instance"
) )
func (c *Commands) AddSecretGeneratorConfig(ctx context.Context, generatorType domain.SecretGeneratorType, config *crypto.GeneratorConfig) (*domain.ObjectDetails, error) { func (c *Commands) AddSecretGeneratorConfig(ctx context.Context, typ domain.SecretGeneratorType, config *crypto.GeneratorConfig) (*domain.ObjectDetails, error) {
if generatorType == domain.SecretGeneratorTypeUnspecified { agg := instance.NewAggregate(authz.GetInstance(ctx).InstanceID())
return nil, caos_errs.ThrowInvalidArgument(nil, "COMMAND-0pkwf", "Errors.SecretGenerator.TypeMissing") cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, addSecretGeneratorConfig(agg, typ, config))
}
generatorWriteModel, err := c.getSecretConfig(ctx, generatorType)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if generatorWriteModel.State == domain.SecretGeneratorStateActive {
return nil, caos_errs.ThrowAlreadyExists(nil, "COMMAND-3n9ls", "Errors.SecretGenerator.AlreadyExists") events, err := c.eventstore.Push(ctx, cmds...)
if err != nil {
return nil, err
} }
instanceAgg := InstanceAggregateFromWriteModel(&generatorWriteModel.WriteModel) return &domain.ObjectDetails{
pushedEvents, err := c.eventstore.Push(ctx, instance.NewSecretGeneratorAddedEvent( Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
ResourceOwner: agg.ResourceOwner,
}, nil
}
func addSecretGeneratorConfig(a *instance.Aggregate, typ domain.SecretGeneratorType, config *crypto.GeneratorConfig) preparation.Validation {
return func() (preparation.CreateCommands, error) {
if !typ.Valid() {
return nil, errors.ThrowInvalidArgument(nil, "V2-FGqVj", "Errors.InvalidArgument")
}
if config.Length < 1 {
return nil, errors.ThrowInvalidArgument(nil, "V2-jEqCt", "Errors.InvalidArgument")
}
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
writeModel := NewInstanceSecretGeneratorConfigWriteModel(ctx, typ)
events, err := filter(ctx, writeModel.Query())
if err != nil {
return nil, err
}
writeModel.AppendEvents(events...)
if err = writeModel.Reduce(); err != nil {
return nil, err
}
if writeModel.State == domain.SecretGeneratorStateActive {
return nil, errors.ThrowAlreadyExists(nil, "V2-6CqKo", "Errors.SecretGenerator.AlreadyExists")
}
return []eventstore.Command{
instance.NewSecretGeneratorAddedEvent(
ctx, ctx,
instanceAgg, &a.Aggregate,
generatorType, typ,
config.Length, config.Length,
config.Expiry, config.Expiry,
config.IncludeLowerLetters, config.IncludeLowerLetters,
config.IncludeUpperLetters, config.IncludeUpperLetters,
config.IncludeDigits, config.IncludeDigits,
config.IncludeSymbols)) config.IncludeSymbols,
if err != nil { ),
return nil, err }, nil
}, nil
} }
err = AppendAndReduce(generatorWriteModel, pushedEvents...)
if err != nil {
return nil, err
}
return writeModelToObjectDetails(&generatorWriteModel.WriteModel), nil
} }
func (c *Commands) ChangeSecretGeneratorConfig(ctx context.Context, generatorType domain.SecretGeneratorType, config *crypto.GeneratorConfig) (*domain.ObjectDetails, error) { func (c *Commands) ChangeSecretGeneratorConfig(ctx context.Context, generatorType domain.SecretGeneratorType, config *crypto.GeneratorConfig) (*domain.ObjectDetails, error) {

View File

@ -21,7 +21,7 @@ type OrgSetup struct {
Human AddHuman Human AddHuman
} }
func (c *commandNew) SetUpOrg(ctx context.Context, o *OrgSetup) (*domain.ObjectDetails, error) { func (c *Commands) SetUpOrg(ctx context.Context, o *OrgSetup) (*domain.ObjectDetails, error) {
orgID, err := id.SonyFlakeGenerator.Next() orgID, err := id.SonyFlakeGenerator.Next()
if err != nil { if err != nil {
return nil, err return nil, err
@ -32,19 +32,19 @@ func (c *commandNew) SetUpOrg(ctx context.Context, o *OrgSetup) (*domain.ObjectD
return nil, err return nil, err
} }
orgAgg := org.NewAggregate(orgID, orgID) orgAgg := org.NewAggregate(orgID)
userAgg := user_repo.NewAggregate(userID, orgID) userAgg := user_repo.NewAggregate(userID, orgID)
cmds, err := preparation.PrepareCommands(ctx, c.es.Filter, cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter,
AddOrgCommand(ctx, orgAgg, o.Name), AddOrgCommand(ctx, orgAgg, o.Name),
addHumanCommand(userAgg, &o.Human, c.userPasswordAlg, c.phoneAlg, c.emailAlg, c.initCodeAlg), AddHumanCommand(userAgg, &o.Human, c.userPasswordAlg, c.smsEncryption, c.smtpEncryption, c.userEncryption),
c.AddOrgMember(orgAgg, userID, domain.RoleOrgOwner), c.AddOrgMemberCommand(orgAgg, userID, domain.RoleOrgOwner),
) )
if err != nil { if err != nil {
return nil, err return nil, err
} }
events, err := c.es.Push(ctx, cmds...) events, err := c.eventstore.Push(ctx, cmds...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -96,31 +96,6 @@ func (c *Commands) checkOrgExists(ctx context.Context, orgID string) error {
return nil return nil
} }
func (c *Commands) SetUpOrg(ctx context.Context, organisation *domain.Org, admin *domain.Human, initCodeGenerator, phoneCodeGenerator crypto.Generator, claimedUserIDs []string, selfregistered bool) (*domain.ObjectDetails, error) {
domainPolicy, err := c.getDefaultDomainPolicy(ctx)
if err != nil {
return nil, caos_errs.ThrowPreconditionFailed(err, "COMMAND-33M9f", "Errors.Instance.DomainPolicy.NotFound")
}
pwPolicy, err := c.getDefaultPasswordComplexityPolicy(ctx)
if err != nil {
return nil, caos_errs.ThrowPreconditionFailed(err, "COMMAND-M5Fsd", "Errors.Instance.PasswordComplexity.NotFound")
}
_, orgWriteModel, _, _, events, err := c.setUpOrg(ctx, organisation, admin, domainPolicy, pwPolicy, initCodeGenerator, phoneCodeGenerator, claimedUserIDs, selfregistered)
if err != nil {
return nil, err
}
pushedEvents, err := c.eventstore.Push(ctx, events...)
if err != nil {
return nil, err
}
err = AppendAndReduce(orgWriteModel, pushedEvents...)
if err != nil {
return nil, err
}
return writeModelToObjectDetails(&orgWriteModel.WriteModel), nil
}
func (c *Commands) AddOrg(ctx context.Context, name, userID, resourceOwner string, claimedUserIDs []string) (*domain.Org, error) { func (c *Commands) AddOrg(ctx context.Context, name, userID, resourceOwner string, claimedUserIDs []string) (*domain.Org, error) {
orgAgg, addedOrg, events, err := c.addOrg(ctx, &domain.Org{Name: name}, claimedUserIDs) orgAgg, addedOrg, events, err := c.addOrg(ctx, &domain.Org{Name: name}, claimedUserIDs)
if err != nil { if err != nil {

View File

@ -181,7 +181,7 @@ func (c *Commands) DeleteAction(ctx context.Context, actionID, resourceOwner str
events := []eventstore.Command{ events := []eventstore.Command{
action.NewRemovedEvent(ctx, actionAgg, existingAction.Name), action.NewRemovedEvent(ctx, actionAgg, existingAction.Name),
} }
orgAgg := org.NewAggregate(resourceOwner, resourceOwner).Aggregate orgAgg := org.NewAggregate(resourceOwner).Aggregate
for _, flowType := range flowTypes { for _, flowType := range flowTypes {
events = append(events, org.NewTriggerActionsCascadeRemovedEvent(ctx, &orgAgg, flowType, actionID)) events = append(events, org.NewTriggerActionsCascadeRemovedEvent(ctx, &orgAgg, flowType, actionID))
} }

View File

@ -64,7 +64,7 @@ func TestCommands_AddAction(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
func() eventstore.Command { func() eventstore.Command {
e, _ := org.NewFeaturesSetEvent(context.Background(), e, _ := org.NewFeaturesSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]features.FeaturesChanges{ []features.FeaturesChanges{
features.ChangeMaxActions(1), features.ChangeMaxActions(1),
}, },
@ -106,7 +106,7 @@ func TestCommands_AddAction(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
func() eventstore.Command { func() eventstore.Command {
e, _ := org.NewFeaturesSetEvent(context.Background(), e, _ := org.NewFeaturesSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]features.FeaturesChanges{ []features.FeaturesChanges{
features.ChangeMaxActions(2), features.ChangeMaxActions(2),
}, },
@ -164,7 +164,7 @@ func TestCommands_AddAction(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
func() eventstore.Command { func() eventstore.Command {
e, _ := org.NewFeaturesSetEvent(context.Background(), e, _ := org.NewFeaturesSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]features.FeaturesChanges{ []features.FeaturesChanges{
features.ChangeMaxActions(2), features.ChangeMaxActions(2),
}, },
@ -687,7 +687,7 @@ func TestCommands_ReactivateAction(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
func() eventstore.Command { func() eventstore.Command {
e, _ := org.NewFeaturesSetEvent(context.Background(), e, _ := org.NewFeaturesSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]features.FeaturesChanges{ []features.FeaturesChanges{
features.ChangeMaxActions(1), features.ChangeMaxActions(1),
}, },
@ -742,7 +742,7 @@ func TestCommands_ReactivateAction(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
func() eventstore.Command { func() eventstore.Command {
e, _ := org.NewFeaturesSetEvent(context.Background(), e, _ := org.NewFeaturesSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]features.FeaturesChanges{ []features.FeaturesChanges{
features.ChangeMaxActions(1), features.ChangeMaxActions(1),
}, },
@ -923,7 +923,7 @@ func TestCommands_DeleteAction(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewTriggerActionsCascadeRemovedEvent(context.Background(), org.NewTriggerActionsCascadeRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication, domain.FlowTypeExternalAuthentication,
"id1", "id1",
), ),

View File

@ -15,7 +15,7 @@ func (c *Commands) SetOrgLoginText(ctx context.Context, resourceOwner string, lo
if resourceOwner == "" { if resourceOwner == "" {
return nil, caos_errs.ThrowInvalidArgument(nil, "ORG-m29rF", "Errors.ResourceOwnerMissing") return nil, caos_errs.ThrowInvalidArgument(nil, "ORG-m29rF", "Errors.ResourceOwnerMissing")
} }
iamAgg := org.NewAggregate(resourceOwner, resourceOwner) iamAgg := org.NewAggregate(resourceOwner)
events, existingLoginText, err := c.setOrgLoginText(ctx, &iamAgg.Aggregate, loginText) events, existingLoginText, err := c.setOrgLoginText(ctx, &iamAgg.Aggregate, loginText)
if err != nil { if err != nil {
return nil, err return nil, err

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ func (c *Commands) SetOrgMessageText(ctx context.Context, resourceOwner string,
if resourceOwner == "" { if resourceOwner == "" {
return nil, caos_errs.ThrowInvalidArgument(nil, "ORG-2biiR", "Errors.ResourceOwnerMissing") return nil, caos_errs.ThrowInvalidArgument(nil, "ORG-2biiR", "Errors.ResourceOwnerMissing")
} }
orgAgg := org.NewAggregate(resourceOwner, resourceOwner) orgAgg := org.NewAggregate(resourceOwner)
events, existingMessageText, err := c.setOrgMessageText(ctx, &orgAgg.Aggregate, messageText) events, existingMessageText, err := c.setOrgMessageText(ctx, &orgAgg.Aggregate, messageText)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -74,7 +74,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageGreeting, domain.MessageGreeting,
"Greeting", "Greeting",
@ -83,7 +83,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageSubject, domain.MessageSubject,
"Subject", "Subject",
@ -92,7 +92,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageTitle, domain.MessageTitle,
"Title", "Title",
@ -101,7 +101,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessagePreHeader, domain.MessagePreHeader,
"PreHeader", "PreHeader",
@ -110,7 +110,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageText, domain.MessageText,
"Text", "Text",
@ -119,7 +119,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageButtonText, domain.MessageButtonText,
"ButtonText", "ButtonText",
@ -128,7 +128,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageFooterText, domain.MessageFooterText,
"Footer", "Footer",
@ -168,7 +168,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageGreeting, domain.MessageGreeting,
"Greeting", "Greeting",
@ -177,7 +177,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageSubject, domain.MessageSubject,
"Subject", "Subject",
@ -186,7 +186,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageTitle, domain.MessageTitle,
"Title", "Title",
@ -195,7 +195,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessagePreHeader, domain.MessagePreHeader,
"PreHeader", "PreHeader",
@ -204,7 +204,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageText, domain.MessageText,
"Text", "Text",
@ -213,7 +213,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageButtonText, domain.MessageButtonText,
"ButtonText", "ButtonText",
@ -222,7 +222,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageFooterText, domain.MessageFooterText,
"Footer", "Footer",
@ -234,7 +234,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(), org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageGreeting, domain.MessageGreeting,
language.English, language.English,
@ -242,7 +242,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(), org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageSubject, domain.MessageSubject,
language.English, language.English,
@ -250,7 +250,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(), org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageTitle, domain.MessageTitle,
language.English, language.English,
@ -258,7 +258,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(), org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessagePreHeader, domain.MessagePreHeader,
language.English, language.English,
@ -266,7 +266,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(), org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageText, domain.MessageText,
language.English, language.English,
@ -274,7 +274,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(), org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageButtonText, domain.MessageButtonText,
language.English, language.English,
@ -282,7 +282,7 @@ func TestCommandSide_SetCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextRemovedEvent(context.Background(), org.NewCustomTextRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageFooterText, domain.MessageFooterText,
language.English, language.English,
@ -409,7 +409,7 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageGreeting, domain.MessageGreeting,
"Greeting", "Greeting",
@ -418,7 +418,7 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageSubject, domain.MessageSubject,
"Subject", "Subject",
@ -427,7 +427,7 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageTitle, domain.MessageTitle,
"Title", "Title",
@ -436,7 +436,7 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessagePreHeader, domain.MessagePreHeader,
"PreHeader", "PreHeader",
@ -445,7 +445,7 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageText, domain.MessageText,
"Text", "Text",
@ -454,7 +454,7 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageButtonText, domain.MessageButtonText,
"ButtonText", "ButtonText",
@ -463,7 +463,7 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextSetEvent(context.Background(), org.NewCustomTextSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
domain.MessageFooterText, domain.MessageFooterText,
"Footer", "Footer",
@ -475,7 +475,7 @@ func TestCommandSide_RemoveCustomMessageText(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextTemplateRemovedEvent(context.Background(), org.NewCustomTextTemplateRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"Template", "Template",
language.English, language.English,
), ),

View File

@ -29,7 +29,7 @@ func TestAddDomain(t *testing.T) {
filter preparation.FilterToQueryReducer filter preparation.FilterToQueryReducer
} }
agg := org.NewAggregate("test", "test") agg := org.NewAggregate("test")
tests := []struct { tests := []struct {
name string name string
@ -120,7 +120,7 @@ func TestVerifyDomain(t *testing.T) {
{ {
name: "invalid domain", name: "invalid domain",
args: args{ args: args{
a: org.NewAggregate("test", "test"), a: org.NewAggregate("test"),
domain: "", domain: "",
}, },
want: Want{ want: Want{
@ -130,12 +130,12 @@ func TestVerifyDomain(t *testing.T) {
{ {
name: "correct", name: "correct",
args: args{ args: args{
a: org.NewAggregate("test", "test"), a: org.NewAggregate("test"),
domain: "domain", domain: "domain",
}, },
want: Want{ want: Want{
Commands: []eventstore.Command{ Commands: []eventstore.Command{
org.NewDomainVerifiedEvent(context.Background(), &org.NewAggregate("test", "test").Aggregate, "domain"), org.NewDomainVerifiedEvent(context.Background(), &org.NewAggregate("test").Aggregate, "domain"),
}, },
}, },
}, },
@ -154,7 +154,7 @@ func TestSetDomainPrimary(t *testing.T) {
filter preparation.FilterToQueryReducer filter preparation.FilterToQueryReducer
} }
agg := org.NewAggregate("test", "test") agg := org.NewAggregate("test")
tests := []struct { tests := []struct {
name string name string
@ -284,13 +284,13 @@ func TestCommandSide_AddOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -318,7 +318,7 @@ func TestCommandSide_AddOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
@ -326,7 +326,7 @@ func TestCommandSide_AddOrgDomain(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(), eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
)), )),
}, },
@ -456,7 +456,7 @@ func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
@ -485,19 +485,19 @@ func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -526,13 +526,13 @@ func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -540,7 +540,7 @@ func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainVerificationAddedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
domain.OrgDomainValidationTypeDNS, domain.OrgDomainValidationTypeDNS,
&crypto.CryptoValue{ &crypto.CryptoValue{
@ -578,13 +578,13 @@ func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -592,7 +592,7 @@ func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainVerificationAddedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
domain.OrgDomainValidationTypeHTTP, domain.OrgDomainValidationTypeHTTP,
&crypto.CryptoValue{ &crypto.CryptoValue{
@ -711,7 +711,7 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
@ -740,19 +740,19 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -781,13 +781,13 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -816,19 +816,19 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerificationAddedEvent(context.Background(), org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
domain.OrgDomainValidationTypeDNS, domain.OrgDomainValidationTypeDNS,
&crypto.CryptoValue{ &crypto.CryptoValue{
@ -843,7 +843,7 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainVerificationFailedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerificationFailedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
)), )),
}, },
@ -874,19 +874,19 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerificationAddedEvent(context.Background(), org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
domain.OrgDomainValidationTypeDNS, domain.OrgDomainValidationTypeDNS,
&crypto.CryptoValue{ &crypto.CryptoValue{
@ -901,7 +901,7 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
)), )),
}, },
@ -935,19 +935,19 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerificationAddedEvent(context.Background(), org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
domain.OrgDomainValidationTypeDNS, domain.OrgDomainValidationTypeDNS,
&crypto.CryptoValue{ &crypto.CryptoValue{
@ -963,7 +963,7 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
)), )),
}, },
@ -998,19 +998,19 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerificationAddedEvent(context.Background(), org.NewDomainVerificationAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
domain.OrgDomainValidationTypeDNS, domain.OrgDomainValidationTypeDNS,
&crypto.CryptoValue{ &crypto.CryptoValue{
@ -1041,12 +1041,12 @@ func TestCommandSide_ValidateOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
false, false))), false, false))),
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
)), )),
eventFromEventPusher(user.NewDomainClaimedEvent(context.Background(), eventFromEventPusher(user.NewDomainClaimedEvent(context.Background(),
@ -1169,7 +1169,7 @@ func TestCommandSide_SetPrimaryDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
@ -1198,13 +1198,13 @@ func TestCommandSide_SetPrimaryDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -1232,19 +1232,19 @@ func TestCommandSide_SetPrimaryDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -1252,7 +1252,7 @@ func TestCommandSide_SetPrimaryDomain(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(), eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
)), )),
}, },
@ -1356,7 +1356,7 @@ func TestCommandSide_RemoveOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
@ -1385,25 +1385,25 @@ func TestCommandSide_RemoveOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent(context.Background(), org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -1431,13 +1431,13 @@ func TestCommandSide_RemoveOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -1445,7 +1445,7 @@ func TestCommandSide_RemoveOrgDomain(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(), eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", false, "domain.ch", false,
)), )),
}, },
@ -1475,19 +1475,19 @@ func TestCommandSide_RemoveOrgDomain(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"name", "name",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", "domain.ch",
), ),
), ),
@ -1495,7 +1495,7 @@ func TestCommandSide_RemoveOrgDomain(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(), eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"domain.ch", true, "domain.ch", true,
)), )),
}, },

View File

@ -149,7 +149,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
@ -210,28 +210,28 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
@ -333,7 +333,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
@ -394,49 +394,49 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test1", "test1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test1", "test1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test2", "test2",
), ),
), ),
@ -491,10 +491,10 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "test1", true), org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "test1", true),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "test2", false), org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "test2", false),
), ),
eventFromEventPusher( eventFromEventPusher(
newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour), newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour),
@ -543,7 +543,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
@ -604,56 +604,56 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test1", "test1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test1", "test1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test1.iam-domain", "test1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test2", "test2",
), ),
), ),
@ -708,13 +708,13 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "org1.iam-domain"), org.NewDomainPrimarySetEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "org1.iam-domain"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "test1", true), org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "test1", true),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "test2", false), org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "test2", false),
), ),
eventFromEventPusher( eventFromEventPusher(
newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour), newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour),
@ -763,7 +763,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
@ -824,63 +824,63 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test1", "test1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test1", "test1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test1.iam-domain", "test1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test2", "test2",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainRemovedEvent( org.NewDomainRemovedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", true, "org1.iam-domain", true,
), ),
), ),
@ -935,16 +935,16 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "org1.iam-domain"), org.NewDomainAddedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "org1.iam-domain"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "org1.iam-domain"), org.NewDomainPrimarySetEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "org1.iam-domain"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "test1", true), org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "test1", true),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, "test2", false), org.NewDomainRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "test2", false),
), ),
eventFromEventPusher( eventFromEventPusher(
newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour), newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour),
@ -994,7 +994,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
@ -1070,7 +1070,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
instance.NewLoginPolicyMultiFactorAddedEvent(context.Background(), &instance.NewAggregate("INSTANCE").Aggregate, domain.MultiFactorTypeU2FWithPIN), instance.NewLoginPolicyMultiFactorAddedEvent(context.Background(), &instance.NewAggregate("INSTANCE").Aggregate, domain.MultiFactorTypeU2FWithPIN),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, domain.SecondFactorTypeOTP), org.NewLoginPolicySecondFactorAddedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, domain.SecondFactorTypeOTP),
), ),
), ),
//addSecondFactorToLoginPolicy //addSecondFactorToLoginPolicy
@ -1151,28 +1151,28 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
@ -1216,7 +1216,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewLockoutPolicyAddedEvent( org.NewLockoutPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
5, 5,
false, false,
), ),
@ -1227,13 +1227,13 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, domain.SecondFactorTypeOTP), org.NewLoginPolicySecondFactorRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, domain.SecondFactorTypeOTP),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, domain.SecondFactorTypeU2F), org.NewLoginPolicySecondFactorAddedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, domain.SecondFactorTypeU2F),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, domain.MultiFactorTypeU2FWithPIN), org.NewLoginPolicyMultiFactorAddedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, domain.MultiFactorTypeU2FWithPIN),
), ),
eventFromEventPusher( eventFromEventPusher(
newLoginPolicyChangedEvent(context.Background(), "org1", newLoginPolicyChangedEvent(context.Background(), "org1",
@ -1245,22 +1245,22 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
nil), nil),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate), org.NewPasswordComplexityPolicyRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate), org.NewLabelPolicyRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextTemplateRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, domain.InitCodeMessageType, language.English), org.NewCustomTextTemplateRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, domain.InitCodeMessageType, language.English),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewCustomTextTemplateRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate, domain.LoginCustomText, language.English), org.NewCustomTextTemplateRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, domain.LoginCustomText, language.English),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate), org.NewPrivacyPolicyRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLockoutPolicyRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate), org.NewLockoutPolicyRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate),
), ),
eventFromEventPusher( eventFromEventPusher(
newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour), newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour),
@ -1308,7 +1308,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
@ -1369,28 +1369,28 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
@ -1634,28 +1634,28 @@ func TestCommandSide_RemoveOrgFeatures(t *testing.T) {
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent( org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1", "org1",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent( org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent( org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent( org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org1.iam-domain", "org1.iam-domain",
), ),
), ),
@ -1710,7 +1710,7 @@ func TestCommandSide_RemoveOrgFeatures(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewFeaturesRemovedEvent(context.Background(), &org.NewAggregate("org1", "org1").Aggregate), org.NewFeaturesRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -1764,7 +1764,7 @@ func newIAMFeaturesSetEvent(ctx context.Context, tierName string, state domain.F
func newFeaturesSetEvent(ctx context.Context, orgID string, tierName string, state domain.FeaturesState, auditLog time.Duration) *org.FeaturesSetEvent { func newFeaturesSetEvent(ctx context.Context, orgID string, tierName string, state domain.FeaturesState, auditLog time.Duration) *org.FeaturesSetEvent {
event, _ := org.NewFeaturesSetEvent( event, _ := org.NewFeaturesSetEvent(
ctx, ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
[]features.FeaturesChanges{ []features.FeaturesChanges{
features.ChangeTierName(tierName), features.ChangeTierName(tierName),
features.ChangeState(state), features.ChangeState(state),

View File

@ -4,12 +4,13 @@ import (
"context" "context"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore" "github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/action" "github.com/caos/zitadel/internal/repository/action"
"github.com/caos/zitadel/internal/repository/org" "github.com/caos/zitadel/internal/repository/org"
"github.com/stretchr/testify/assert"
) )
func TestCommands_ClearFlow(t *testing.T) { func TestCommands_ClearFlow(t *testing.T) {
@ -70,7 +71,7 @@ func TestCommands_ClearFlow(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewTriggerActionsSetEvent(context.Background(), org.NewTriggerActionsSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication, domain.FlowTypeExternalAuthentication,
domain.TriggerTypePostAuthentication, domain.TriggerTypePostAuthentication,
[]string{"actionID1"}, []string{"actionID1"},
@ -80,7 +81,7 @@ func TestCommands_ClearFlow(t *testing.T) {
expectPush( expectPush(
eventPusherToEvents( eventPusherToEvents(
org.NewFlowClearedEvent(context.Background(), org.NewFlowClearedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication, domain.FlowTypeExternalAuthentication,
), ),
), ),
@ -182,7 +183,7 @@ func TestCommands_SetTriggerActions(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewTriggerActionsSetEvent(context.Background(), org.NewTriggerActionsSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication, domain.FlowTypeExternalAuthentication,
domain.TriggerTypePostAuthentication, domain.TriggerTypePostAuthentication,
[]string{"actionID1"}, []string{"actionID1"},
@ -242,7 +243,7 @@ func TestCommands_SetTriggerActions(t *testing.T) {
expectPush( expectPush(
eventPusherToEvents( eventPusherToEvents(
org.NewTriggerActionsSetEvent(context.Background(), org.NewTriggerActionsSetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.FlowTypeExternalAuthentication, domain.FlowTypeExternalAuthentication,
domain.TriggerTypePostAuthentication, domain.TriggerTypePostAuthentication,
[]string{"actionID1"}, []string{"actionID1"},

View File

@ -40,7 +40,7 @@ func (c *Commands) AddIDPConfig(ctx context.Context, config *domain.IDPConfig, r
), ),
} }
if config.OIDCConfig != nil { if config.OIDCConfig != nil {
clientSecret, err := crypto.Crypt([]byte(config.OIDCConfig.ClientSecretString), c.idpConfigSecretCrypto) clientSecret, err := crypto.Crypt([]byte(config.OIDCConfig.ClientSecretString), c.idpConfigEncryption)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -94,7 +94,7 @@ func TestCommandSide_AddIDPConfig(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -104,7 +104,7 @@ func TestCommandSide_AddIDPConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPOIDCConfigAddedEvent(context.Background(), org.NewIDPOIDCConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"clientid1", "clientid1",
"config1", "config1",
"issuer", "issuer",
@ -170,7 +170,7 @@ func TestCommandSide_AddIDPConfig(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -180,7 +180,7 @@ func TestCommandSide_AddIDPConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPJWTConfigAddedEvent(context.Background(), org.NewIDPJWTConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"jwt-endpoint", "jwt-endpoint",
"issuer", "issuer",
@ -227,7 +227,7 @@ func TestCommandSide_AddIDPConfig(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
idGenerator: tt.fields.idGenerator, idGenerator: tt.fields.idGenerator,
idpConfigSecretCrypto: tt.fields.secretCrypto, idpConfigEncryption: tt.fields.secretCrypto,
} }
got, err := r.AddIDPConfig(tt.args.ctx, tt.args.config, tt.args.resourceOwner) got, err := r.AddIDPConfig(tt.args.ctx, tt.args.config, tt.args.resourceOwner)
if tt.res.err == nil { if tt.res.err == nil {
@ -321,7 +321,7 @@ func TestCommandSide_ChangeIDPConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -331,7 +331,7 @@ func TestCommandSide_ChangeIDPConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPOIDCConfigAddedEvent(context.Background(), org.NewIDPOIDCConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"clientid1", "clientid1",
"config1", "config1",
"issuer", "issuer",
@ -406,7 +406,7 @@ func TestCommandSide_ChangeIDPConfig(t *testing.T) {
func newIDPConfigChangedEvent(ctx context.Context, orgID, configID, oldName, newName string, stylingType domain.IDPConfigStylingType) *org.IDPConfigChangedEvent { func newIDPConfigChangedEvent(ctx context.Context, orgID, configID, oldName, newName string, stylingType domain.IDPConfigStylingType) *org.IDPConfigChangedEvent {
event, _ := org.NewIDPConfigChangedEvent(ctx, event, _ := org.NewIDPConfigChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
configID, configID,
oldName, oldName,
[]idpconfig.IDPConfigChanges{ []idpconfig.IDPConfigChanges{
@ -464,7 +464,7 @@ func TestCommands_RemoveIDPConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"idp1", "idp1",
"name1", "name1",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -476,7 +476,7 @@ func TestCommands_RemoveIDPConfig(t *testing.T) {
expectPush( expectPush(
eventPusherToEvents( eventPusherToEvents(
org.NewIDPConfigRemovedEvent(context.Background(), org.NewIDPConfigRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"idp1", "idp1",
"name1", "name1",
), ),
@ -506,7 +506,7 @@ func TestCommands_RemoveIDPConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"idp1", "idp1",
"name1", "name1",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -518,7 +518,7 @@ func TestCommands_RemoveIDPConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(), user.NewHumanAddedEvent(context.Background(),
&org.NewAggregate("user1", "org1").Aggregate, &user.NewAggregate("user1", "org1").Aggregate,
"username", "username",
"firstname", "firstname",
"lastname", "lastname",
@ -532,7 +532,7 @@ func TestCommands_RemoveIDPConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
user.NewUserIDPLinkAddedEvent(context.Background(), user.NewUserIDPLinkAddedEvent(context.Background(),
&org.NewAggregate("user1", "org1").Aggregate, &user.NewAggregate("user1", "org1").Aggregate,
"idp1", "idp1",
"name", "name",
"id1", "id1",
@ -542,12 +542,12 @@ func TestCommands_RemoveIDPConfig(t *testing.T) {
expectPush( expectPush(
eventPusherToEvents( eventPusherToEvents(
org.NewIDPConfigRemovedEvent(context.Background(), org.NewIDPConfigRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"idp1", "idp1",
"name1", "name1",
), ),
org.NewIdentityProviderCascadeRemovedEvent(context.Background(), org.NewIdentityProviderCascadeRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"idp1", "idp1",
), ),
user.NewUserIDPLinkCascadeRemovedEvent(context.Background(), user.NewUserIDPLinkCascadeRemovedEvent(context.Background(),

View File

@ -99,7 +99,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeJWT, domain.IDPConfigTypeJWT,
@ -109,7 +109,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPJWTConfigAddedEvent(context.Background(), org.NewIDPJWTConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"jwt-endpoint", "jwt-endpoint",
"issuer", "issuer",
@ -119,7 +119,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigRemovedEvent(context.Background(), org.NewIDPConfigRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name", "name",
), ),
@ -146,7 +146,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeJWT, domain.IDPConfigTypeJWT,
@ -156,7 +156,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPJWTConfigAddedEvent(context.Background(), org.NewIDPJWTConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"jwt-endpoint", "jwt-endpoint",
"issuer", "issuer",
@ -191,7 +191,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeJWT, domain.IDPConfigTypeJWT,
@ -201,7 +201,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPJWTConfigAddedEvent(context.Background(), org.NewIDPJWTConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"jwt-endpoint", "jwt-endpoint",
"issuer", "issuer",
@ -257,7 +257,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
idpConfigSecretCrypto: tt.fields.secretCrypto, idpConfigEncryption: tt.fields.secretCrypto,
} }
got, err := r.ChangeIDPJWTConfig(tt.args.ctx, tt.args.config, tt.args.resourceOwner) got, err := r.ChangeIDPJWTConfig(tt.args.ctx, tt.args.config, tt.args.resourceOwner)
if tt.res.err == nil { if tt.res.err == nil {
@ -275,7 +275,7 @@ func TestCommandSide_ChangeIDPJWTConfig(t *testing.T) {
func newIDPJWTConfigChangedEvent(ctx context.Context, orgID, configID, jwtEndpoint, issuer, keysEndpoint, headerName string) *org.IDPJWTConfigChangedEvent { func newIDPJWTConfigChangedEvent(ctx context.Context, orgID, configID, jwtEndpoint, issuer, keysEndpoint, headerName string) *org.IDPJWTConfigChangedEvent {
event, _ := org.NewIDPJWTConfigChangedEvent(ctx, event, _ := org.NewIDPJWTConfigChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
configID, configID,
[]idpconfig.JWTConfigChanges{ []idpconfig.JWTConfigChanges{
idpconfig.ChangeJWTEndpoint(jwtEndpoint), idpconfig.ChangeJWTEndpoint(jwtEndpoint),

View File

@ -34,7 +34,7 @@ func (c *Commands) ChangeIDPOIDCConfig(ctx context.Context, config *domain.OIDCI
config.AuthorizationEndpoint, config.AuthorizationEndpoint,
config.TokenEndpoint, config.TokenEndpoint,
config.ClientSecretString, config.ClientSecretString,
c.idpConfigSecretCrypto, c.idpConfigEncryption,
config.IDPDisplayNameMapping, config.IDPDisplayNameMapping,
config.UsernameMapping, config.UsernameMapping,
config.Scopes...) config.Scopes...)

View File

@ -99,7 +99,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -109,7 +109,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPOIDCConfigAddedEvent(context.Background(), org.NewIDPOIDCConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"clientid1", "clientid1",
"config1", "config1",
"issuer", "issuer",
@ -128,7 +128,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigRemovedEvent(context.Background(), org.NewIDPConfigRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name", "name",
), ),
@ -155,7 +155,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -165,7 +165,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPOIDCConfigAddedEvent(context.Background(), org.NewIDPOIDCConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"clientid1", "clientid1",
"config1", "config1",
"issuer", "issuer",
@ -212,7 +212,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name1", "name1",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -222,7 +222,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIDPOIDCConfigAddedEvent(context.Background(), org.NewIDPOIDCConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"clientid1", "clientid1",
"config1", "config1",
"issuer", "issuer",
@ -303,7 +303,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
idpConfigSecretCrypto: tt.fields.secretCrypto, idpConfigEncryption: tt.fields.secretCrypto,
} }
got, err := r.ChangeIDPOIDCConfig(tt.args.ctx, tt.args.config, tt.args.resourceOwner) got, err := r.ChangeIDPOIDCConfig(tt.args.ctx, tt.args.config, tt.args.resourceOwner)
if tt.res.err == nil { if tt.res.err == nil {
@ -321,7 +321,7 @@ func TestCommandSide_ChangeIDPOIDCConfig(t *testing.T) {
func newIDPOIDCConfigChangedEvent(ctx context.Context, orgID, configID, clientID, issuer, authorizationEndpoint, tokenEndpoint string, secret *crypto.CryptoValue, displayMapping, usernameMapping domain.OIDCMappingField, scopes []string) *org.IDPOIDCConfigChangedEvent { func newIDPOIDCConfigChangedEvent(ctx context.Context, orgID, configID, clientID, issuer, authorizationEndpoint, tokenEndpoint string, secret *crypto.CryptoValue, displayMapping, usernameMapping domain.OIDCMappingField, scopes []string) *org.IDPOIDCConfigChangedEvent {
event, _ := org.NewIDPOIDCConfigChangedEvent(ctx, event, _ := org.NewIDPOIDCConfigChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
configID, configID,
[]idpconfig.OIDCConfigChanges{ []idpconfig.OIDCConfigChanges{
idpconfig.ChangeClientID(clientID), idpconfig.ChangeClientID(clientID),

View File

@ -12,7 +12,7 @@ import (
"github.com/caos/zitadel/internal/telemetry/tracing" "github.com/caos/zitadel/internal/telemetry/tracing"
) )
func (c *commandNew) AddOrgMember(a *org.Aggregate, userID string, roles ...string) preparation.Validation { func (c *Commands) AddOrgMemberCommand(a *org.Aggregate, userID string, roles ...string) preparation.Validation {
return func() (preparation.CreateCommands, error) { return func() (preparation.CreateCommands, error) {
if userID == "" { if userID == "" {
return nil, errors.ThrowInvalidArgument(nil, "ORG-4Mlfs", "Errors.Invalid.Argument") return nil, errors.ThrowInvalidArgument(nil, "ORG-4Mlfs", "Errors.Invalid.Argument")
@ -26,7 +26,7 @@ func (c *commandNew) AddOrgMember(a *org.Aggregate, userID string, roles ...stri
} }
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) { return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
if exists, err := ExistsUser(ctx, filter, userID, a.ID); err != nil || !exists { if exists, err := ExistsUser(ctx, filter, userID, a.ID); err != nil || !exists {
return nil, errors.ThrowNotFound(err, "ORG-GoXOn", "Errors.User.NotFound") return nil, errors.ThrowPreconditionFailed(err, "ORG-GoXOn", "Errors.User.NotFound")
} }
if isMember, err := IsOrgMember(ctx, filter, a.ID, userID); err != nil || isMember { if isMember, err := IsOrgMember(ctx, filter, a.ID, userID); err != nil || isMember {
return nil, errors.ThrowAlreadyExists(err, "ORG-poWwe", "Errors.Org.Member.AlreadyExists") return nil, errors.ThrowAlreadyExists(err, "ORG-poWwe", "Errors.Org.Member.AlreadyExists")
@ -73,25 +73,18 @@ func IsOrgMember(ctx context.Context, filter preparation.FilterToQueryReducer, o
return isMember, nil return isMember, nil
} }
func (c *Commands) AddOrgMember(ctx context.Context, member *domain.Member) (*domain.Member, error) { func (c *Commands) AddOrgMember(ctx context.Context, userID, orgID string, roles ...string) (*domain.Member, error) {
if member.UserID == "" { orgAgg := org.NewAggregate(orgID)
return nil, errors.ThrowInvalidArgument(nil, "Org-u8fkf", "Errors.Org.MemberInvalid") cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, c.AddOrgMemberCommand(orgAgg, userID, roles...))
}
addedMember := NewOrgMemberWriteModel(member.AggregateID, member.UserID)
orgAgg := OrgAggregateFromWriteModel(&addedMember.WriteModel)
err := c.checkUserExists(ctx, addedMember.UserID, "")
if err != nil {
return nil, errors.ThrowPreconditionFailed(err, "Org-2H8ds", "Errors.User.NotFound")
}
event, err := c.addOrgMember(ctx, orgAgg, addedMember, member)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pushedEvents, err := c.eventstore.Push(ctx, event) events, err := c.eventstore.Push(ctx, cmds...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = AppendAndReduce(addedMember, pushedEvents...) addedMember := NewOrgMemberWriteModel(orgID, userID)
err = AppendAndReduce(addedMember, events...)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -30,7 +30,7 @@ func TestAddMember(t *testing.T) {
} }
ctx := context.Background() ctx := context.Background()
agg := org.NewAggregate("test", "test") agg := org.NewAggregate("test")
tests := []struct { tests := []struct {
name string name string
@ -85,7 +85,7 @@ func TestAddMember(t *testing.T) {
}).Filter(), }).Filter(),
}, },
want: Want{ want: Want{
CreateErr: errors.ThrowNotFound(nil, "ORG-GoXOn", "Errors.User.NotFound"), CreateErr: errors.ThrowPreconditionFailed(nil, "ORG-GoXOn", "Errors.User.NotFound"),
}, },
}, },
{ {
@ -116,7 +116,7 @@ func TestAddMember(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewMemberAddedEvent( org.NewMemberAddedEvent(
ctx, ctx,
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
"userID", "userID",
), ),
}, nil }, nil
@ -165,7 +165,7 @@ func TestAddMember(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
AssertValidation(t, (&commandNew{zitadelRoles: tt.args.zitadelRoles}).AddOrgMember(tt.args.a, tt.args.userID, tt.args.roles...), tt.args.filter, tt.want) AssertValidation(t, (&Commands{zitadelRoles: tt.args.zitadelRoles}).AddOrgMemberCommand(tt.args.a, tt.args.userID, tt.args.roles...), tt.args.filter, tt.want)
}) })
} }
} }
@ -201,7 +201,7 @@ func TestIsMember(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewMemberAddedEvent( org.NewMemberAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("orgID", "ro").Aggregate, &org.NewAggregate("orgID").Aggregate,
"userID", "userID",
), ),
}, nil }, nil
@ -219,12 +219,12 @@ func TestIsMember(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewMemberAddedEvent( org.NewMemberAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("orgID", "ro").Aggregate, &org.NewAggregate("orgID").Aggregate,
"userID", "userID",
), ),
org.NewMemberRemovedEvent( org.NewMemberRemovedEvent(
context.Background(), context.Background(),
&org.NewAggregate("orgID", "ro").Aggregate, &org.NewAggregate("orgID").Aggregate,
"userID", "userID",
), ),
}, nil }, nil
@ -242,12 +242,12 @@ func TestIsMember(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewMemberAddedEvent( org.NewMemberAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("orgID", "ro").Aggregate, &org.NewAggregate("orgID").Aggregate,
"userID", "userID",
), ),
org.NewMemberCascadeRemovedEvent( org.NewMemberCascadeRemovedEvent(
context.Background(), context.Background(),
&org.NewAggregate("orgID", "ro").Aggregate, &org.NewAggregate("orgID").Aggregate,
"userID", "userID",
), ),
}, nil }, nil
@ -292,7 +292,9 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
} }
type args struct { type args struct {
ctx context.Context ctx context.Context
member *domain.Member userID string
orgID string
roles []string
} }
type res struct { type res struct {
want *domain.Member want *domain.Member
@ -313,11 +315,24 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
}, },
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
member: &domain.Member{ orgID: "org1",
ObjectRoot: models.ObjectRoot{ },
AggregateID: "org1", res: res{
err: errors.IsErrorInvalidArgument,
}, },
}, },
{
name: "invalid roles, error",
fields: fields{
eventstore: eventstoreExpect(
t,
),
},
args: args{
ctx: context.Background(),
orgID: "org1",
userID: "user1",
roles: []string{"ORG_OWNER"},
}, },
res: res{ res: res{
err: errors.IsErrorInvalidArgument, err: errors.IsErrorInvalidArgument,
@ -330,58 +345,22 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
t, t,
expectFilter(), expectFilter(),
), ),
zitadelRoles: []authz.RoleMapping{
{
Role: domain.RoleOrgOwner,
},
},
}, },
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
member: &domain.Member{ orgID: "org1",
ObjectRoot: models.ObjectRoot{ userID: "user1",
AggregateID: "org1", roles: []string{domain.RoleOrgOwner},
},
UserID: "user1",
Roles: []string{domain.RoleOrgOwner},
},
}, },
res: res{ res: res{
err: errors.IsPreconditionFailed, err: errors.IsPreconditionFailed,
}, },
}, },
{
name: "invalid roles, error",
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
user.NewHumanAddedEvent(context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"username1",
"firstname1",
"lastname1",
"nickname1",
"displayname1",
language.German,
domain.GenderMale,
"email1",
true,
),
),
),
),
},
args: args{
ctx: context.Background(),
member: &domain.Member{
ObjectRoot: models.ObjectRoot{
AggregateID: "org1",
},
UserID: "user1",
Roles: []string{"ORG_OWNER"},
},
},
res: res{
err: errors.IsErrorInvalidArgument,
},
},
{ {
name: "member already exists, precondition error", name: "member already exists, precondition error",
fields: fields{ fields: fields{
@ -406,7 +385,7 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewMemberAddedEvent(context.Background(), org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"user1", "user1",
), ),
), ),
@ -420,13 +399,9 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
}, },
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
member: &domain.Member{ orgID: "org1",
ObjectRoot: models.ObjectRoot{ userID: "user1",
AggregateID: "org1", roles: []string{"ORG_OWNER"},
},
UserID: "user1",
Roles: []string{"ORG_OWNER"},
},
}, },
res: res{ res: res{
err: errors.IsErrorAlreadyExists, err: errors.IsErrorAlreadyExists,
@ -457,7 +432,7 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
expectPushFailed(errors.ThrowAlreadyExists(nil, "ERROR", "internal"), expectPushFailed(errors.ThrowAlreadyExists(nil, "ERROR", "internal"),
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(), eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"user1", "user1",
[]string{"ORG_OWNER"}..., []string{"ORG_OWNER"}...,
)), )),
@ -473,13 +448,9 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
}, },
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
member: &domain.Member{ orgID: "org1",
ObjectRoot: models.ObjectRoot{ userID: "user1",
AggregateID: "org1", roles: []string{"ORG_OWNER"},
},
UserID: "user1",
Roles: []string{"ORG_OWNER"},
},
}, },
res: res{ res: res{
err: errors.IsErrorAlreadyExists, err: errors.IsErrorAlreadyExists,
@ -510,7 +481,7 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(), eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"user1", "user1",
[]string{"ORG_OWNER"}..., []string{"ORG_OWNER"}...,
)), )),
@ -526,13 +497,9 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
}, },
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
member: &domain.Member{ orgID: "org1",
ObjectRoot: models.ObjectRoot{ userID: "user1",
AggregateID: "org1", roles: []string{"ORG_OWNER"},
},
UserID: "user1",
Roles: []string{"ORG_OWNER"},
},
}, },
res: res{ res: res{
want: &domain.Member{ want: &domain.Member{
@ -552,7 +519,7 @@ func TestCommandSide_AddOrgMember(t *testing.T) {
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
zitadelRoles: tt.fields.zitadelRoles, zitadelRoles: tt.fields.zitadelRoles,
} }
got, err := r.AddOrgMember(tt.args.ctx, tt.args.member) got, err := r.AddOrgMember(tt.args.ctx, tt.args.userID, tt.args.orgID, tt.args.roles...)
if tt.res.err == nil { if tt.res.err == nil {
assert.NoError(t, err) assert.NoError(t, err)
} }
@ -660,7 +627,7 @@ func TestCommandSide_ChangeOrgMember(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewMemberAddedEvent(context.Background(), org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"user1", "user1",
[]string{"ORG_OWNER"}..., []string{"ORG_OWNER"}...,
), ),
@ -695,7 +662,7 @@ func TestCommandSide_ChangeOrgMember(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewMemberAddedEvent(context.Background(), org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"user1", "user1",
[]string{"ORG_OWNER"}..., []string{"ORG_OWNER"}...,
), ),
@ -704,7 +671,7 @@ func TestCommandSide_ChangeOrgMember(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewMemberChangedEvent(context.Background(), eventFromEventPusher(org.NewMemberChangedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"user1", "user1",
[]string{"ORG_OWNER", "ORG_OWNER_VIEWER"}..., []string{"ORG_OWNER", "ORG_OWNER_VIEWER"}...,
)), )),

View File

@ -60,7 +60,7 @@ func TestCommandSide_AddDomainPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -90,7 +90,7 @@ func TestCommandSide_AddDomainPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -203,7 +203,7 @@ func TestCommandSide_ChangeDomainPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -231,7 +231,7 @@ func TestCommandSide_ChangeDomainPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -341,7 +341,7 @@ func TestCommandSide_RemoveDomainPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -351,7 +351,7 @@ func TestCommandSide_RemoveDomainPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyRemovedEvent(context.Background(), org.NewDomainPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -386,7 +386,7 @@ func TestCommandSide_RemoveDomainPolicy(t *testing.T) {
func newDomainPolicyChangedEvent(ctx context.Context, orgID string, userLoginMustBeDomain, validateOrgDomains bool) *org.DomainPolicyChangedEvent { func newDomainPolicyChangedEvent(ctx context.Context, orgID string, userLoginMustBeDomain, validateOrgDomains bool) *org.DomainPolicyChangedEvent {
event, _ := org.NewDomainPolicyChangedEvent(ctx, event, _ := org.NewDomainPolicyChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
[]policy.DomainPolicyChanges{ []policy.DomainPolicyChanges{
policy.ChangeUserLoginMustBeDomain(userLoginMustBeDomain), policy.ChangeUserLoginMustBeDomain(userLoginMustBeDomain),
policy.ChangeValidateOrgDomains(validateOrgDomains), policy.ChangeValidateOrgDomains(validateOrgDomains),

View File

@ -66,7 +66,7 @@ func TestCommandSide_AddLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -180,7 +180,7 @@ func TestCommandSide_AddLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -324,7 +324,7 @@ func TestCommandSide_ChangeLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -389,7 +389,7 @@ func TestCommandSide_ChangeLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -454,7 +454,7 @@ func TestCommandSide_ChangeLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -623,7 +623,7 @@ func TestCommandSide_ActivateLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -642,7 +642,7 @@ func TestCommandSide_ActivateLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyActivatedEvent(context.Background(), org.NewLabelPolicyActivatedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -727,7 +727,7 @@ func TestCommandSide_RemoveLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -746,7 +746,7 @@ func TestCommandSide_RemoveLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyRemovedEvent(context.Background(), org.NewLabelPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -852,7 +852,7 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -894,7 +894,7 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -913,7 +913,7 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyLogoAddedEvent(context.Background(), org.NewLabelPolicyLogoAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"logo", "logo",
), ),
), ),
@ -1022,7 +1022,7 @@ func TestCommandSide_RemoveLogoLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1038,7 +1038,7 @@ func TestCommandSide_RemoveLogoLabelPolicy(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyLogoAddedEvent(context.Background(), org.NewLabelPolicyLogoAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -1047,7 +1047,7 @@ func TestCommandSide_RemoveLogoLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyLogoRemovedEvent(context.Background(), org.NewLabelPolicyLogoRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -1162,7 +1162,7 @@ func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1204,7 +1204,7 @@ func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1223,7 +1223,7 @@ func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyIconAddedEvent(context.Background(), org.NewLabelPolicyIconAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"icon", "icon",
), ),
), ),
@ -1330,7 +1330,7 @@ func TestCommandSide_RemoveIconLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1346,7 +1346,7 @@ func TestCommandSide_RemoveIconLabelPolicy(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyIconAddedEvent(context.Background(), org.NewLabelPolicyIconAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -1355,7 +1355,7 @@ func TestCommandSide_RemoveIconLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyIconRemovedEvent(context.Background(), org.NewLabelPolicyIconRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -1469,7 +1469,7 @@ func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1511,7 +1511,7 @@ func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1530,7 +1530,7 @@ func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyLogoDarkAddedEvent(context.Background(), org.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"logo", "logo",
), ),
), ),
@ -1639,7 +1639,7 @@ func TestCommandSide_RemoveLogoDarkLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1655,7 +1655,7 @@ func TestCommandSide_RemoveLogoDarkLabelPolicy(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyLogoDarkAddedEvent(context.Background(), org.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -1664,7 +1664,7 @@ func TestCommandSide_RemoveLogoDarkLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyLogoDarkRemovedEvent(context.Background(), org.NewLabelPolicyLogoDarkRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -1779,7 +1779,7 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1821,7 +1821,7 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1840,7 +1840,7 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyIconDarkAddedEvent(context.Background(), org.NewLabelPolicyIconDarkAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"icon", "icon",
), ),
), ),
@ -1945,7 +1945,7 @@ func TestCommandSide_RemoveIconDarkLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -1961,7 +1961,7 @@ func TestCommandSide_RemoveIconDarkLabelPolicy(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyIconDarkAddedEvent(context.Background(), org.NewLabelPolicyIconDarkAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -1970,7 +1970,7 @@ func TestCommandSide_RemoveIconDarkLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyIconDarkRemovedEvent(context.Background(), org.NewLabelPolicyIconDarkRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -2076,7 +2076,7 @@ func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -2118,7 +2118,7 @@ func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -2137,7 +2137,7 @@ func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyFontAddedEvent(context.Background(), org.NewLabelPolicyFontAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"font", "font",
), ),
), ),
@ -2242,7 +2242,7 @@ func TestCommandSide_RemoveFontLabelPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyAddedEvent(context.Background(), org.NewLabelPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
"#ffffff", "#ffffff",
@ -2258,7 +2258,7 @@ func TestCommandSide_RemoveFontLabelPolicy(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyFontAddedEvent(context.Background(), org.NewLabelPolicyFontAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -2267,7 +2267,7 @@ func TestCommandSide_RemoveFontLabelPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLabelPolicyFontRemovedEvent(context.Background(), org.NewLabelPolicyFontRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"key", "key",
), ),
), ),
@ -2308,7 +2308,7 @@ func TestCommandSide_RemoveFontLabelPolicy(t *testing.T) {
func newLabelPolicyChangedEvent(ctx context.Context, orgID, primaryColor, backgroundColor, warnColor, fontColor, primaryColorDark, backgroundColorDark, warnColorDark, fontColorDark string, hideLoginNameSuffix, errMsgPopup, disableWatermark bool) *org.LabelPolicyChangedEvent { func newLabelPolicyChangedEvent(ctx context.Context, orgID, primaryColor, backgroundColor, warnColor, fontColor, primaryColorDark, backgroundColorDark, warnColorDark, fontColorDark string, hideLoginNameSuffix, errMsgPopup, disableWatermark bool) *org.LabelPolicyChangedEvent {
event, _ := org.NewLabelPolicyChangedEvent(ctx, event, _ := org.NewLabelPolicyChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
[]policy.LabelPolicyChanges{ []policy.LabelPolicyChanges{
policy.ChangePrimaryColor(primaryColor), policy.ChangePrimaryColor(primaryColor),
policy.ChangeBackgroundColor(backgroundColor), policy.ChangeBackgroundColor(backgroundColor),

View File

@ -60,7 +60,7 @@ func TestCommandSide_AddPasswordLockoutPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLockoutPolicyAddedEvent(context.Background(), org.NewLockoutPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
true, true,
), ),
@ -90,7 +90,7 @@ func TestCommandSide_AddPasswordLockoutPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLockoutPolicyAddedEvent(context.Background(), org.NewLockoutPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
true, true,
), ),
@ -203,7 +203,7 @@ func TestCommandSide_ChangePasswordLockoutPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLockoutPolicyAddedEvent(context.Background(), org.NewLockoutPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
true, true,
), ),
@ -231,7 +231,7 @@ func TestCommandSide_ChangePasswordLockoutPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLockoutPolicyAddedEvent(context.Background(), org.NewLockoutPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
true, true,
), ),
@ -341,7 +341,7 @@ func TestCommandSide_RemovePasswordLockoutPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLockoutPolicyAddedEvent(context.Background(), org.NewLockoutPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
true, true,
), ),
@ -351,7 +351,7 @@ func TestCommandSide_RemovePasswordLockoutPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLockoutPolicyRemovedEvent(context.Background(), org.NewLockoutPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -386,7 +386,7 @@ func TestCommandSide_RemovePasswordLockoutPolicy(t *testing.T) {
func newPasswordLockoutPolicyChangedEvent(ctx context.Context, orgID string, maxAttempts uint64, showLockoutFailure bool) *org.LockoutPolicyChangedEvent { func newPasswordLockoutPolicyChangedEvent(ctx context.Context, orgID string, maxAttempts uint64, showLockoutFailure bool) *org.LockoutPolicyChangedEvent {
event, _ := org.NewLockoutPolicyChangedEvent(ctx, event, _ := org.NewLockoutPolicyChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
[]policy.LockoutPolicyChanges{ []policy.LockoutPolicyChanges{
policy.ChangeMaxAttempts(maxAttempts), policy.ChangeMaxAttempts(maxAttempts),
policy.ChangeShowLockOutFailures(showLockoutFailure), policy.ChangeShowLockOutFailures(showLockoutFailure),

View File

@ -73,7 +73,7 @@ func TestCommandSide_AddLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -185,7 +185,7 @@ func TestCommandSide_AddLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -334,7 +334,7 @@ func TestCommandSide_ChangeLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -398,7 +398,7 @@ func TestCommandSide_ChangeLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -463,7 +463,7 @@ func TestCommandSide_ChangeLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -632,7 +632,7 @@ func TestCommandSide_RemoveLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -651,7 +651,7 @@ func TestCommandSide_RemoveLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyRemovedEvent(context.Background(), org.NewLoginPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -770,7 +770,7 @@ func TestCommandSide_AddIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -809,7 +809,7 @@ func TestCommandSide_AddIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -827,7 +827,7 @@ func TestCommandSide_AddIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name", "name",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -839,7 +839,7 @@ func TestCommandSide_AddIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderAddedEvent(context.Background(), org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1", "or1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
domain.IdentityProviderTypeOrg, domain.IdentityProviderTypeOrg,
), ),
@ -868,7 +868,7 @@ func TestCommandSide_AddIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -886,7 +886,7 @@ func TestCommandSide_AddIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name", "name",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -900,7 +900,7 @@ func TestCommandSide_AddIDPProviderLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderAddedEvent(context.Background(), org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
domain.IdentityProviderTypeOrg), domain.IdentityProviderTypeOrg),
), ),
@ -1030,7 +1030,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -1069,7 +1069,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -1087,14 +1087,14 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderAddedEvent(context.Background(), org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
domain.IdentityProviderTypeOrg, domain.IdentityProviderTypeOrg,
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderRemovedEvent(context.Background(), org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
), ),
), ),
@ -1120,7 +1120,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -1138,7 +1138,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderAddedEvent(context.Background(), org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
domain.IdentityProviderTypeOrg, domain.IdentityProviderTypeOrg,
), ),
@ -1148,7 +1148,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderRemovedEvent(context.Background(), org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1"), "config1"),
), ),
}, },
@ -1178,7 +1178,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -1196,7 +1196,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderAddedEvent(context.Background(), org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
domain.IdentityProviderTypeOrg, domain.IdentityProviderTypeOrg,
), ),
@ -1206,7 +1206,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderRemovedEvent(context.Background(), org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1"), "config1"),
), ),
}, },
@ -1244,7 +1244,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
true, true,
@ -1262,7 +1262,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderAddedEvent(context.Background(), org.NewIdentityProviderAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
domain.IdentityProviderTypeOrg, domain.IdentityProviderTypeOrg,
), ),
@ -1279,7 +1279,7 @@ func TestCommandSide_RemoveIDPProviderLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewIdentityProviderRemovedEvent(context.Background(), org.NewIdentityProviderRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1"), "config1"),
), ),
eventFromEventPusher( eventFromEventPusher(
@ -1390,7 +1390,7 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(), org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTP, domain.SecondFactorTypeOTP,
), ),
), ),
@ -1416,7 +1416,7 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(), org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTP), domain.SecondFactorTypeOTP),
), ),
}, },
@ -1526,13 +1526,13 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(), org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTP, domain.SecondFactorTypeOTP,
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(), org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTP, domain.SecondFactorTypeOTP,
), ),
), ),
@ -1556,7 +1556,7 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorAddedEvent(context.Background(), org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTP, domain.SecondFactorTypeOTP,
), ),
), ),
@ -1565,7 +1565,7 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(), org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.SecondFactorTypeOTP), domain.SecondFactorTypeOTP),
), ),
}, },
@ -1657,7 +1657,7 @@ func TestCommandSide_AddMultiFactorLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(), org.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN, domain.MultiFactorTypeU2FWithPIN,
), ),
), ),
@ -1683,7 +1683,7 @@ func TestCommandSide_AddMultiFactorLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(), org.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN), domain.MultiFactorTypeU2FWithPIN),
), ),
}, },
@ -1793,13 +1793,13 @@ func TestCommandSide_RemoveMultiFactorLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(), org.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN, domain.MultiFactorTypeU2FWithPIN,
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyMultiFactorRemovedEvent(context.Background(), org.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN, domain.MultiFactorTypeU2FWithPIN,
), ),
), ),
@ -1823,7 +1823,7 @@ func TestCommandSide_RemoveMultiFactorLoginPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyMultiFactorAddedEvent(context.Background(), org.NewLoginPolicyMultiFactorAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN, domain.MultiFactorTypeU2FWithPIN,
), ),
), ),
@ -1832,7 +1832,7 @@ func TestCommandSide_RemoveMultiFactorLoginPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyMultiFactorRemovedEvent(context.Background(), org.NewLoginPolicyMultiFactorRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
domain.MultiFactorTypeU2FWithPIN), domain.MultiFactorTypeU2FWithPIN),
), ),
}, },
@ -1894,7 +1894,7 @@ func newLoginPolicyChangedEvent(ctx context.Context, orgID string, usernamePassw
changes = append(changes, policy.ChangeMultiFactorCheckLifetime(*multiFactorLifetime)) changes = append(changes, policy.ChangeMultiFactorCheckLifetime(*multiFactorLifetime))
} }
event, _ := org.NewLoginPolicyChangedEvent(ctx, event, _ := org.NewLoginPolicyChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
changes, changes,
) )
return event return event

View File

@ -59,7 +59,7 @@ func TestCommandSide_AddMailTemplate(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewMailTemplateAddedEvent(context.Background(), org.NewMailTemplateAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]byte("template"), []byte("template"),
), ),
), ),
@ -87,7 +87,7 @@ func TestCommandSide_AddMailTemplate(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewMailTemplateAddedEvent(context.Background(), org.NewMailTemplateAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]byte("template"), []byte("template"),
), ),
), ),
@ -195,7 +195,7 @@ func TestCommandSide_ChangeMailTemplate(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewMailTemplateAddedEvent(context.Background(), org.NewMailTemplateAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]byte("template"), []byte("template"),
), ),
), ),
@ -221,7 +221,7 @@ func TestCommandSide_ChangeMailTemplate(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewMailTemplateAddedEvent(context.Background(), org.NewMailTemplateAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]byte("template"), []byte("template"),
), ),
), ),
@ -328,7 +328,7 @@ func TestCommandSide_RemoveMailTemplate(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewMailTemplateAddedEvent(context.Background(), org.NewMailTemplateAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
[]byte("template"), []byte("template"),
), ),
), ),
@ -337,7 +337,7 @@ func TestCommandSide_RemoveMailTemplate(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewMailTemplateRemovedEvent(context.Background(), org.NewMailTemplateRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -372,7 +372,7 @@ func TestCommandSide_RemoveMailTemplate(t *testing.T) {
func newMailTemplateChangedEvent(ctx context.Context, orgID string, template string) *org.MailTemplateChangedEvent { func newMailTemplateChangedEvent(ctx context.Context, orgID string, template string) *org.MailTemplateChangedEvent {
event, _ := org.NewMailTemplateChangedEvent(ctx, event, _ := org.NewMailTemplateChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
[]policy.MailTemplateChanges{ []policy.MailTemplateChanges{
policy.ChangeTemplate([]byte(template)), policy.ChangeTemplate([]byte(template)),
}, },

View File

@ -60,7 +60,7 @@ func TestCommandSide_AddPasswordAgePolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordAgePolicyAddedEvent(context.Background(), org.NewPasswordAgePolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
365, 365,
10, 10,
), ),
@ -90,7 +90,7 @@ func TestCommandSide_AddPasswordAgePolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordAgePolicyAddedEvent(context.Background(), org.NewPasswordAgePolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
365, 365,
), ),
@ -203,7 +203,7 @@ func TestCommandSide_ChangePasswordAgePolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordAgePolicyAddedEvent(context.Background(), org.NewPasswordAgePolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
365, 365,
), ),
@ -231,7 +231,7 @@ func TestCommandSide_ChangePasswordAgePolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordAgePolicyAddedEvent(context.Background(), org.NewPasswordAgePolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
365, 365,
), ),
@ -341,7 +341,7 @@ func TestCommandSide_RemovePasswordAgePolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordAgePolicyAddedEvent(context.Background(), org.NewPasswordAgePolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
10, 10,
365, 365,
), ),
@ -351,7 +351,7 @@ func TestCommandSide_RemovePasswordAgePolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordAgePolicyRemovedEvent(context.Background(), org.NewPasswordAgePolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -389,7 +389,7 @@ func TestCommandSide_RemovePasswordAgePolicy(t *testing.T) {
func newPasswordAgePolicyChangedEvent(ctx context.Context, orgID string, maxAgeDays, expireWarnDays uint64) *org.PasswordAgePolicyChangedEvent { func newPasswordAgePolicyChangedEvent(ctx context.Context, orgID string, maxAgeDays, expireWarnDays uint64) *org.PasswordAgePolicyChangedEvent {
event, _ := org.NewPasswordAgePolicyChangedEvent(ctx, event, _ := org.NewPasswordAgePolicyChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
[]policy.PasswordAgePolicyChanges{ []policy.PasswordAgePolicyChanges{
policy.ChangeMaxAgeDays(maxAgeDays), policy.ChangeMaxAgeDays(maxAgeDays),
policy.ChangeExpireWarnDays(expireWarnDays), policy.ChangeExpireWarnDays(expireWarnDays),

View File

@ -63,7 +63,7 @@ func TestCommandSide_AddPasswordComplexityPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
8, 8,
true, true, true, true, true, true, true, true,
), ),
@ -96,7 +96,7 @@ func TestCommandSide_AddPasswordComplexityPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
8, 8,
true, true, true, true, true, true, true, true,
), ),
@ -221,7 +221,7 @@ func TestCommandSide_ChangePasswordComplexityPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
8, 8,
true, true, true, true, true, true, true, true,
), ),
@ -252,7 +252,7 @@ func TestCommandSide_ChangePasswordComplexityPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
8, 8,
true, true, true, true, true, true, true, true,
), ),
@ -368,7 +368,7 @@ func TestCommandSide_RemovePasswordComplexityPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
8, 8,
true, true, true, true, true, true, true, true,
), ),
@ -378,7 +378,7 @@ func TestCommandSide_RemovePasswordComplexityPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyRemovedEvent(context.Background(), org.NewPasswordComplexityPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -416,7 +416,7 @@ func TestCommandSide_RemovePasswordComplexityPolicy(t *testing.T) {
func newPasswordComplexityPolicyChangedEvent(ctx context.Context, orgID string, minLength uint64, hasUpper, hasLower, hasNumber, hasSymbol bool) *org.PasswordComplexityPolicyChangedEvent { func newPasswordComplexityPolicyChangedEvent(ctx context.Context, orgID string, minLength uint64, hasUpper, hasLower, hasNumber, hasSymbol bool) *org.PasswordComplexityPolicyChangedEvent {
event, _ := org.NewPasswordComplexityPolicyChangedEvent(ctx, event, _ := org.NewPasswordComplexityPolicyChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
[]policy.PasswordComplexityPolicyChanges{ []policy.PasswordComplexityPolicyChanges{
policy.ChangeMinLength(minLength), policy.ChangeMinLength(minLength),
policy.ChangeHasUppercase(hasUpper), policy.ChangeHasUppercase(hasUpper),

View File

@ -61,7 +61,7 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(), org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"TOSLink", "TOSLink",
"PrivacyLink", "PrivacyLink",
"HelpLink", "HelpLink",
@ -93,7 +93,7 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(), org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"TOSLink", "TOSLink",
"PrivacyLink", "PrivacyLink",
"HelpLink", "HelpLink",
@ -134,7 +134,7 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(), org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"", "",
"", "",
"", "",
@ -252,7 +252,7 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(), org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"TOSLink", "TOSLink",
"PrivacyLink", "PrivacyLink",
"HelpLink", "HelpLink",
@ -282,7 +282,7 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(), org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"TOSLink", "TOSLink",
"PrivacyLink", "PrivacyLink",
"HelpLink", "HelpLink",
@ -327,7 +327,7 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(), org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"TOSLink", "TOSLink",
"PrivacyLink", "PrivacyLink",
"HelpLink", "HelpLink",
@ -440,7 +440,7 @@ func TestCommandSide_RemovePrivacyPolicy(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyAddedEvent(context.Background(), org.NewPrivacyPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"TOSLink", "TOSLink",
"PrivacyLink", "PrivacyLink",
"HelpLink", "HelpLink",
@ -451,7 +451,7 @@ func TestCommandSide_RemovePrivacyPolicy(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher( eventFromEventPusher(
org.NewPrivacyPolicyRemovedEvent(context.Background(), org.NewPrivacyPolicyRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
}, },
), ),
@ -489,7 +489,7 @@ func TestCommandSide_RemovePrivacyPolicy(t *testing.T) {
func newPrivacyPolicyChangedEvent(ctx context.Context, orgID string, tosLink, privacyLink, helpLink string) *org.PrivacyPolicyChangedEvent { func newPrivacyPolicyChangedEvent(ctx context.Context, orgID string, tosLink, privacyLink, helpLink string) *org.PrivacyPolicyChangedEvent {
event, _ := org.NewPrivacyPolicyChangedEvent(ctx, event, _ := org.NewPrivacyPolicyChangedEvent(ctx,
&org.NewAggregate(orgID, orgID).Aggregate, &org.NewAggregate(orgID).Aggregate,
[]policy.PrivacyPolicyChanges{ []policy.PrivacyPolicyChanges{
policy.ChangeTOSLink(tosLink), policy.ChangeTOSLink(tosLink),
policy.ChangePrivacyLink(privacyLink), policy.ChangePrivacyLink(privacyLink),

View File

@ -27,7 +27,7 @@ func TestAddOrg(t *testing.T) {
} }
ctx := context.Background() ctx := context.Background()
agg := org.NewAggregate("test", "test") agg := org.NewAggregate("test")
tests := []struct { tests := []struct {
name string name string
@ -178,23 +178,23 @@ func TestCommandSide_AddOrg(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent( eventFromEventPusher(org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"Org")), "Org")),
eventFromEventPusher(org.NewDomainAddedEvent( eventFromEventPusher(org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"org.iam-domain")), "org.iam-domain")),
eventFromEventPusher(org.NewDomainVerifiedEvent( eventFromEventPusher(org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"org.iam-domain")), "org.iam-domain")),
eventFromEventPusher(org.NewDomainPrimarySetEvent( eventFromEventPusher(org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"org.iam-domain")), "org.iam-domain")),
eventFromEventPusher(org.NewMemberAddedEvent( eventFromEventPusher(org.NewMemberAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"user1", domain.RoleOrgOwner)), "user1", domain.RoleOrgOwner)),
}, },
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")), uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
@ -247,23 +247,23 @@ func TestCommandSide_AddOrg(t *testing.T) {
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent( eventFromEventPusher(org.NewOrgAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"Org")), "Org")),
eventFromEventPusher(org.NewDomainAddedEvent( eventFromEventPusher(org.NewDomainAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"org.iam-domain")), "org.iam-domain")),
eventFromEventPusher(org.NewDomainVerifiedEvent( eventFromEventPusher(org.NewDomainVerifiedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"org.iam-domain")), "org.iam-domain")),
eventFromEventPusher(org.NewDomainPrimarySetEvent( eventFromEventPusher(org.NewDomainPrimarySetEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"org.iam-domain")), "org.iam-domain")),
eventFromEventPusher(org.NewMemberAddedEvent( eventFromEventPusher(org.NewMemberAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"user1", domain.RoleOrgOwner)), "user1", domain.RoleOrgOwner)),
}, },
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")), uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("Org")),
@ -315,22 +315,22 @@ func TestCommandSide_AddOrg(t *testing.T) {
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(), eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"Org", "Org",
)), )),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(), eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, "org.iam-domain", &org.NewAggregate("org2").Aggregate, "org.iam-domain",
)), )),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"org.iam-domain", "org.iam-domain",
)), )),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(), eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"org.iam-domain", "org.iam-domain",
)), )),
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(), eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"user1", "user1",
domain.RoleOrgOwner, domain.RoleOrgOwner,
)), )),
@ -450,7 +450,7 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
), ),
@ -459,7 +459,7 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
errors.ThrowInternal(nil, "id", "message"), errors.ThrowInternal(nil, "id", "message"),
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgChangedEvent(context.Background(), eventFromEventPusher(org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "org", "neworg")), &org.NewAggregate("org1").Aggregate, "org", "neworg")),
}, },
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")), uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")), uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")),
@ -484,37 +484,37 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
), ),
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org.zitadel.ch"), "org.zitadel.ch"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org.zitadel.ch"), "org.zitadel.ch"),
), ),
), ),
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgChangedEvent(context.Background(), eventFromEventPusher(org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "org", "neworg")), &org.NewAggregate("org1").Aggregate, "org", "neworg")),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(), eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "neworg.zitadel.ch")), &org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "neworg.zitadel.ch")), &org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(), eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "org.zitadel.ch", true)), &org.NewAggregate("org1").Aggregate, "org.zitadel.ch", true)),
}, },
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")), uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")), uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")),
@ -539,44 +539,44 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
), ),
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org.zitadel.ch"), "org.zitadel.ch"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org.zitadel.ch"), "org.zitadel.ch"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPrimarySetEvent(context.Background(), org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org.zitadel.ch"), "org.zitadel.ch"),
), ),
), ),
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgChangedEvent(context.Background(), eventFromEventPusher(org.NewOrgChangedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "org", "neworg")), &org.NewAggregate("org1").Aggregate, "org", "neworg")),
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(), eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "neworg.zitadel.ch")), &org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(), eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "neworg.zitadel.ch")), &org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(), eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "neworg.zitadel.ch")), &org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch")),
eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(), eventFromEventPusher(org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, "org.zitadel.ch", true)), &org.NewAggregate("org1").Aggregate, "org.zitadel.ch", true)),
}, },
uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")), uniqueConstraintsFromEventConstraint(org.NewRemoveOrgNameUniqueConstraint("org")),
uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")), uniqueConstraintsFromEventConstraint(org.NewAddOrgNameUniqueConstraint("neworg")),
@ -654,12 +654,12 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgDeactivatedEvent(context.Background(), org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
), ),
), ),
@ -680,7 +680,7 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
), ),
@ -688,7 +688,7 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
errors.ThrowInternal(nil, "id", "message"), errors.ThrowInternal(nil, "id", "message"),
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgDeactivatedEvent(context.Background(), eventFromEventPusher(org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate)), &org.NewAggregate("org1").Aggregate)),
}, },
), ),
), ),
@ -709,14 +709,14 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
), ),
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgDeactivatedEvent(context.Background(), eventFromEventPusher(org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
)), )),
}, },
), ),
@ -789,7 +789,7 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
), ),
@ -811,12 +811,12 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgDeactivatedEvent(context.Background(), org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
), ),
), ),
), ),
@ -824,7 +824,7 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
errors.ThrowInternal(nil, "id", "message"), errors.ThrowInternal(nil, "id", "message"),
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgReactivatedEvent(context.Background(), eventFromEventPusher(org.NewOrgReactivatedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
)), )),
}, },
), ),
@ -846,18 +846,18 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"org"), "org"),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgDeactivatedEvent(context.Background(), org.NewOrgDeactivatedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate), &org.NewAggregate("org1").Aggregate),
), ),
), ),
expectPush( expectPush(
[]*repository.Event{ []*repository.Event{
eventFromEventPusher(org.NewOrgReactivatedEvent(context.Background(), eventFromEventPusher(org.NewOrgReactivatedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate)), &org.NewAggregate("org1").Aggregate)),
}, },
), ),
), ),

View File

@ -2,6 +2,10 @@ package command
import ( import (
"context" "context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore" "github.com/caos/zitadel/internal/eventstore"
@ -12,8 +16,6 @@ import (
"github.com/caos/zitadel/internal/repository/org" "github.com/caos/zitadel/internal/repository/org"
"github.com/caos/zitadel/internal/repository/project" "github.com/caos/zitadel/internal/repository/project"
"github.com/caos/zitadel/internal/repository/usergrant" "github.com/caos/zitadel/internal/repository/usergrant"
"github.com/stretchr/testify/assert"
"testing"
) )
func TestCommandSide_AddProjectGrant(t *testing.T) { func TestCommandSide_AddProjectGrant(t *testing.T) {
@ -123,7 +125,7 @@ func TestCommandSide_AddProjectGrant(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("grantedorg1", "grantedorg1").Aggregate, &org.NewAggregate("grantedorg1").Aggregate,
"granted org", "granted org",
), ),
), ),
@ -160,7 +162,7 @@ func TestCommandSide_AddProjectGrant(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("grantedorg1", "grantedorg1").Aggregate, &org.NewAggregate("grantedorg1").Aggregate,
"granted org", "granted org",
), ),
), ),
@ -389,7 +391,7 @@ func TestCommandSide_ChangeProjectGrant(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("grantedorg1", "grantedorg1").Aggregate, &org.NewAggregate("grantedorg1").Aggregate,
"granted org", "granted org",
), ),
), ),
@ -435,7 +437,7 @@ func TestCommandSide_ChangeProjectGrant(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("grantedorg1", "grantedorg1").Aggregate, &org.NewAggregate("grantedorg1").Aggregate,
"granted org", "granted org",
), ),
), ),
@ -489,7 +491,7 @@ func TestCommandSide_ChangeProjectGrant(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("grantedorg1", "grantedorg1").Aggregate, &org.NewAggregate("grantedorg1").Aggregate,
"granted org", "granted org",
), ),
), ),
@ -569,7 +571,7 @@ func TestCommandSide_ChangeProjectGrant(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("grantedorg1", "grantedorg1").Aggregate, &org.NewAggregate("grantedorg1").Aggregate,
"granted org", "granted org",
), ),
), ),
@ -651,7 +653,7 @@ func TestCommandSide_ChangeProjectGrant(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewOrgAddedEvent(context.Background(), org.NewOrgAddedEvent(context.Background(),
&org.NewAggregate("grantedorg1", "grantedorg1").Aggregate, &org.NewAggregate("grantedorg1").Aggregate,
"granted org", "granted org",
), ),
), ),

View File

@ -1,73 +0,0 @@
package command
import (
"context"
"github.com/caos/zitadel/internal/api/authz"
"github.com/caos/zitadel/internal/command/preparation"
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/instance"
)
func (c *commandNew) AddSecretGeneratorConfig(ctx context.Context, typ domain.SecretGeneratorType, config *crypto.GeneratorConfig) (*domain.ObjectDetails, error) {
agg := instance.NewAggregate(authz.GetInstance(ctx).InstanceID())
cmds, err := preparation.PrepareCommands(ctx, c.es.Filter, addSecretGeneratorConfig(agg, typ, config))
if err != nil {
return nil, err
}
events, err := c.es.Push(ctx, cmds...)
if err != nil {
return nil, err
}
return &domain.ObjectDetails{
Sequence: events[len(events)-1].Sequence(),
EventDate: events[len(events)-1].CreationDate(),
ResourceOwner: agg.ResourceOwner,
}, nil
}
//AddOrg defines the commands to create a new org,
// this includes the verified default domain
func addSecretGeneratorConfig(a *instance.Aggregate, typ domain.SecretGeneratorType, config *crypto.GeneratorConfig) preparation.Validation {
return func() (preparation.CreateCommands, error) {
if !typ.Valid() {
return nil, errors.ThrowInvalidArgument(nil, "V2-FGqVj", "Errors.InvalidArgument")
}
if config.Length < 1 {
return nil, errors.ThrowInvalidArgument(nil, "V2-jEqCt", "Errors.InvalidArgument")
}
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
writeModel := NewInstanceSecretGeneratorConfigWriteModel(ctx, typ)
events, err := filter(ctx, writeModel.Query())
if err != nil {
return nil, err
}
writeModel.AppendEvents(events...)
if err = writeModel.Reduce(); err != nil {
return nil, err
}
if writeModel.State == domain.SecretGeneratorStateActive {
return nil, errors.ThrowAlreadyExists(nil, "V2-6CqKo", "Errors.SecretGenerator.AlreadyExists")
}
return []eventstore.Command{
instance.NewSecretGeneratorAddedEvent(
ctx,
&a.Aggregate,
typ,
config.Length,
config.Expiry,
config.IncludeLowerLetters,
config.IncludeUpperLetters,
config.IncludeDigits,
config.IncludeSymbols,
),
}, nil
}, nil
}
}

View File

@ -22,7 +22,7 @@ func (c *Commands) AddSMSConfigTwilio(ctx context.Context, instanceID string, co
var token *crypto.CryptoValue var token *crypto.CryptoValue
if config.Token != "" { if config.Token != "" {
token, err = crypto.Encrypt([]byte(config.Token), c.smsCrypto) token, err = crypto.Encrypt([]byte(config.Token), c.smsEncryption)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
@ -91,7 +91,7 @@ func (c *Commands) ChangeSMSConfigTwilioToken(ctx context.Context, instanceID, i
return nil, caos_errs.ThrowNotFound(nil, "COMMAND-fj9wf", "Errors.SMSConfig.NotFound") return nil, caos_errs.ThrowNotFound(nil, "COMMAND-fj9wf", "Errors.SMSConfig.NotFound")
} }
iamAgg := InstanceAggregateFromWriteModel(&smsConfigWriteModel.WriteModel) iamAgg := InstanceAggregateFromWriteModel(&smsConfigWriteModel.WriteModel)
newtoken, err := crypto.Encrypt([]byte(token), c.smsCrypto) newtoken, err := crypto.Encrypt([]byte(token), c.smsEncryption)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -4,6 +4,9 @@ import (
"context" "context"
"testing" "testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
@ -13,8 +16,6 @@ import (
id_mock "github.com/caos/zitadel/internal/id/mock" id_mock "github.com/caos/zitadel/internal/id/mock"
"github.com/caos/zitadel/internal/notification/channels/twilio" "github.com/caos/zitadel/internal/notification/channels/twilio"
"github.com/caos/zitadel/internal/repository/instance" "github.com/caos/zitadel/internal/repository/instance"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
) )
func TestCommandSide_AddSMSConfigTwilio(t *testing.T) { func TestCommandSide_AddSMSConfigTwilio(t *testing.T) {
@ -87,7 +88,7 @@ func TestCommandSide_AddSMSConfigTwilio(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
idGenerator: tt.fields.idGenerator, idGenerator: tt.fields.idGenerator,
smsCrypto: tt.fields.alg, smsEncryption: tt.fields.alg,
} }
_, got, err := r.AddSMSConfigTwilio(tt.args.ctx, tt.args.instanceID, tt.args.sms) _, got, err := r.AddSMSConfigTwilio(tt.args.ctx, tt.args.instanceID, tt.args.sms)
if tt.res.err == nil { if tt.res.err == nil {

View File

@ -20,7 +20,7 @@ func (c *Commands) AddSMTPConfig(ctx context.Context, instanceID string, config
} }
var smtpPassword *crypto.CryptoValue var smtpPassword *crypto.CryptoValue
if config.SMTP.Password != "" { if config.SMTP.Password != "" {
smtpPassword, err = crypto.Encrypt([]byte(config.SMTP.Password), c.smtpPasswordCrypto) smtpPassword, err = crypto.Encrypt([]byte(config.SMTP.Password), c.smtpEncryption)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -90,7 +90,7 @@ func (c *Commands) ChangeSMTPConfigPassword(ctx context.Context, instanceID, pas
return nil, caos_errs.ThrowNotFound(nil, "COMMAND-3n9ls", "Errors.SMTPConfig.NotFound") return nil, caos_errs.ThrowNotFound(nil, "COMMAND-3n9ls", "Errors.SMTPConfig.NotFound")
} }
iamAgg := InstanceAggregateFromWriteModel(&smtpConfigWriteModel.WriteModel) iamAgg := InstanceAggregateFromWriteModel(&smtpConfigWriteModel.WriteModel)
newPW, err := crypto.Encrypt([]byte(password), c.smtpPasswordCrypto) newPW, err := crypto.Encrypt([]byte(password), c.smtpEncryption)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -4,15 +4,15 @@ import (
"context" "context"
"testing" "testing"
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/notification/channels/smtp"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore" "github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/repository" "github.com/caos/zitadel/internal/eventstore/repository"
"github.com/caos/zitadel/internal/notification/channels/smtp"
"github.com/caos/zitadel/internal/repository/instance" "github.com/caos/zitadel/internal/repository/instance"
) )
@ -121,7 +121,7 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
smtpPasswordCrypto: tt.fields.alg, smtpEncryption: tt.fields.alg,
} }
got, err := r.AddSMTPConfig(tt.args.ctx, tt.args.instanceID, tt.args.smtp) got, err := r.AddSMTPConfig(tt.args.ctx, tt.args.instanceID, tt.args.smtp)
if tt.res.err == nil { if tt.res.err == nil {
@ -373,7 +373,7 @@ func TestCommandSide_ChangeSMTPConfigPassword(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
r := &Commands{ r := &Commands{
eventstore: tt.fields.eventstore, eventstore: tt.fields.eventstore,
smtpPasswordCrypto: tt.fields.alg, smtpEncryption: tt.fields.alg,
} }
got, err := r.ChangeSMTPConfigPassword(tt.args.ctx, tt.args.instanceID, tt.args.password) got, err := r.ChangeSMTPConfigPassword(tt.args.ctx, tt.args.instanceID, tt.args.password)
if tt.res.err == nil { if tt.res.err == nil {

View File

@ -51,7 +51,7 @@ func Test_customDomainPolicy(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewDomainPolicyAddedEvent( org.NewDomainPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
true, true,
true, true,
), ),
@ -61,7 +61,7 @@ func Test_customDomainPolicy(t *testing.T) {
want: &PolicyDomainWriteModel{ want: &PolicyDomainWriteModel{
WriteModel: eventstore.WriteModel{ WriteModel: eventstore.WriteModel{
AggregateID: "id", AggregateID: "id",
ResourceOwner: "ro", ResourceOwner: "id",
Events: []eventstore.Event{}, Events: []eventstore.Event{},
}, },
UserLoginMustBeDomain: true, UserLoginMustBeDomain: true,
@ -183,7 +183,7 @@ func Test_DomainPolicy(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewDomainPolicyAddedEvent( org.NewDomainPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
true, true,
true, true,
), ),
@ -193,7 +193,7 @@ func Test_DomainPolicy(t *testing.T) {
want: &PolicyDomainWriteModel{ want: &PolicyDomainWriteModel{
WriteModel: eventstore.WriteModel{ WriteModel: eventstore.WriteModel{
AggregateID: "id", AggregateID: "id",
ResourceOwner: "ro", ResourceOwner: "id",
Events: []eventstore.Event{}, Events: []eventstore.Event{},
}, },
UserLoginMustBeDomain: true, UserLoginMustBeDomain: true,

View File

@ -4,6 +4,8 @@ import (
"context" "context"
"strings" "strings"
"golang.org/x/text/language"
"github.com/caos/zitadel/internal/command/preparation" "github.com/caos/zitadel/internal/command/preparation"
"github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
@ -11,7 +13,6 @@ import (
"github.com/caos/zitadel/internal/eventstore" "github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/v1/models" "github.com/caos/zitadel/internal/eventstore/v1/models"
"github.com/caos/zitadel/internal/repository/user" "github.com/caos/zitadel/internal/repository/user"
"golang.org/x/text/language"
) )
func (c *Commands) getHuman(ctx context.Context, userID, resourceowner string) (*domain.Human, error) { func (c *Commands) getHuman(ctx context.Context, userID, resourceowner string) (*domain.Human, error) {
@ -54,24 +55,20 @@ type AddHuman struct {
} }
func (c *Commands) AddHuman(ctx context.Context, resourceOwner string, human *AddHuman) (*domain.HumanDetails, error) { func (c *Commands) AddHuman(ctx context.Context, resourceOwner string, human *AddHuman) (*domain.HumanDetails, error) {
return c.v2.AddHuman(ctx, resourceOwner, human)
}
func (c *commandNew) AddHuman(ctx context.Context, resourceOwner string, human *AddHuman) (*domain.HumanDetails, error) {
if resourceOwner == "" { if resourceOwner == "" {
return nil, errors.ThrowInvalidArgument(nil, "COMMA-5Ky74", "Errors.Internal") return nil, errors.ThrowInvalidArgument(nil, "COMMA-5Ky74", "Errors.Internal")
} }
userID, err := c.id.Next() userID, err := c.idGenerator.Next()
if err != nil { if err != nil {
return nil, err return nil, err
} }
agg := user.NewAggregate(userID, resourceOwner) agg := user.NewAggregate(userID, resourceOwner)
cmds, err := preparation.PrepareCommands(ctx, c.es.Filter, addHumanCommand(agg, human, c.userPasswordAlg, c.phoneAlg, c.emailAlg, c.initCodeAlg)) cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, AddHumanCommand(agg, human, c.userPasswordAlg, c.smsEncryption, c.smtpEncryption, c.userEncryption))
if err != nil { if err != nil {
return nil, err return nil, err
} }
events, err := c.es.Push(ctx, cmds...) events, err := c.eventstore.Push(ctx, cmds...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -92,7 +89,7 @@ type humanCreationCommand interface {
AddPasswordData(secret *crypto.CryptoValue, changeRequired bool) AddPasswordData(secret *crypto.CryptoValue, changeRequired bool)
} }
func addHumanCommand(a *user.Aggregate, human *AddHuman, passwordAlg crypto.HashAlgorithm, phoneAlg, emailAlg, initCodeAlg crypto.EncryptionAlgorithm) preparation.Validation { func AddHumanCommand(a *user.Aggregate, human *AddHuman, passwordAlg crypto.HashAlgorithm, phoneAlg, emailAlg, initCodeAlg crypto.EncryptionAlgorithm) preparation.Validation {
return func() (_ preparation.CreateCommands, err error) { return func() (_ preparation.CreateCommands, err error) {
if !human.Email.Valid() { if !human.Email.Valid() {
return nil, errors.ThrowInvalidArgument(nil, "USER-Ec7dM", "Errors.Invalid.Argument") return nil, errors.ThrowInvalidArgument(nil, "USER-Ec7dM", "Errors.Invalid.Argument")

View File

@ -177,7 +177,7 @@ func TestCommandSide_AddHumanOTP(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),

View File

@ -1150,7 +1150,7 @@ func TestCommandSide_CheckPassword(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
false, false,
false, false,
@ -1185,7 +1185,7 @@ func TestCommandSide_CheckPassword(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
false, false,
false, false,
@ -1221,7 +1221,7 @@ func TestCommandSide_CheckPassword(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
false, false,
false, false,
@ -1273,7 +1273,7 @@ func TestCommandSide_CheckPassword(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
false, false,
false, false,
@ -1359,7 +1359,7 @@ func TestCommandSide_CheckPassword(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
false, false,
false, false,
@ -1452,7 +1452,7 @@ func TestCommandSide_CheckPassword(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
false, false,
false, false,

View File

@ -688,13 +688,13 @@ func TestCommandSide_AddHuman(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
r := &commandNew{ r := &Commands{
es: tt.fields.eventstore, eventstore: tt.fields.eventstore,
userPasswordAlg: tt.fields.userPasswordAlg, userPasswordAlg: tt.fields.userPasswordAlg,
initCodeAlg: tt.fields.initCodeAlg, userEncryption: tt.fields.initCodeAlg,
emailAlg: tt.fields.emailCodeAlg, smtpEncryption: tt.fields.emailCodeAlg,
id: tt.fields.idGenerator, idGenerator: tt.fields.idGenerator,
phoneAlg: tt.fields.phoneAlg, smsEncryption: tt.fields.phoneAlg,
} }
got, err := r.AddHuman(tt.args.ctx, tt.args.orgID, tt.args.human) got, err := r.AddHuman(tt.args.ctx, tt.args.orgID, tt.args.human)
if tt.res.err == nil { if tt.res.err == nil {
@ -1568,7 +1568,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -1607,7 +1607,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -1616,7 +1616,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -1654,7 +1654,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -1663,7 +1663,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -1675,7 +1675,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
false, false,
false, false,
@ -1717,7 +1717,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -1726,7 +1726,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -1738,7 +1738,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
false, false,
@ -1780,7 +1780,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
), ),
@ -1789,7 +1789,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -1801,7 +1801,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
false, false,
@ -1819,13 +1819,13 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"test.ch", "test.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"test.ch", "test.ch",
), ),
), ),
@ -1860,7 +1860,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
), ),
@ -1869,7 +1869,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -1881,7 +1881,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
false, false,
@ -1899,32 +1899,32 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"test.ch", "test.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"test.ch", "test.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainRemovedEvent(context.Background(), org.NewDomainRemovedEvent(context.Background(),
&org.NewAggregate("org2", "org2").Aggregate, &org.NewAggregate("org2").Aggregate,
"test.ch", "test.ch",
true, true,
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainAddedEvent(context.Background(), org.NewDomainAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test.ch", "test.ch",
), ),
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewDomainVerifiedEvent(context.Background(), org.NewDomainVerifiedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"test.ch", "test.ch",
), ),
), ),
@ -1998,7 +1998,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -2007,7 +2007,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -2019,7 +2019,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
false, false,
@ -2113,7 +2113,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -2125,7 +2125,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
false, false,
@ -2204,7 +2204,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -2213,7 +2213,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -2225,7 +2225,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
false, false,
@ -2326,7 +2326,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewDomainPolicyAddedEvent(context.Background(), org.NewDomainPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
true, true,
true, true,
), ),
@ -2335,7 +2335,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewPasswordComplexityPolicyAddedEvent(context.Background(), org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
1, 1,
false, false,
false, false,
@ -2347,7 +2347,7 @@ func TestCommandSide_RegisterHuman(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewLoginPolicyAddedEvent(context.Background(), org.NewLoginPolicyAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
false, false,
true, true,
false, false,
@ -2897,7 +2897,7 @@ func TestAddHumanCommand(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewDomainPolicyAddedEvent( org.NewDomainPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
true, true,
true, true,
), ),
@ -2908,7 +2908,7 @@ func TestAddHumanCommand(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewPasswordComplexityPolicyAddedEvent( org.NewPasswordComplexityPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
8, 8,
true, true,
true, true,
@ -2940,7 +2940,7 @@ func TestAddHumanCommand(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewDomainPolicyAddedEvent( org.NewDomainPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
true, true,
true, true,
), ),
@ -2951,7 +2951,7 @@ func TestAddHumanCommand(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewPasswordComplexityPolicyAddedEvent( org.NewPasswordComplexityPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
2, 2,
false, false,
false, false,
@ -2984,7 +2984,7 @@ func TestAddHumanCommand(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
AssertValidation(t, addHumanCommand(tt.args.a, tt.args.human, tt.args.passwordAlg, tt.args.phoneAlg, tt.args.emailAlg, tt.args.initCodeAlg), tt.args.filter, tt.want) AssertValidation(t, AddHumanCommand(tt.args.a, tt.args.human, tt.args.passwordAlg, tt.args.phoneAlg, tt.args.emailAlg, tt.args.initCodeAlg), tt.args.filter, tt.want)
}) })
} }
} }

View File

@ -159,7 +159,7 @@ func TestCommandSide_BulkAddUserIDPLinks(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
org.NewIDPConfigAddedEvent(context.Background(), org.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name", "name",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,
@ -209,7 +209,7 @@ func TestCommandSide_BulkAddUserIDPLinks(t *testing.T) {
expectFilter( expectFilter(
eventFromEventPusher( eventFromEventPusher(
instance.NewIDPConfigAddedEvent(context.Background(), instance.NewIDPConfigAddedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"config1", "config1",
"name", "name",
domain.IDPConfigTypeOIDC, domain.IDPConfigTypeOIDC,

View File

@ -18,8 +18,8 @@ func (c *Commands) removeUserMemberships(ctx context.Context, memberships []*que
removeEvent := c.removeInstanceMember(ctx, &iamAgg.Aggregate, membership.UserID, true) removeEvent := c.removeInstanceMember(ctx, &iamAgg.Aggregate, membership.UserID, true)
events = append(events, removeEvent) events = append(events, removeEvent)
} else if membership.Org != nil { } else if membership.Org != nil {
iamAgg := org.NewAggregate(membership.Org.OrgID, membership.ResourceOwner) orgAgg := org.NewAggregate(membership.Org.OrgID)
removeEvent := c.removeOrgMember(ctx, &iamAgg.Aggregate, membership.UserID, true) removeEvent := c.removeOrgMember(ctx, &orgAgg.Aggregate, membership.UserID, true)
events = append(events, removeEvent) events = append(events, removeEvent)
} else if membership.Project != nil { } else if membership.Project != nil {
projectAgg := project.NewAggregate(membership.Project.ProjectID, membership.ResourceOwner) projectAgg := project.NewAggregate(membership.Project.ProjectID, membership.ResourceOwner)

View File

@ -51,7 +51,7 @@ func Test_customPasswordComplexityPolicy(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewPasswordComplexityPolicyAddedEvent( org.NewPasswordComplexityPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
8, 8,
true, true,
true, true,
@ -64,7 +64,7 @@ func Test_customPasswordComplexityPolicy(t *testing.T) {
want: &PasswordComplexityPolicyWriteModel{ want: &PasswordComplexityPolicyWriteModel{
WriteModel: eventstore.WriteModel{ WriteModel: eventstore.WriteModel{
AggregateID: "id", AggregateID: "id",
ResourceOwner: "ro", ResourceOwner: "id",
Events: []eventstore.Event{}, Events: []eventstore.Event{},
}, },
MinLength: 8, MinLength: 8,
@ -195,7 +195,7 @@ func Test_passwordComplexityPolicy(t *testing.T) {
return []eventstore.Event{ return []eventstore.Event{
org.NewPasswordComplexityPolicyAddedEvent( org.NewPasswordComplexityPolicyAddedEvent(
context.Background(), context.Background(),
&org.NewAggregate("id", "ro").Aggregate, &org.NewAggregate("id").Aggregate,
8, 8,
true, true,
true, true,
@ -208,7 +208,7 @@ func Test_passwordComplexityPolicy(t *testing.T) {
want: &PasswordComplexityPolicyWriteModel{ want: &PasswordComplexityPolicyWriteModel{
WriteModel: eventstore.WriteModel{ WriteModel: eventstore.WriteModel{
AggregateID: "id", AggregateID: "id",
ResourceOwner: "ro", ResourceOwner: "id",
Events: []eventstore.Event{}, Events: []eventstore.Event{},
}, },
MinLength: 8, MinLength: 8,

View File

@ -5,11 +5,12 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
"github.com/caos/zitadel/internal/repository/member" "github.com/caos/zitadel/internal/repository/member"
"github.com/caos/zitadel/internal/repository/org" "github.com/caos/zitadel/internal/repository/org"
"github.com/caos/zitadel/internal/repository/project" "github.com/caos/zitadel/internal/repository/project"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
"github.com/caos/zitadel/internal/command/preparation" "github.com/caos/zitadel/internal/command/preparation"
"github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/domain"
@ -1179,7 +1180,7 @@ func TestCommandSide_RemoveUser(t *testing.T) {
), ),
eventFromEventPusher( eventFromEventPusher(
org.NewMemberCascadeRemovedEvent(context.Background(), org.NewMemberCascadeRemovedEvent(context.Background(),
&org.NewAggregate("org1", "org1").Aggregate, &org.NewAggregate("org1").Aggregate,
"user1", "user1",
), ),
), ),

View File

@ -17,13 +17,13 @@ type Aggregate struct {
eventstore.Aggregate eventstore.Aggregate
} }
func NewAggregate(id, resourceOwner string) *Aggregate { func NewAggregate(id string) *Aggregate {
return &Aggregate{ return &Aggregate{
Aggregate: eventstore.Aggregate{ Aggregate: eventstore.Aggregate{
Type: AggregateType, Type: AggregateType,
Version: AggregateVersion, Version: AggregateVersion,
ID: id, ID: id,
ResourceOwner: resourceOwner, ResourceOwner: id,
}, },
} }
} }