mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 13:48:23 +00:00
fix: asset service (CORS and path in console) and user init (#3655)
* fix: asset service (CORS and path in console) and user init * fix tests * improve comment
This commit is contained in:
@@ -164,9 +164,9 @@ export class AppDetailComponent implements OnInit, OnDestroy {
|
|||||||
this.http.get('./assets/environment.json').subscribe((env: any) => {
|
this.http.get('./assets/environment.json').subscribe((env: any) => {
|
||||||
this.environmentMap = {
|
this.environmentMap = {
|
||||||
issuer: env.issuer,
|
issuer: env.issuer,
|
||||||
adminServiceUrl: env.adminServiceUrl,
|
adminServiceUrl: env.api,
|
||||||
mgmtServiceUrl: env.mgmtServiceUrl,
|
mgmtServiceUrl: env.api,
|
||||||
authServiceUrl: env.adminServiceUrl,
|
authServiceUrl: env.api,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -84,8 +84,8 @@ export class AssetService {
|
|||||||
.get('./assets/environment.json')
|
.get('./assets/environment.json')
|
||||||
.toPromise()
|
.toPromise()
|
||||||
.then((data: any) => {
|
.then((data: any) => {
|
||||||
if (data && data.assetServiceUrl) {
|
if (data && data.api) {
|
||||||
return data.assetServiceUrl;
|
return data.api;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@@ -83,7 +83,7 @@ func NewHandler(commands *command.Commands, verifier *authz.TokenVerifier, authC
|
|||||||
|
|
||||||
verifier.RegisterServer("Assets-API", "assets", AssetsService_AuthMethods)
|
verifier.RegisterServer("Assets-API", "assets", AssetsService_AuthMethods)
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.Use(sentryhttp.New(sentryhttp.Options{}).Handle, instanceInterceptor)
|
router.Use(sentryhttp.New(sentryhttp.Options{}).Handle, http_mw.CORSInterceptor, instanceInterceptor)
|
||||||
RegisterRoutes(router, h)
|
RegisterRoutes(router, h)
|
||||||
router.PathPrefix("/{owner}").Methods("GET").HandlerFunc(DownloadHandleFunc(h, h.GetFile()))
|
router.PathPrefix("/{owner}").Methods("GET").HandlerFunc(DownloadHandleFunc(h, h.GetFile()))
|
||||||
return router
|
return router
|
||||||
|
@@ -179,16 +179,16 @@ func AddHumanCommand(a *user.Aggregate, human *AddHuman, passwordAlg crypto.Hash
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cmds = append(cmds, user.NewHumanInitialCodeAddedEvent(ctx, &a.Aggregate, value, expiry))
|
cmds = append(cmds, user.NewHumanInitialCodeAddedEvent(ctx, &a.Aggregate, value, expiry))
|
||||||
}
|
|
||||||
|
|
||||||
if human.Email.Verified {
|
|
||||||
cmds = append(cmds, user.NewHumanEmailVerifiedEvent(ctx, &a.Aggregate))
|
|
||||||
} else {
|
} else {
|
||||||
value, expiry, err := newEmailCode(ctx, filter, codeAlg)
|
if human.Email.Verified {
|
||||||
if err != nil {
|
cmds = append(cmds, user.NewHumanEmailVerifiedEvent(ctx, &a.Aggregate))
|
||||||
return nil, err
|
} else {
|
||||||
|
value, expiry, err := newEmailCode(ctx, filter, codeAlg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cmds = append(cmds, user.NewHumanEmailCodeAddedEvent(ctx, &a.Aggregate, value, expiry))
|
||||||
}
|
}
|
||||||
cmds = append(cmds, user.NewHumanEmailCodeAddedEvent(ctx, &a.Aggregate, value, expiry))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if human.Phone.Verified {
|
if human.Phone.Verified {
|
||||||
@@ -249,13 +249,17 @@ func (h *AddHuman) ensureDisplayName() {
|
|||||||
h.DisplayName = h.FirstName + " " + h.LastName
|
h.DisplayName = h.FirstName + " " + h.LastName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//shouldAddInitCode returns true for all added Humans which:
|
||||||
|
// - were not added from an external IDP
|
||||||
|
// - and either:
|
||||||
|
// - have no verified email
|
||||||
|
// and / or
|
||||||
|
// - have no authentication method (password / passwordless)
|
||||||
func (h *AddHuman) shouldAddInitCode() bool {
|
func (h *AddHuman) shouldAddInitCode() bool {
|
||||||
//user without idp
|
return !h.ExternalIDP &&
|
||||||
return !h.Email.Verified ||
|
!h.Email.Verified ||
|
||||||
//user with idp
|
!h.Passwordless &&
|
||||||
!h.ExternalIDP &&
|
h.Password == ""
|
||||||
!h.Passwordless &&
|
|
||||||
h.Password != ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commands) ImportHuman(ctx context.Context, orgID string, human *domain.Human, passwordless bool, initCodeGenerator crypto.Generator, phoneCodeGenerator crypto.Generator, passwordlessCodeGenerator crypto.Generator) (_ *domain.Human, passwordlessCode *domain.PasswordlessInitCode, err error) {
|
func (c *Commands) ImportHuman(ctx context.Context, orgID string, human *domain.Human, passwordless bool, initCodeGenerator crypto.Generator, phoneCodeGenerator crypto.Generator, passwordlessCodeGenerator crypto.Generator) (_ *domain.Human, passwordlessCode *domain.PasswordlessInitCode, err error) {
|
||||||
|
@@ -189,21 +189,6 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
expectFilter(
|
|
||||||
eventFromEventPusher(
|
|
||||||
instance.NewSecretGeneratorAddedEvent(
|
|
||||||
context.Background(),
|
|
||||||
&instanceAgg.Aggregate,
|
|
||||||
domain.SecretGeneratorTypeVerifyEmailCode,
|
|
||||||
0,
|
|
||||||
1*time.Hour,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
expectPush(
|
expectPush(
|
||||||
[]*repository.Event{
|
[]*repository.Event{
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
@@ -232,18 +217,6 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
time.Hour*1,
|
time.Hour*1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
eventFromEventPusher(
|
|
||||||
user.NewHumanEmailCodeAddedEvent(context.Background(),
|
|
||||||
&userAgg.Aggregate,
|
|
||||||
&crypto.CryptoValue{
|
|
||||||
CryptoType: crypto.TypeEncryption,
|
|
||||||
Algorithm: "enc",
|
|
||||||
KeyID: "id",
|
|
||||||
Crypted: []byte(""),
|
|
||||||
},
|
|
||||||
time.Hour*1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("username", "org1", true)),
|
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("username", "org1", true)),
|
||||||
),
|
),
|
||||||
@@ -303,20 +276,6 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
expectFilter(
|
|
||||||
eventFromEventPusher(
|
|
||||||
user.NewHumanInitialCodeAddedEvent(context.Background(),
|
|
||||||
&userAgg.Aggregate,
|
|
||||||
&crypto.CryptoValue{
|
|
||||||
CryptoType: crypto.TypeEncryption,
|
|
||||||
Algorithm: "enc",
|
|
||||||
KeyID: "id",
|
|
||||||
Crypted: []byte(""),
|
|
||||||
},
|
|
||||||
time.Hour*1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
expectFilter(
|
expectFilter(
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
instance.NewSecretGeneratorAddedEvent(
|
instance.NewSecretGeneratorAddedEvent(
|
||||||
@@ -346,20 +305,7 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
KeyID: "id",
|
KeyID: "id",
|
||||||
Crypted: []byte(""),
|
Crypted: []byte(""),
|
||||||
},
|
},
|
||||||
0,
|
1*time.Hour,
|
||||||
),
|
|
||||||
),
|
|
||||||
eventFromEventPusher(
|
|
||||||
user.NewHumanEmailCodeAddedEvent(
|
|
||||||
context.Background(),
|
|
||||||
&userAgg.Aggregate,
|
|
||||||
&crypto.CryptoValue{
|
|
||||||
CryptoType: crypto.TypeEncryption,
|
|
||||||
Algorithm: "enc",
|
|
||||||
KeyID: "id",
|
|
||||||
Crypted: []byte(""),
|
|
||||||
},
|
|
||||||
0,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -421,39 +367,11 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
expectFilter(
|
|
||||||
eventFromEventPusher(
|
|
||||||
instance.NewSecretGeneratorAddedEvent(
|
|
||||||
context.Background(),
|
|
||||||
&instanceAgg.Aggregate,
|
|
||||||
domain.SecretGeneratorTypeInitCode,
|
|
||||||
0,
|
|
||||||
1*time.Hour,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
expectPush(
|
expectPush(
|
||||||
[]*repository.Event{
|
[]*repository.Event{
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
newAddHumanEvent("password", true, ""),
|
newAddHumanEvent("password", true, ""),
|
||||||
),
|
),
|
||||||
eventFromEventPusher(
|
|
||||||
user.NewHumanInitialCodeAddedEvent(
|
|
||||||
context.Background(),
|
|
||||||
&userAgg.Aggregate,
|
|
||||||
&crypto.CryptoValue{
|
|
||||||
CryptoType: crypto.TypeEncryption,
|
|
||||||
Algorithm: "enc",
|
|
||||||
KeyID: "id",
|
|
||||||
Crypted: []byte(""),
|
|
||||||
},
|
|
||||||
1*time.Hour,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
user.NewHumanEmailVerifiedEvent(context.Background(),
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
||||||
&userAgg.Aggregate),
|
&userAgg.Aggregate),
|
||||||
@@ -507,6 +425,18 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
expectFilter(
|
||||||
|
eventFromEventPusher(
|
||||||
|
org.NewPasswordComplexityPolicyAddedEvent(context.Background(),
|
||||||
|
&userAgg.Aggregate,
|
||||||
|
1,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
expectFilter(
|
expectFilter(
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
instance.NewSecretGeneratorAddedEvent(
|
instance.NewSecretGeneratorAddedEvent(
|
||||||
@@ -525,7 +455,7 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
expectPush(
|
expectPush(
|
||||||
[]*repository.Event{
|
[]*repository.Event{
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
newAddHumanEvent("", false, "+41711234567"),
|
newAddHumanEvent("password", false, "+41711234567"),
|
||||||
),
|
),
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
user.NewHumanEmailVerifiedEvent(
|
user.NewHumanEmailVerifiedEvent(
|
||||||
@@ -547,8 +477,9 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("username", "org1", true)),
|
uniqueConstraintsFromEventConstraint(user.NewAddUsernameUniqueConstraint("username", "org1", true)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "user1"),
|
||||||
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
userPasswordAlg: crypto.CreateMockHashAlg(gomock.NewController(t)),
|
||||||
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||||
},
|
},
|
||||||
args: args{
|
args: args{
|
||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
@@ -557,6 +488,7 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
Username: "username",
|
Username: "username",
|
||||||
FirstName: "firstname",
|
FirstName: "firstname",
|
||||||
LastName: "lastname",
|
LastName: "lastname",
|
||||||
|
Password: "password",
|
||||||
Email: Email{
|
Email: Email{
|
||||||
Address: "email@test.ch",
|
Address: "email@test.ch",
|
||||||
Verified: true,
|
Verified: true,
|
||||||
@@ -607,21 +539,6 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
expectFilter(
|
|
||||||
eventFromEventPusher(
|
|
||||||
instance.NewSecretGeneratorAddedEvent(
|
|
||||||
context.Background(),
|
|
||||||
&instanceAgg.Aggregate,
|
|
||||||
domain.SecretGeneratorTypeVerifyEmailCode,
|
|
||||||
0,
|
|
||||||
1*time.Hour,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
expectPush(
|
expectPush(
|
||||||
[]*repository.Event{
|
[]*repository.Event{
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
@@ -640,19 +557,6 @@ func TestCommandSide_AddHuman(t *testing.T) {
|
|||||||
1*time.Hour,
|
1*time.Hour,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
eventFromEventPusher(
|
|
||||||
user.NewHumanEmailCodeAddedEvent(
|
|
||||||
context.Background(),
|
|
||||||
&userAgg.Aggregate,
|
|
||||||
&crypto.CryptoValue{
|
|
||||||
CryptoType: crypto.TypeEncryption,
|
|
||||||
Algorithm: "enc",
|
|
||||||
KeyID: "id",
|
|
||||||
Crypted: []byte(""),
|
|
||||||
},
|
|
||||||
1*time.Hour,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
eventFromEventPusher(
|
eventFromEventPusher(
|
||||||
user.NewHumanPhoneVerifiedEvent(
|
user.NewHumanPhoneVerifiedEvent(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
@@ -2980,10 +2884,11 @@ func TestAddHumanCommand(t *testing.T) {
|
|||||||
PreferredLanguage: language.English,
|
PreferredLanguage: language.English,
|
||||||
FirstName: "gigi",
|
FirstName: "gigi",
|
||||||
LastName: "giraffe",
|
LastName: "giraffe",
|
||||||
Password: "",
|
Password: "password",
|
||||||
Username: "username",
|
Username: "username",
|
||||||
},
|
},
|
||||||
passwordAlg: crypto.CreateMockHashAlg(gomock.NewController(t)),
|
passwordAlg: crypto.CreateMockHashAlg(gomock.NewController(t)),
|
||||||
|
codeAlg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||||
filter: NewMultiFilter().Append(
|
filter: NewMultiFilter().Append(
|
||||||
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
||||||
return []eventstore.Event{
|
return []eventstore.Event{
|
||||||
@@ -3014,19 +2919,28 @@ func TestAddHumanCommand(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: Want{
|
want: Want{
|
||||||
Commands: []eventstore.Command{
|
Commands: []eventstore.Command{
|
||||||
user.NewHumanAddedEvent(
|
func() *user.HumanAddedEvent {
|
||||||
context.Background(),
|
event := user.NewHumanAddedEvent(
|
||||||
&agg.Aggregate,
|
context.Background(),
|
||||||
"username",
|
&agg.Aggregate,
|
||||||
"gigi",
|
"username",
|
||||||
"giraffe",
|
"gigi",
|
||||||
"",
|
"giraffe",
|
||||||
"gigi giraffe",
|
"",
|
||||||
language.English,
|
"gigi giraffe",
|
||||||
0,
|
language.English,
|
||||||
"support@zitadel.ch",
|
0,
|
||||||
true,
|
"support@zitadel.ch",
|
||||||
),
|
true,
|
||||||
|
)
|
||||||
|
event.AddPasswordData(&crypto.CryptoValue{
|
||||||
|
CryptoType: crypto.TypeHash,
|
||||||
|
Algorithm: "hash",
|
||||||
|
KeyID: "",
|
||||||
|
Crypted: []byte("password"),
|
||||||
|
}, false)
|
||||||
|
return event
|
||||||
|
}(),
|
||||||
user.NewHumanEmailVerifiedEvent(context.Background(), &agg.Aggregate),
|
user.NewHumanEmailVerifiedEvent(context.Background(), &agg.Aggregate),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user