2021-03-19 10:12:56 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-12-06 08:01:31 +00:00
|
|
|
"golang.org/x/text/language"
|
2021-03-19 10:12:56 +00:00
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2022-12-06 08:01:31 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
2022-12-06 08:01:31 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/user"
|
2021-03-19 10:12:56 +00:00
|
|
|
)
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
func TestCommandSide_AddDomainPolicy(t *testing.T) {
|
2021-03-19 10:12:56 +00:00
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
userLoginMustBeDomain bool
|
|
|
|
validateOrgDomains bool
|
|
|
|
smtpSenderAddressMatchesInstanceDomain bool
|
2021-03-19 10:12:56 +00:00
|
|
|
}
|
|
|
|
type res struct {
|
2022-12-06 08:01:31 +00:00
|
|
|
want *domain.ObjectDetails
|
2021-03-19 10:12:56 +00:00
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "org id missing, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
userLoginMustBeDomain: true,
|
|
|
|
validateOrgDomains: true,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: true,
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-12-06 08:01:31 +00:00
|
|
|
name: "policy already existing, already exists error",
|
2021-03-19 10:12:56 +00:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 08:05:09 +00:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 14:59:37 +00:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 10:12:56 +00:00
|
|
|
true,
|
2022-04-13 09:24:03 +00:00
|
|
|
true,
|
2022-05-16 14:08:47 +00:00
|
|
|
true,
|
2021-03-19 10:12:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userLoginMustBeDomain: true,
|
|
|
|
validateOrgDomains: true,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: true,
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: caos_errs.IsErrorAlreadyExists,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-12-06 08:01:31 +00:00
|
|
|
name: "add policy, no userLoginMustBeDomain change, ok",
|
2021-03-19 10:12:56 +00:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
2022-12-06 08:01:31 +00:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&instance.NewAggregate("instanceID").Aggregate,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 10:12:56 +00:00
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
2021-03-19 10:12:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userLoginMustBeDomain: true,
|
|
|
|
validateOrgDomains: true,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: true,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
},
|
2022-12-06 08:01:31 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add policy, userLoginMustBeDomain changed, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&instance.NewAggregate("instanceID").Aggregate,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org.com",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"test.com",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainRemovedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"test.com",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPrimarySetEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org.com",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"user1@org.com",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"user1@org.com",
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user2", "org1").Aggregate,
|
|
|
|
"user@test.com",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"user@test.com",
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
user.NewUsernameChangedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"user1@org.com",
|
|
|
|
"user1",
|
|
|
|
true,
|
|
|
|
user.UsernameChangedEventWithPolicyChange(),
|
|
|
|
),
|
|
|
|
user.NewUsernameChangedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user2", "org1").Aggregate,
|
|
|
|
"user@test.com",
|
|
|
|
"user@test.com",
|
|
|
|
true,
|
|
|
|
user.UsernameChangedEventWithPolicyChange(),
|
|
|
|
),
|
2022-12-06 08:01:31 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userLoginMustBeDomain: true,
|
|
|
|
validateOrgDomains: true,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: true,
|
|
|
|
},
|
2021-03-19 10:12:56 +00:00
|
|
|
res: res{
|
2022-12-06 08:01:31 +00:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
2022-12-06 08:01:31 +00:00
|
|
|
got, err := r.AddOrgDomainPolicy(tt.args.ctx, tt.args.orgID, tt.args.userLoginMustBeDomain, tt.args.validateOrgDomains, tt.args.smtpSenderAddressMatchesInstanceDomain)
|
2021-03-19 10:12:56 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.Equal(t, tt.res.want, got)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
func TestCommandSide_ChangeDomainPolicy(t *testing.T) {
|
2021-03-19 10:12:56 +00:00
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
userLoginMustBeDomain bool
|
|
|
|
validateOrgDomains bool
|
|
|
|
smtpSenderAddressMatchesInstanceDomain bool
|
2021-03-19 10:12:56 +00:00
|
|
|
}
|
|
|
|
type res struct {
|
2022-12-06 08:01:31 +00:00
|
|
|
want *domain.ObjectDetails
|
2021-03-19 10:12:56 +00:00
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "org id missing, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
userLoginMustBeDomain: true,
|
|
|
|
validateOrgDomains: true,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: true,
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "policy not existing, not found error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userLoginMustBeDomain: true,
|
|
|
|
validateOrgDomains: true,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: true,
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: caos_errs.IsNotFound,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no changes, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 08:05:09 +00:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 14:59:37 +00:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 10:12:56 +00:00
|
|
|
true,
|
2022-04-13 09:24:03 +00:00
|
|
|
true,
|
2022-05-16 14:08:47 +00:00
|
|
|
true,
|
2021-03-19 10:12:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userLoginMustBeDomain: true,
|
|
|
|
validateOrgDomains: true,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: true,
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: caos_errs.IsPreconditionFailed,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-12-06 08:01:31 +00:00
|
|
|
name: "change, no userLoginMustBeDomain change, ok",
|
2021-03-19 10:12:56 +00:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 08:05:09 +00:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 14:59:37 +00:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2022-12-06 08:01:31 +00:00
|
|
|
false,
|
2022-04-13 09:24:03 +00:00
|
|
|
true,
|
2022-05-16 14:08:47 +00:00
|
|
|
true,
|
2021-03-19 10:12:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
newDomainPolicyChangedEvent(context.Background(), "org1",
|
|
|
|
policy.ChangeValidateOrgDomains(false),
|
|
|
|
policy.ChangeSMTPSenderAddressMatchesInstanceDomain(false),
|
|
|
|
),
|
2021-03-19 10:12:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-12-06 08:01:31 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userLoginMustBeDomain: false,
|
|
|
|
validateOrgDomains: false,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: false,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
},
|
2022-12-06 08:01:31 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "change, userLoginMustBeDomain changed, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPrimarySetEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org.com",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org.com",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"user1",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"user1@org.com",
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
newDomainPolicyChangedEvent(context.Background(), "org1",
|
|
|
|
policy.ChangeUserLoginMustBeDomain(false),
|
|
|
|
policy.ChangeValidateOrgDomains(false),
|
|
|
|
policy.ChangeSMTPSenderAddressMatchesInstanceDomain(false),
|
|
|
|
),
|
|
|
|
user.NewUsernameChangedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"user1",
|
|
|
|
"user1@org.com",
|
|
|
|
false,
|
|
|
|
user.UsernameChangedEventWithPolicyChange(),
|
|
|
|
),
|
2022-12-06 08:01:31 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userLoginMustBeDomain: false,
|
|
|
|
validateOrgDomains: false,
|
|
|
|
smtpSenderAddressMatchesInstanceDomain: false,
|
|
|
|
},
|
2021-03-19 10:12:56 +00:00
|
|
|
res: res{
|
2022-12-06 08:01:31 +00:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2021-03-19 10:12:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
2022-12-06 08:01:31 +00:00
|
|
|
got, err := r.ChangeOrgDomainPolicy(tt.args.ctx, tt.args.orgID, tt.args.userLoginMustBeDomain, tt.args.validateOrgDomains, tt.args.smtpSenderAddressMatchesInstanceDomain)
|
2021-03-19 10:12:56 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.Equal(t, tt.res.want, got)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
func TestCommandSide_RemoveDomainPolicy(t *testing.T) {
|
2021-03-19 10:12:56 +00:00
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "org id missing, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "policy not existing, not found error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: caos_errs.IsNotFound,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-12-06 08:01:31 +00:00
|
|
|
name: "remove, no userLoginMustBeDomain change, ok",
|
2021-03-19 10:12:56 +00:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 08:05:09 +00:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 14:59:37 +00:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 10:12:56 +00:00
|
|
|
true,
|
2022-04-13 09:24:03 +00:00
|
|
|
true,
|
2022-05-16 14:08:47 +00:00
|
|
|
true,
|
2021-03-19 10:12:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-12-06 08:01:31 +00:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&instance.NewAggregate("instanceID").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 10:12:56 +00:00
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
org.NewDomainPolicyRemovedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate),
|
2021-03-19 10:12:56 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-06 08:01:31 +00:00
|
|
|
{
|
|
|
|
name: "remove, userLoginMustBeDomain changed, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&instance.NewAggregate("instanceID").Aggregate,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPrimarySetEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org.com",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org.com",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"user1",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"user1@org.com",
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
org.NewDomainPolicyRemovedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
),
|
|
|
|
user.NewUsernameChangedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"user1",
|
|
|
|
"user1@org.com",
|
|
|
|
false,
|
|
|
|
user.UsernameChangedEventWithPolicyChange(),
|
|
|
|
),
|
2022-12-06 08:01:31 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-19 10:12:56 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
2022-07-21 11:46:59 +00:00
|
|
|
got, err := r.RemoveOrgDomainPolicy(tt.args.ctx, tt.args.orgID)
|
2021-03-19 10:12:56 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
2022-07-21 11:46:59 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.Equal(t, tt.res.want, got)
|
|
|
|
}
|
2021-03-19 10:12:56 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-06 08:01:31 +00:00
|
|
|
func newDomainPolicyChangedEvent(ctx context.Context, orgID string, changes ...policy.DomainPolicyChanges) *org.DomainPolicyChangedEvent {
|
2022-03-28 08:05:09 +00:00
|
|
|
event, _ := org.NewDomainPolicyChangedEvent(ctx,
|
2022-04-20 14:59:37 +00:00
|
|
|
&org.NewAggregate(orgID).Aggregate,
|
2022-12-06 08:01:31 +00:00
|
|
|
changes,
|
2021-03-19 10:12:56 +00:00
|
|
|
)
|
|
|
|
return event
|
|
|
|
}
|