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