2021-03-19 11:12:56 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-04-26 07:47:57 +02:00
|
|
|
"errors"
|
2021-03-19 11:12:56 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-04-26 07:47:57 +02:00
|
|
|
"github.com/muhlemmer/gu"
|
2021-03-19 11:12:56 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-11-22 12:56:43 +02:00
|
|
|
"go.uber.org/mock/gomock"
|
2021-03-19 11:12:56 +01:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/command/preparation"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-04-26 07:47:57 +02:00
|
|
|
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
|
|
"github.com/zitadel/zitadel/internal/id"
|
|
|
|
id_mock "github.com/zitadel/zitadel/internal/id/mock"
|
2023-08-23 13:55:52 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/idp"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/user"
|
2021-03-19 11:12:56 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommandSide_AddHuman(t *testing.T) {
|
|
|
|
type fields struct {
|
2023-07-14 09:49:57 +03:00
|
|
|
eventstore func(t *testing.T) *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
userPasswordHasher *crypto.PasswordHasher
|
|
|
|
codeAlg crypto.EncryptionAlgorithm
|
|
|
|
newCode cryptoCodeFunc
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
type args struct {
|
2022-02-16 16:49:17 +01:00
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
2022-04-12 16:20:17 +02:00
|
|
|
human *AddHuman
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator crypto.Generator
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail bool
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
type res struct {
|
2023-04-26 07:47:57 +02:00
|
|
|
want *domain.ObjectDetails
|
|
|
|
wantID string
|
|
|
|
wantEmailCode string
|
|
|
|
err func(error) bool
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
2022-04-12 16:20:17 +02:00
|
|
|
|
|
|
|
userAgg := user.NewAggregate("user1", "org1")
|
|
|
|
|
2021-03-19 11:12:56 +01:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "orgid missing, invalid argument error",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "",
|
2022-04-12 16:20:17 +02:00
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, caos_errs.ThrowInvalidArgument(nil, "COMMA-5Ky74", "Errors.Internal"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "user invalid, invalid argument error",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(),
|
2023-04-26 07:47:57 +02:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
},
|
|
|
|
allowInitMail: true,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, caos_errs.ThrowInvalidArgument(nil, "EMAIL-spblu", "Errors.User.Email.Empty"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "with id, already exists, precondition error",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 07:47:57 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", true, true, ""),
|
2023-04-26 07:47:57 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
ID: "user1",
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
},
|
|
|
|
allowInitMail: true,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-k2unb", "Errors.User.AlreadyExisting"))
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-04-12 16:20:17 +02:00
|
|
|
name: "domain policy not found, precondition error",
|
2021-03-19 11:12:56 +01:00
|
|
|
fields: fields{
|
2022-04-12 16:20:17 +02:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2021-03-19 18:46:26 +01:00
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
2022-04-12 16:20:17 +02:00
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, caos_errs.ThrowInternal(nil, "USER-Ggk9n", "Errors.Internal"))
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-19 18:46:26 +01:00
|
|
|
name: "password policy not found, precondition error",
|
2021-03-19 11:12:56 +01:00
|
|
|
fields: fields{
|
2022-04-12 16:20:17 +02:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2021-03-19 18:46:26 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-12 16:20:17 +02:00
|
|
|
&userAgg.Aggregate,
|
2021-03-19 18:46:26 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 18:46:26 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
2022-04-12 16:20:17 +02:00
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Password: "pass",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, caos_errs.ThrowInternal(nil, "USER-uQ96e", "Errors.Internal"))
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with initial code), ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-12 16:20:17 +02:00
|
|
|
&userAgg.Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"",
|
|
|
|
"firstname lastname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("userinit"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2022-04-25 16:36:10 +02:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2023-07-10 11:07:10 +03:00
|
|
|
newCode: mockCode("userinit", time.Hour),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
2022-04-12 16:20:17 +02:00
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
Sequence: 0,
|
|
|
|
EventDate: time.Time{},
|
|
|
|
ResourceOwner: "org1",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
wantID: "user1",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with password and initial code), ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-03-19 11:12:56 +01:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, ""),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("userinit"),
|
|
|
|
},
|
|
|
|
1*time.Hour,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
newCode: mockCode("userinit", time.Hour),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
2022-04-12 16:20:17 +02:00
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
wantID: "user1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with password and email code custom template), ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2023-04-26 07:47:57 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, ""),
|
|
|
|
user.NewHumanEmailCodeAddedEventV2(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("emailCode"),
|
|
|
|
},
|
|
|
|
1*time.Hour,
|
|
|
|
"https://example.com/email/verify?userID={{.UserID}}&code={{.Code}}",
|
|
|
|
false,
|
|
|
|
),
|
2023-04-26 07:47:57 +02:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
newCode: mockCode("emailCode", time.Hour),
|
2023-04-26 07:47:57 +02:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
URLTemplate: "https://example.com/email/verify?userID={{.UserID}}&code={{.Code}}",
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
allowInitMail: false,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
wantID: "user1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with password and return email code), ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2023-04-26 07:47:57 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, ""),
|
|
|
|
user.NewHumanEmailCodeAddedEventV2(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("emailCode"),
|
|
|
|
},
|
|
|
|
1*time.Hour,
|
|
|
|
"",
|
|
|
|
true,
|
|
|
|
),
|
2023-04-26 07:47:57 +02:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
newCode: mockCode("emailCode", time.Hour),
|
2023-04-26 07:47:57 +02:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
ReturnCode: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
allowInitMail: false,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
wantID: "user1",
|
|
|
|
wantEmailCode: "emailCode",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human email verified, ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-12 16:20:17 +02:00
|
|
|
&userAgg.Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-12 16:20:17 +02:00
|
|
|
&userAgg.Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", true, true, ""),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
2022-04-12 16:20:17 +02:00
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
|
|
|
},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2022-04-12 16:20:17 +02:00
|
|
|
PasswordChangeRequired: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
wantID: "user1",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
2022-08-19 15:00:14 +02:00
|
|
|
{
|
|
|
|
name: "add human email verified, trim spaces, ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2022-08-19 15:00:14 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", true, true, ""),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
),
|
2022-08-19 15:00:14 +02:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2022-08-19 15:00:14 +02:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: " username ",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
PasswordChangeRequired: true,
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2022-08-19 15:00:14 +02:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2022-08-19 15:00:14 +02:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
wantID: "user1",
|
2022-08-19 15:00:14 +02:00
|
|
|
},
|
|
|
|
},
|
2022-12-22 12:16:17 +01:00
|
|
|
{
|
|
|
|
name: "add human, email verified, userLoginMustBeDomain false, ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2022-12-22 12:16:17 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", true, false, ""),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
),
|
2022-12-22 12:16:17 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
PasswordChangeRequired: true,
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
wantID: "user1",
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human claimed domain, userLoginMustBeDomain false, error",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2022-12-22 12:16:17 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"test.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username@test.ch",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
PasswordChangeRequired: true,
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, caos_errs.ThrowInvalidArgument(nil, "COMMAND-SFd21", "Errors.User.DomainNotAllowedAsUsername"))
|
|
|
|
},
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human domain, userLoginMustBeDomain false, ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2022-12-22 12:16:17 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"test.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
func() eventstore.Command {
|
|
|
|
event := user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username@test.ch",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"",
|
|
|
|
"firstname lastname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
event.AddPasswordData("$plain$x$password", true)
|
|
|
|
return event
|
|
|
|
}(),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
),
|
2022-12-22 12:16:17 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username@test.ch",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
PasswordChangeRequired: true,
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
wantID: "user1",
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
{
|
|
|
|
name: "add human (with phone), ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-12 16:20:17 +02:00
|
|
|
&userAgg.Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-05-18 14:10:49 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, "+41711234567"),
|
|
|
|
user.NewHumanEmailVerifiedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
),
|
|
|
|
user.NewHumanPhoneCodeAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("phonecode"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
newCode: mockCode("phonecode", time.Hour),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
2022-04-12 16:20:17 +02:00
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
2022-05-18 14:10:49 +02:00
|
|
|
Password: "password",
|
2022-04-12 16:20:17 +02:00
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-04-12 16:20:17 +02:00
|
|
|
Phone: Phone{
|
|
|
|
Number: "+41711234567",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
wantID: "user1",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with verified phone), ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-12 16:20:17 +02:00
|
|
|
&userAgg.Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("", false, true, "+41711234567"),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("userinit"),
|
|
|
|
},
|
|
|
|
1*time.Hour,
|
|
|
|
),
|
|
|
|
user.NewHumanPhoneVerifiedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2022-04-25 16:36:10 +02:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2023-07-10 11:07:10 +03:00
|
|
|
newCode: mockCode("userinit", time.Hour),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
2022-04-12 16:20:17 +02:00
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-04-12 16:20:17 +02:00
|
|
|
Phone: Phone{
|
|
|
|
Number: "+41711234567",
|
|
|
|
Verified: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2023-04-26 07:47:57 +02:00
|
|
|
allowInitMail: true,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
wantID: "user1",
|
|
|
|
},
|
2023-08-03 06:42:59 +02:00
|
|
|
}, {
|
|
|
|
name: "add human (with return code), ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, "+41711234567"),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate),
|
|
|
|
user.NewHumanPhoneCodeAddedEventV2(
|
|
|
|
context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("phoneCode"),
|
|
|
|
},
|
|
|
|
1*time.Hour,
|
|
|
|
true,
|
|
|
|
),
|
2023-08-03 06:42:59 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
newCode: mockCode("phoneCode", time.Hour),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
Password: "password",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
|
|
|
},
|
|
|
|
Phone: Phone{
|
|
|
|
Number: "+41711234567",
|
|
|
|
ReturnCode: true,
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
allowInitMail: true,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
wantID: "user1",
|
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human with metadata, ok",
|
|
|
|
fields: fields{
|
2023-07-10 11:07:10 +03:00
|
|
|
eventstore: expectEventstore(
|
2023-04-26 16:19:32 +02:00
|
|
|
expectFilter(),
|
2023-04-26 07:47:57 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("", false, true, ""),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("userinit"),
|
|
|
|
},
|
|
|
|
1*time.Hour,
|
|
|
|
),
|
|
|
|
user.NewMetadataSetEvent(
|
|
|
|
context.Background(),
|
|
|
|
&userAgg.Aggregate,
|
|
|
|
"testKey",
|
|
|
|
[]byte("testValue"),
|
|
|
|
),
|
2023-04-26 07:47:57 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2023-07-10 11:07:10 +03:00
|
|
|
newCode: mockCode("userinit", time.Hour),
|
2023-04-26 07:47:57 +02:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
Metadata: []*AddMetadataEntry{
|
|
|
|
{
|
|
|
|
Key: "testKey",
|
|
|
|
Value: []byte("testValue"),
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
2023-04-26 07:47:57 +02:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
allowInitMail: true,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
wantID: "user1",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-04-20 16:59:37 +02:00
|
|
|
r := &Commands{
|
2023-07-14 09:49:57 +03:00
|
|
|
eventstore: tt.fields.eventstore(t),
|
|
|
|
userPasswordHasher: tt.fields.userPasswordHasher,
|
|
|
|
userEncryption: tt.fields.codeAlg,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
newCode: tt.fields.newCode,
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
2023-04-26 07:47:57 +02:00
|
|
|
err := r.AddHuman(tt.args.ctx, tt.args.orgID, tt.args.human, tt.args.allowInitMail)
|
2021-03-19 11:12:56 +01:00
|
|
|
if tt.res.err == nil {
|
2022-04-12 16:20:17 +02:00
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
2023-10-19 12:19:10 +02:00
|
|
|
} else if !tt.res.err(err) {
|
2021-03-19 11:12:56 +01:00
|
|
|
t.Errorf("got wrong err: %v ", err)
|
2023-10-19 12:19:10 +02:00
|
|
|
return
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
2023-04-26 07:47:57 +02:00
|
|
|
assert.Equal(t, tt.res.want, tt.args.human.Details)
|
|
|
|
assert.Equal(t, tt.res.wantID, tt.args.human.ID)
|
|
|
|
assert.Equal(t, tt.res.wantEmailCode, gu.Value(tt.args.human.EmailCode))
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-25 14:41:07 +01:00
|
|
|
func TestCommandSide_ImportHuman(t *testing.T) {
|
2021-03-19 11:12:56 +01:00
|
|
|
type fields struct {
|
2023-07-14 09:49:57 +03:00
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
userPasswordHasher *crypto.PasswordHasher
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
type args struct {
|
2022-02-16 16:49:17 +01:00
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
human *domain.Human
|
|
|
|
passwordless bool
|
2022-11-09 09:33:50 +01:00
|
|
|
links []*domain.UserIDPLink
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator crypto.Generator
|
|
|
|
passwordlessInitCode crypto.Generator
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
type res struct {
|
2021-08-02 15:24:58 +02:00
|
|
|
wantHuman *domain.Human
|
|
|
|
wantCode *domain.PasswordlessInitCode
|
|
|
|
err func(error) bool
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "orgid missing, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-25 14:41:07 +01:00
|
|
|
name: "org policy not found, precondition error",
|
2021-03-19 11:12:56 +01:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
2021-03-25 14:41:07 +01:00
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
2021-03-25 14:41:07 +01:00
|
|
|
LastName: "lastname",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2021-03-25 14:41:07 +01:00
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsPreconditionFailed,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-25 14:41:07 +01:00
|
|
|
name: "password policy not found, precondition error",
|
2021-03-19 11:12:56 +01:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
2021-03-25 14:41:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-03-25 14:41:07 +01:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsPreconditionFailed,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-25 14:41:07 +01:00
|
|
|
name: "user invalid, invalid argument error",
|
2021-03-19 11:12:56 +01:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-03-25 14:41:07 +01:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-25 14:41:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with password and initial code), ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-03-25 14:41:07 +01:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", true, true, ""),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
2021-03-19 18:46:26 +01:00
|
|
|
Username: "username",
|
2021-03-25 14:41:07 +01:00
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
ChangeRequired: true,
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
Profile: &domain.Profile{
|
2022-04-28 10:30:41 +02:00
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
PreferredLanguage: language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2021-08-02 15:24:58 +02:00
|
|
|
wantHuman: &domain.Human{
|
2021-03-25 14:41:07 +01:00
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
State: domain.UserStateInitial,
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-25 14:41:07 +01:00
|
|
|
name: "add human email verified password change not required, ok",
|
2021-03-19 11:12:56 +01:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-03-25 14:41:07 +01:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 18:46:26 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2021-03-25 14:41:07 +01:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
2021-03-19 18:46:26 +01:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-25 14:41:07 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, ""),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
),
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
2021-03-25 14:41:07 +01:00
|
|
|
Username: "username",
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
ChangeRequired: false,
|
|
|
|
},
|
|
|
|
Profile: &domain.Profile{
|
2022-04-28 10:30:41 +02:00
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
PreferredLanguage: language.English,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2021-08-02 15:24:58 +02:00
|
|
|
wantHuman: &domain.Human{
|
2021-03-25 14:41:07 +01:00
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
State: domain.UserStateActive,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-08-02 15:24:58 +02:00
|
|
|
{
|
|
|
|
name: "add human email verified passwordless only, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-08-02 15:24:58 +02:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-08-02 15:24:58 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("", false, true, ""),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate),
|
|
|
|
user.NewHumanPasswordlessInitCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"code1",
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour,
|
|
|
|
),
|
2021-08-02 15:24:58 +02:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1", "code1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-08-02 15:24:58 +02:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
2022-04-28 10:30:41 +02:00
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
PreferredLanguage: language.English,
|
2021-08-02 15:24:58 +02:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
passwordless: true,
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
passwordlessInitCode: GetMockSecretGenerator(t),
|
2021-08-02 15:24:58 +02:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
wantHuman: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-08-02 15:24:58 +02:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
State: domain.UserStateActive,
|
|
|
|
},
|
|
|
|
wantCode: &domain.PasswordlessInitCode{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Expiration: time.Hour,
|
|
|
|
CodeID: "code1",
|
|
|
|
Code: "a",
|
|
|
|
State: domain.PasswordlessInitCodeStateActive,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human email verified passwordless and password change not required, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-08-02 15:24:58 +02:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-08-02 15:24:58 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, ""),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate),
|
|
|
|
user.NewHumanPasswordlessInitCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"code1",
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour,
|
|
|
|
),
|
2021-08-02 15:24:58 +02:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1", "code1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-08-02 15:24:58 +02:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
ChangeRequired: false,
|
|
|
|
},
|
|
|
|
Profile: &domain.Profile{
|
2022-04-28 10:30:41 +02:00
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
PreferredLanguage: language.English,
|
2021-08-02 15:24:58 +02:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
passwordless: true,
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
passwordlessInitCode: GetMockSecretGenerator(t),
|
2021-08-02 15:24:58 +02:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
wantHuman: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-08-02 15:24:58 +02:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
State: domain.UserStateActive,
|
|
|
|
},
|
|
|
|
wantCode: &domain.PasswordlessInitCode{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Expiration: time.Hour,
|
|
|
|
CodeID: "code1",
|
|
|
|
Code: "a",
|
|
|
|
State: domain.PasswordlessInitCodeStateActive,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-25 14:41:07 +01:00
|
|
|
{
|
|
|
|
name: "add human (with phone), ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-03-25 14:41:07 +01:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, "+41711234567"),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
|
|
|
user.NewHumanPhoneCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1),
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
2022-04-28 10:30:41 +02:00
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
PreferredLanguage: language.English,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
ChangeRequired: false,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Phone: &domain.Phone{
|
|
|
|
PhoneNumber: "+41711234567",
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2021-08-02 15:24:58 +02:00
|
|
|
wantHuman: &domain.Human{
|
2021-03-25 14:41:07 +01:00
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Phone: &domain.Phone{
|
|
|
|
PhoneNumber: "+41711234567",
|
|
|
|
},
|
|
|
|
State: domain.UserStateInitial,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with verified phone), ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-03-25 14:41:07 +01:00
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("$plain$x$password", false, true, "+41711234567"),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
|
|
|
user.NewHumanPhoneVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate),
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
2022-04-28 10:30:41 +02:00
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
PreferredLanguage: language.English,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
ChangeRequired: false,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Phone: &domain.Phone{
|
|
|
|
PhoneNumber: "+41711234567",
|
|
|
|
IsPhoneVerified: true,
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2021-08-02 15:24:58 +02:00
|
|
|
wantHuman: &domain.Human{
|
2021-03-25 14:41:07 +01:00
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Phone: &domain.Phone{
|
|
|
|
PhoneNumber: "+41711234567",
|
|
|
|
},
|
|
|
|
State: domain.UserStateInitial,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-11-09 09:33:50 +01:00
|
|
|
{
|
|
|
|
name: "add human (with idp), ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-08-23 13:55:52 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
"name",
|
|
|
|
domain.IDPConfigTypeOIDC,
|
|
|
|
domain.IDPConfigStylingTypeUnspecified,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPOIDCConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"clientID",
|
|
|
|
"idpID",
|
|
|
|
"issuer",
|
|
|
|
"authEndpoint",
|
|
|
|
"tokenEndpoint",
|
|
|
|
nil,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-11-09 09:33:50 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
"name",
|
|
|
|
domain.IDPConfigTypeOIDC,
|
|
|
|
domain.IDPConfigStylingTypeUnspecified,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPOIDCConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"clientID",
|
|
|
|
"idpID",
|
|
|
|
"issuer",
|
|
|
|
"authEndpoint",
|
|
|
|
"tokenEndpoint",
|
|
|
|
nil,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIdentityProviderAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
domain.IdentityProviderTypeOrg,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newAddHumanEvent("", false, true, ""),
|
|
|
|
user.NewUserIDPLinkAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
"name",
|
|
|
|
"externalID",
|
|
|
|
),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate),
|
2022-11-09 09:33:50 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2022-11-09 09:33:50 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
links: []*domain.UserIDPLink{
|
|
|
|
{
|
|
|
|
IDPConfigID: "idpID",
|
|
|
|
ExternalUserID: "externalID",
|
|
|
|
DisplayName: "name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
wantHuman: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
State: domain.UserStateActive,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-23 13:55:52 +02:00
|
|
|
{
|
|
|
|
name: "add human (with idp, creation not allowed), precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
"name",
|
|
|
|
domain.IDPConfigTypeOIDC,
|
|
|
|
domain.IDPConfigStylingTypeUnspecified,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPOIDCConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"clientID",
|
|
|
|
"idpID",
|
|
|
|
"issuer",
|
|
|
|
"authEndpoint",
|
|
|
|
"tokenEndpoint",
|
|
|
|
nil,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
func() eventstore.Command {
|
|
|
|
e, _ := org.NewOIDCIDPChangedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"config1",
|
|
|
|
[]idp.OIDCIDPChanges{
|
|
|
|
idp.ChangeOIDCOptions(idp.OptionChanges{IsCreationAllowed: gu.Ptr(false)}),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return e
|
|
|
|
}(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
"name",
|
|
|
|
domain.IDPConfigTypeOIDC,
|
|
|
|
domain.IDPConfigStylingTypeUnspecified,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPOIDCConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"clientID",
|
|
|
|
"idpID",
|
|
|
|
"issuer",
|
|
|
|
"authEndpoint",
|
|
|
|
"tokenEndpoint",
|
|
|
|
nil,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
func() eventstore.Command {
|
|
|
|
e, _ := org.NewOIDCIDPChangedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"config1",
|
|
|
|
[]idp.OIDCIDPChanges{
|
|
|
|
idp.ChangeOIDCOptions(idp.OptionChanges{IsCreationAllowed: gu.Ptr(false)}),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return e
|
|
|
|
}(),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIdentityProviderAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
domain.IdentityProviderTypeOrg,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
links: []*domain.UserIDPLink{
|
|
|
|
{
|
|
|
|
IDPConfigID: "idpID",
|
|
|
|
ExternalUserID: "externalID",
|
|
|
|
DisplayName: "name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: caos_errs.IsPreconditionFailed,
|
|
|
|
},
|
|
|
|
},
|
2021-03-25 14:41:07 +01:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
2023-07-14 09:49:57 +03:00
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
userPasswordHasher: tt.fields.userPasswordHasher,
|
2021-03-25 14:41:07 +01:00
|
|
|
}
|
2022-11-09 09:33:50 +01:00
|
|
|
gotHuman, gotCode, err := r.ImportHuman(tt.args.ctx, tt.args.orgID, tt.args.human, tt.args.passwordless, tt.args.links, tt.args.secretGenerator, tt.args.secretGenerator, tt.args.secretGenerator, tt.args.secretGenerator)
|
2021-03-25 14:41:07 +01: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 {
|
2021-08-02 15:24:58 +02:00
|
|
|
assert.Equal(t, tt.res.wantHuman, gotHuman)
|
|
|
|
assert.Equal(t, tt.res.wantCode, gotCode)
|
2021-03-25 14:41:07 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_RegisterHuman(t *testing.T) {
|
|
|
|
type fields struct {
|
2023-07-14 09:49:57 +03:00
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
userPasswordHasher *crypto.PasswordHasher
|
2021-03-25 14:41:07 +01:00
|
|
|
}
|
|
|
|
type args struct {
|
2022-02-16 16:49:17 +01:00
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
human *domain.Human
|
|
|
|
link *domain.UserIDPLink
|
|
|
|
orgMemberRoles []string
|
|
|
|
secretGenerator crypto.Generator
|
2021-03-25 14:41:07 +01:00
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.Human
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "orgid missing, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-08-25 11:12:24 +02:00
|
|
|
name: "org policy not found, precondition error",
|
2021-03-25 14:41:07 +01:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
2021-08-25 11:12:24 +02:00
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
2021-08-25 11:12:24 +02:00
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsPreconditionFailed,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-08-25 11:12:24 +02:00
|
|
|
name: "password policy not found, precondition error",
|
2021-03-25 14:41:07 +01:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
2021-08-25 11:12:24 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-08-25 11:12:24 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-25 14:41:07 +01:00
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsPreconditionFailed,
|
2021-03-25 14:41:07 +01:00
|
|
|
},
|
|
|
|
},
|
2021-11-08 08:42:07 +01:00
|
|
|
{
|
|
|
|
name: "login policy not found, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsPreconditionFailed,
|
2021-11-08 08:42:07 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "login policy registration not allowed, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2022-05-16 15:39:09 +02:00
|
|
|
false,
|
2022-10-06 13:30:14 +02:00
|
|
|
false,
|
2022-10-17 21:19:15 +02:00
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2021-11-08 08:42:07 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
2022-05-16 15:39:09 +02:00
|
|
|
"",
|
2022-02-21 16:05:02 +01:00
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsPreconditionFailed,
|
2021-11-08 08:42:07 +01:00
|
|
|
},
|
|
|
|
},
|
2021-03-25 14:41:07 +01:00
|
|
|
{
|
2021-08-25 11:12:24 +02:00
|
|
|
name: "user invalid, invalid argument error",
|
2021-03-25 14:41:07 +01:00
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-25 14:41:07 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-08-25 11:12:24 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-08 08:42:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2022-05-16 15:39:09 +02:00
|
|
|
false,
|
2022-10-06 13:30:14 +02:00
|
|
|
false,
|
2022-10-17 21:19:15 +02:00
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2021-11-08 08:42:07 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
2022-05-16 15:39:09 +02:00
|
|
|
"",
|
2022-02-21 16:05:02 +01:00
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-25 14:41:07 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
2021-08-25 11:12:24 +02:00
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
2021-08-25 11:12:24 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "email domain reserved, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
false,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-08-25 11:12:24 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-08 08:42:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2022-05-16 15:39:09 +02:00
|
|
|
false,
|
2022-10-06 13:30:14 +02:00
|
|
|
false,
|
2022-10-17 21:19:15 +02:00
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2021-11-08 08:42:07 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
2022-05-16 15:39:09 +02:00
|
|
|
"",
|
2022-02-21 16:05:02 +01:00
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-08-25 11:12:24 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org2").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
"test.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org2").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
"test.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
2021-08-25 11:12:24 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
2021-08-25 11:12:24 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "email domain reserved, same org, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
false,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-08-25 11:12:24 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-08 08:42:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2022-05-16 15:39:09 +02:00
|
|
|
false,
|
2022-10-06 13:30:14 +02:00
|
|
|
false,
|
2022-10-17 21:19:15 +02:00
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2021-11-08 08:42:07 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
2022-05-16 15:39:09 +02:00
|
|
|
"",
|
2022-02-21 16:05:02 +01:00
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-08-25 11:12:24 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org2").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
"test.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org2").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
"test.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainRemovedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org2").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
"test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
"test.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
"test.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newRegisterHumanEvent("email@test.ch", "$plain$x$password", false, false, ""),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
2021-08-25 11:12:24 +02:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-08-25 11:12:24 +02:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
2021-03-19 11:12:56 +01:00
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
2021-08-25 11:12:24 +02:00
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2021-08-25 11:12:24 +02:00
|
|
|
want: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "email@test.ch",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
|
|
|
PreferredLanguage: language.Und,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
State: domain.UserStateInitial,
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
2022-12-22 12:16:17 +01:00
|
|
|
{
|
|
|
|
name: "username without @, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2022-12-22 12:16:17 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
|
|
|
"",
|
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newRegisterHumanEvent("username", "$plain$x$password", false, false, ""),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
2022-12-22 12:16:17 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2022-12-22 12:16:17 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
|
|
|
PreferredLanguage: language.Und,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
State: domain.UserStateInitial,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
{
|
|
|
|
name: "add human (with password and initial code), ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-08 08:42:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2022-05-16 15:39:09 +02:00
|
|
|
false,
|
2022-10-06 13:30:14 +02:00
|
|
|
false,
|
2022-10-17 21:19:15 +02:00
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2021-11-08 08:42:07 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
2022-05-16 15:39:09 +02:00
|
|
|
"",
|
2022-02-21 16:05:02 +01:00
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newRegisterHumanEvent("username", "$plain$x$password", false, true, ""),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
|
|
|
PreferredLanguage: language.Und,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
State: domain.UserStateInitial,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human email verified, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2021-03-19 18:46:26 +01:00
|
|
|
&user.NewAggregate("org1", "org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-08 08:42:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2022-05-16 15:39:09 +02:00
|
|
|
false,
|
2022-10-06 13:30:14 +02:00
|
|
|
false,
|
2022-10-17 21:19:15 +02:00
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2021-11-08 08:42:07 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
2022-05-16 15:39:09 +02:00
|
|
|
"",
|
2022-02-21 16:05:02 +01:00
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newRegisterHumanEvent("username", "$plain$x$password", false, true, ""),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
|
|
|
PreferredLanguage: language.Und,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
2021-03-22 14:40:25 +01:00
|
|
|
State: domain.UserStateActive,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with phone), ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-08 08:42:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2022-05-16 15:39:09 +02:00
|
|
|
false,
|
2022-10-06 13:30:14 +02:00
|
|
|
false,
|
2022-10-17 21:19:15 +02:00
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2021-11-08 08:42:07 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
2022-05-16 15:39:09 +02:00
|
|
|
"",
|
2022-02-21 16:05:02 +01:00
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newRegisterHumanEvent("username", "$plain$x$password", false, true, "+41711234567"),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
|
|
|
user.NewHumanPhoneCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Phone: &domain.Phone{
|
|
|
|
PhoneNumber: "+41711234567",
|
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
|
|
|
PreferredLanguage: language.Und,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Phone: &domain.Phone{
|
|
|
|
PhoneNumber: "+41711234567",
|
|
|
|
},
|
|
|
|
State: domain.UserStateInitial,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add human (with verified phone), ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
true,
|
2022-04-13 11:24:03 +02:00
|
|
|
true,
|
2022-05-16 16:08:47 +02:00
|
|
|
true,
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-08 08:42:07 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-11-08 08:42:07 +01:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2022-05-16 15:39:09 +02:00
|
|
|
false,
|
2022-10-06 13:30:14 +02:00
|
|
|
false,
|
2022-10-17 21:19:15 +02:00
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2021-11-08 08:42:07 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
2022-05-16 15:39:09 +02:00
|
|
|
"",
|
2022-02-21 16:05:02 +01:00
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
2021-11-08 08:42:07 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newRegisterHumanEvent("username", "$plain$x$password", false, true, "+41711234567"),
|
|
|
|
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
time.Hour*1,
|
|
|
|
),
|
|
|
|
user.NewHumanPhoneVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Phone: &domain.Phone{
|
|
|
|
PhoneNumber: "+41711234567",
|
|
|
|
IsPhoneVerified: true,
|
|
|
|
},
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
},
|
2022-02-16 16:49:17 +01:00
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
|
|
|
PreferredLanguage: language.Und,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
},
|
|
|
|
Phone: &domain.Phone{
|
|
|
|
PhoneNumber: "+41711234567",
|
|
|
|
},
|
|
|
|
State: domain.UserStateInitial,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-11-09 09:33:50 +01:00
|
|
|
{
|
|
|
|
name: "add with idp link, email verified, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("org1", "org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewLoginPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
2023-07-20 06:06:16 +02:00
|
|
|
false,
|
2022-11-09 09:33:50 +01:00
|
|
|
domain.PasswordlessTypeNotAllowed,
|
|
|
|
"",
|
|
|
|
time.Hour*1,
|
|
|
|
time.Hour*2,
|
|
|
|
time.Hour*3,
|
|
|
|
time.Hour*4,
|
|
|
|
time.Hour*5,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
"name",
|
|
|
|
domain.IDPConfigTypeOIDC,
|
|
|
|
domain.IDPConfigStylingTypeUnspecified,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPOIDCConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"clientID",
|
|
|
|
"idpID",
|
|
|
|
"issuer",
|
|
|
|
"authEndpoint",
|
|
|
|
"tokenEndpoint",
|
|
|
|
nil,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIdentityProviderAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
domain.IdentityProviderTypeOrg,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-08-23 13:55:52 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
"name",
|
|
|
|
domain.IDPConfigTypeOIDC,
|
|
|
|
domain.IDPConfigStylingTypeUnspecified,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewIDPOIDCConfigAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"clientID",
|
|
|
|
"idpID",
|
|
|
|
"issuer",
|
|
|
|
"authEndpoint",
|
|
|
|
"tokenEndpoint",
|
|
|
|
nil,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
domain.OIDCMappingFieldUnspecified,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-11-09 09:33:50 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
newRegisterHumanEvent("username", "$plain$x$password", false, true, ""),
|
|
|
|
user.NewUserIDPLinkAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"idpID",
|
|
|
|
"displayName",
|
|
|
|
"externalID",
|
|
|
|
),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
),
|
2022-11-09 09:33:50 +01:00
|
|
|
),
|
|
|
|
),
|
2023-07-14 09:49:57 +03:00
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
|
|
|
userPasswordHasher: mockPasswordHasher("x"),
|
2022-11-09 09:33:50 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
human: &domain.Human{
|
|
|
|
Username: "username",
|
|
|
|
Password: &domain.Password{
|
|
|
|
SecretString: "password",
|
|
|
|
},
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
link: &domain.UserIDPLink{
|
|
|
|
IDPConfigID: "idpID",
|
|
|
|
ExternalUserID: "externalID",
|
|
|
|
DisplayName: "displayName",
|
|
|
|
},
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.Human{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "user1",
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
Username: "username",
|
|
|
|
Profile: &domain.Profile{
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
DisplayName: "firstname lastname",
|
|
|
|
PreferredLanguage: language.Und,
|
|
|
|
},
|
|
|
|
Email: &domain.Email{
|
|
|
|
EmailAddress: "email@test.ch",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
State: domain.UserStateActive,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
2023-07-14 09:49:57 +03:00
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
userPasswordHasher: tt.fields.userPasswordHasher,
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
2022-10-18 16:48:26 +02:00
|
|
|
got, err := r.RegisterHuman(tt.args.ctx, tt.args.orgID, tt.args.human, tt.args.link, tt.args.orgMemberRoles, tt.args.secretGenerator, tt.args.secretGenerator, tt.args.secretGenerator)
|
2021-03-19 11:12:56 +01: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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_HumanMFASkip(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type (
|
|
|
|
args struct {
|
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
userID string
|
|
|
|
}
|
|
|
|
)
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "userid missing, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userID: "",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "user not existing, not found error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userID: "user1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsNotFound,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "skip mfa init, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.German,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
user.NewHumanMFAInitSkippedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
userID: "user1",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
|
|
|
err := r.HumanSkipMFAInit(tt.args.ctx, tt.args.userID, tt.args.orgID)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_HumanSignOut(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type (
|
|
|
|
args struct {
|
|
|
|
ctx context.Context
|
|
|
|
agentID string
|
|
|
|
userIDs []string
|
|
|
|
}
|
|
|
|
)
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "agentid missing, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
agentID: "",
|
|
|
|
userIDs: []string{"user1"},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "userids missing, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
agentID: "agent1",
|
|
|
|
userIDs: []string{},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-04-26 07:47:57 +02:00
|
|
|
err: caos_errs.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "user not existing, not found error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
agentID: "agent1",
|
|
|
|
userIDs: []string{"user1"},
|
|
|
|
},
|
|
|
|
res: res{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "human sign out, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.German,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
user.NewHumanSignedOutEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"agent1",
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
agentID: "agent1",
|
|
|
|
userIDs: []string{"user1"},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "human sign out multiple users, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.German,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user2", "org1").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.German,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
user.NewHumanSignedOutEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"agent1",
|
|
|
|
),
|
|
|
|
user.NewHumanSignedOutEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user2", "org1").Aggregate,
|
|
|
|
"agent1",
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
agentID: "agent1",
|
|
|
|
userIDs: []string{"user1", "user2"},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
|
|
|
err := r.HumansSignOut(tt.args.ctx, tt.args.agentID, tt.args.userIDs)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func newAddHumanEvent(password string, changeRequired, userLoginMustBeDomain bool, phone string) *user.HumanAddedEvent {
|
2021-03-19 11:12:56 +01:00
|
|
|
event := user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"",
|
|
|
|
"firstname lastname",
|
2022-04-28 10:30:41 +02:00
|
|
|
language.English,
|
2021-03-19 11:12:56 +01:00
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
2023-10-19 12:19:10 +02:00
|
|
|
userLoginMustBeDomain,
|
2021-03-19 11:12:56 +01:00
|
|
|
)
|
|
|
|
if password != "" {
|
2023-07-14 09:49:57 +03:00
|
|
|
event.AddPasswordData(password, changeRequired)
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
if phone != "" {
|
2023-03-14 20:20:38 +01:00
|
|
|
event.AddPhoneData(domain.PhoneNumber(phone))
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
return event
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func newRegisterHumanEvent(username, password string, changeRequired, userLoginMustBeUnique bool, phone string) *user.HumanRegisteredEvent {
|
2021-03-19 11:12:56 +01:00
|
|
|
event := user.NewHumanRegisteredEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
2021-08-25 11:12:24 +02:00
|
|
|
username,
|
2021-03-19 11:12:56 +01:00
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"",
|
|
|
|
"firstname lastname",
|
|
|
|
language.Und,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
2023-10-19 12:19:10 +02:00
|
|
|
userLoginMustBeUnique,
|
2021-03-19 11:12:56 +01:00
|
|
|
)
|
|
|
|
if password != "" {
|
2023-07-14 09:49:57 +03:00
|
|
|
event.AddPasswordData(password, changeRequired)
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
if phone != "" {
|
2023-03-14 20:20:38 +01:00
|
|
|
event.AddPhoneData(domain.PhoneNumber(phone))
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
return event
|
|
|
|
}
|
2022-04-12 16:20:17 +02:00
|
|
|
|
|
|
|
func TestAddHumanCommand(t *testing.T) {
|
2023-04-26 07:47:57 +02:00
|
|
|
type fields struct {
|
|
|
|
idGenerator id.Generator
|
|
|
|
}
|
2022-04-12 16:20:17 +02:00
|
|
|
type args struct {
|
2023-04-26 07:47:57 +02:00
|
|
|
human *AddHuman
|
2023-04-26 16:19:32 +02:00
|
|
|
orgID string
|
2023-07-14 09:49:57 +03:00
|
|
|
hasher *crypto.PasswordHasher
|
2023-04-26 07:47:57 +02:00
|
|
|
filter preparation.FilterToQueryReducer
|
|
|
|
codeAlg crypto.EncryptionAlgorithm
|
|
|
|
allowInitMail bool
|
2022-04-12 16:20:17 +02:00
|
|
|
}
|
|
|
|
agg := user.NewAggregate("id", "ro")
|
|
|
|
tests := []struct {
|
2023-04-26 07:47:57 +02:00
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want Want
|
2022-04-12 16:20:17 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid email",
|
|
|
|
args: args{
|
|
|
|
human: &AddHuman{
|
|
|
|
Email: Email{
|
|
|
|
Address: "invalid",
|
|
|
|
},
|
|
|
|
},
|
2023-04-26 16:19:32 +02:00
|
|
|
orgID: "ro",
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
want: Want{
|
2023-04-26 07:47:57 +02:00
|
|
|
ValidationErr: caos_errs.ThrowInvalidArgument(nil, "EMAIL-599BI", "Errors.User.Email.Invalid"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
2022-04-28 10:30:41 +02:00
|
|
|
{
|
|
|
|
name: "invalid first name",
|
|
|
|
args: args{
|
|
|
|
human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
Email: Email{
|
2022-05-20 16:32:06 +02:00
|
|
|
Address: "support@zitadel.com",
|
2022-04-28 10:30:41 +02:00
|
|
|
},
|
|
|
|
},
|
2023-04-26 16:19:32 +02:00
|
|
|
orgID: "ro",
|
2022-04-28 10:30:41 +02:00
|
|
|
},
|
2022-04-12 16:20:17 +02:00
|
|
|
want: Want{
|
2023-04-26 07:47:57 +02:00
|
|
|
ValidationErr: caos_errs.ThrowInvalidArgument(nil, "USER-UCej2", "Errors.User.Profile.FirstNameEmpty"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid last name",
|
|
|
|
args: args{
|
|
|
|
human: &AddHuman{
|
2022-04-28 10:30:41 +02:00
|
|
|
Username: "username",
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
FirstName: "hurst",
|
2022-05-20 16:32:06 +02:00
|
|
|
Email: Email{Address: "support@zitadel.com"},
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
2023-04-26 16:19:32 +02:00
|
|
|
orgID: "ro",
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
want: Want{
|
2023-04-26 07:47:57 +02:00
|
|
|
ValidationErr: caos_errs.ThrowInvalidArgument(nil, "USER-4hB7d", "Errors.User.Profile.LastNameEmpty"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
2023-07-14 09:49:57 +03:00
|
|
|
{
|
|
|
|
name: "unsupported password hash encoding",
|
|
|
|
args: args{
|
|
|
|
human: &AddHuman{
|
|
|
|
Email: Email{Address: "support@zitadel.com", Verified: true},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
FirstName: "gigi",
|
|
|
|
LastName: "giraffe",
|
|
|
|
EncodedPasswordHash: "$foo$x$password",
|
|
|
|
Username: "username",
|
|
|
|
},
|
|
|
|
orgID: "ro",
|
|
|
|
hasher: mockPasswordHasher("x"),
|
|
|
|
},
|
|
|
|
want: Want{
|
|
|
|
ValidationErr: caos_errs.ThrowInvalidArgument(nil, "USER-JDk4t", "Errors.User.Password.NotSupported"),
|
|
|
|
},
|
|
|
|
},
|
2022-04-12 16:20:17 +02:00
|
|
|
{
|
|
|
|
name: "invalid password",
|
2023-04-26 07:47:57 +02:00
|
|
|
fields: fields{
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "id"),
|
|
|
|
},
|
2022-04-12 16:20:17 +02:00
|
|
|
args: args{
|
|
|
|
human: &AddHuman{
|
2022-05-20 16:32:06 +02:00
|
|
|
Email: Email{Address: "support@zitadel.com"},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
|
|
|
FirstName: "gigi",
|
|
|
|
LastName: "giraffe",
|
|
|
|
Password: "short",
|
|
|
|
Username: "username",
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
2023-04-26 16:19:32 +02:00
|
|
|
orgID: "ro",
|
2022-04-12 16:20:17 +02:00
|
|
|
filter: NewMultiFilter().Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
2023-04-26 16:19:32 +02:00
|
|
|
return []eventstore.Event{}, nil
|
2022-04-12 16:20:17 +02:00
|
|
|
}).
|
2023-04-26 16:19:32 +02:00
|
|
|
Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewDomainPolicyAddedEvent(
|
|
|
|
ctx,
|
|
|
|
&org.NewAggregate("id").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
}, nil
|
|
|
|
}).
|
2022-04-12 16:20:17 +02:00
|
|
|
Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(
|
2023-04-26 16:19:32 +02:00
|
|
|
ctx,
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("id").Aggregate,
|
2022-04-12 16:20:17 +02:00
|
|
|
8,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
}, nil
|
|
|
|
}).
|
|
|
|
Filter(),
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-04-26 07:47:57 +02:00
|
|
|
CreateErr: caos_errs.ThrowInvalidArgument(nil, "COMMA-HuJf6", "Errors.User.PasswordComplexityPolicy.MinLength"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "correct",
|
2023-04-26 07:47:57 +02:00
|
|
|
fields: fields{
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "id"),
|
|
|
|
},
|
2022-04-12 16:20:17 +02:00
|
|
|
args: args{
|
|
|
|
human: &AddHuman{
|
2022-05-20 16:32:06 +02:00
|
|
|
Email: Email{Address: "support@zitadel.com", Verified: true},
|
2022-04-28 10:30:41 +02:00
|
|
|
PreferredLanguage: language.English,
|
|
|
|
FirstName: "gigi",
|
|
|
|
LastName: "giraffe",
|
2022-05-18 14:10:49 +02:00
|
|
|
Password: "password",
|
2022-04-28 10:30:41 +02:00
|
|
|
Username: "username",
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
2023-07-14 09:49:57 +03:00
|
|
|
orgID: "ro",
|
|
|
|
hasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
filter: NewMultiFilter().Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{}, nil
|
|
|
|
}).
|
|
|
|
Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewDomainPolicyAddedEvent(
|
|
|
|
ctx,
|
|
|
|
&org.NewAggregate("id").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
}, nil
|
|
|
|
}).
|
|
|
|
Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(
|
|
|
|
ctx,
|
|
|
|
&org.NewAggregate("id").Aggregate,
|
|
|
|
2,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
}, nil
|
|
|
|
}).
|
|
|
|
Filter(),
|
|
|
|
},
|
|
|
|
want: Want{
|
|
|
|
Commands: []eventstore.Command{
|
|
|
|
func() *user.HumanAddedEvent {
|
|
|
|
event := user.NewHumanAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&agg.Aggregate,
|
|
|
|
"username",
|
|
|
|
"gigi",
|
|
|
|
"giraffe",
|
|
|
|
"",
|
|
|
|
"gigi giraffe",
|
|
|
|
language.English,
|
|
|
|
0,
|
|
|
|
"support@zitadel.com",
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
event.AddPasswordData("$plain$x$password", false)
|
|
|
|
return event
|
|
|
|
}(),
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(), &agg.Aggregate),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "hashed password",
|
|
|
|
fields: fields{
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "id"),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
human: &AddHuman{
|
|
|
|
Email: Email{Address: "support@zitadel.com", Verified: true},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
FirstName: "gigi",
|
|
|
|
LastName: "giraffe",
|
|
|
|
EncodedPasswordHash: "$plain$x$password",
|
|
|
|
Username: "username",
|
|
|
|
},
|
|
|
|
orgID: "ro",
|
|
|
|
hasher: mockPasswordHasher("x"),
|
|
|
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
2022-04-12 16:20:17 +02:00
|
|
|
filter: NewMultiFilter().Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
2023-04-26 16:19:32 +02:00
|
|
|
return []eventstore.Event{}, nil
|
2022-04-12 16:20:17 +02:00
|
|
|
}).
|
2023-04-26 16:19:32 +02:00
|
|
|
Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewDomainPolicyAddedEvent(
|
|
|
|
ctx,
|
|
|
|
&org.NewAggregate("id").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
}, nil
|
|
|
|
}).
|
2022-04-12 16:20:17 +02:00
|
|
|
Append(
|
|
|
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewPasswordComplexityPolicyAddedEvent(
|
2023-04-26 16:19:32 +02:00
|
|
|
ctx,
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("id").Aggregate,
|
2022-04-12 16:20:17 +02:00
|
|
|
2,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
}, nil
|
|
|
|
}).
|
|
|
|
Filter(),
|
|
|
|
},
|
|
|
|
want: Want{
|
|
|
|
Commands: []eventstore.Command{
|
2022-05-18 14:10:49 +02:00
|
|
|
func() *user.HumanAddedEvent {
|
|
|
|
event := user.NewHumanAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&agg.Aggregate,
|
|
|
|
"username",
|
|
|
|
"gigi",
|
|
|
|
"giraffe",
|
|
|
|
"",
|
|
|
|
"gigi giraffe",
|
|
|
|
language.English,
|
|
|
|
0,
|
2022-05-20 16:32:06 +02:00
|
|
|
"support@zitadel.com",
|
2022-05-18 14:10:49 +02:00
|
|
|
true,
|
|
|
|
)
|
2023-07-14 09:49:57 +03:00
|
|
|
event.AddPasswordData("$plain$x$password", false)
|
2022-05-18 14:10:49 +02:00
|
|
|
return event
|
|
|
|
}(),
|
2022-04-12 16:20:17 +02:00
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(), &agg.Aggregate),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-04-26 07:47:57 +02:00
|
|
|
c := &Commands{
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
}
|
2023-07-14 09:49:57 +03:00
|
|
|
AssertValidation(t, context.Background(), c.AddHumanCommand(tt.args.human, tt.args.orgID, tt.args.hasher, tt.args.codeAlg, tt.args.allowInitMail), tt.args.filter, tt.want)
|
2022-04-12 16:20:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|