2021-03-19 11:12:56 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-11-22 12:56:43 +02:00
|
|
|
"go.uber.org/mock/gomock"
|
2021-03-19 11:12:56 +01:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/http"
|
|
|
|
"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"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/user"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2021-03-19 11:12:56 +01:00
|
|
|
)
|
|
|
|
|
2022-04-12 16:20:17 +02:00
|
|
|
func TestAddDomain(t *testing.T) {
|
|
|
|
type args struct {
|
2022-07-28 13:18:31 +02:00
|
|
|
a *org.Aggregate
|
|
|
|
domain string
|
|
|
|
claimedUserIDs []string
|
|
|
|
idGenerator id.Generator
|
|
|
|
filter preparation.FilterToQueryReducer
|
2022-04-12 16:20:17 +02:00
|
|
|
}
|
|
|
|
|
2022-04-20 16:59:37 +02:00
|
|
|
agg := org.NewAggregate("test")
|
2022-04-12 16:20:17 +02:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want Want
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain",
|
|
|
|
args: args{
|
|
|
|
a: agg,
|
|
|
|
domain: "",
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-12-08 16:30:55 +02:00
|
|
|
ValidationErr: zerrors.ThrowInvalidArgument(nil, "ORG-r3h4J", "Errors.Invalid.Argument"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-04-13 11:24:03 +02:00
|
|
|
name: "correct (should verify domain)",
|
2022-04-12 16:20:17 +02:00
|
|
|
args: args{
|
2022-07-28 13:18:31 +02:00
|
|
|
a: agg,
|
|
|
|
domain: "domain",
|
|
|
|
claimedUserIDs: []string{"userID1"},
|
2022-04-12 16:20:17 +02:00
|
|
|
filter: func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
2022-04-13 11:24:03 +02:00
|
|
|
return []eventstore.Event{
|
2022-05-16 16:08:47 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(ctx, &agg.Aggregate, true, true, true),
|
2022-04-13 11:24:03 +02:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: Want{
|
|
|
|
Commands: []eventstore.Command{
|
|
|
|
org.NewDomainAddedEvent(context.Background(), &agg.Aggregate, "domain"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "correct (should not verify domain)",
|
|
|
|
args: args{
|
2022-07-28 13:18:31 +02:00
|
|
|
a: agg,
|
|
|
|
domain: "domain",
|
|
|
|
claimedUserIDs: []string{"userID1"},
|
|
|
|
idGenerator: id_mock.ExpectID(t, "newID"),
|
|
|
|
filter: func() func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
i := 0 //TODO: we should fix this in the future to use some kind of mock struct and expect filter calls
|
|
|
|
return func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
if i == 2 {
|
|
|
|
i++
|
|
|
|
return []eventstore.Event{user.NewHumanAddedEvent(
|
|
|
|
ctx,
|
|
|
|
&user.NewAggregate("userID1", "org2").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.Und,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email",
|
|
|
|
false,
|
|
|
|
)}, nil
|
|
|
|
}
|
|
|
|
if i == 3 {
|
|
|
|
i++
|
|
|
|
return []eventstore.Event{org.NewDomainPolicyAddedEvent(ctx, &agg.Aggregate, false, false, false)}, nil
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
return []eventstore.Event{org.NewDomainPolicyAddedEvent(ctx, &agg.Aggregate, true, false, false)}, nil
|
|
|
|
}
|
|
|
|
}(),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
want: Want{
|
|
|
|
Commands: []eventstore.Command{
|
|
|
|
org.NewDomainAddedEvent(context.Background(), &agg.Aggregate, "domain"),
|
2022-04-13 11:24:03 +02:00
|
|
|
org.NewDomainVerifiedEvent(context.Background(), &agg.Aggregate, "domain"),
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
user.NewDomainClaimedEvent(http.WithRequestedHost(context.Background(), "domain"), &user.NewAggregate("userID1", "org2").Aggregate, "newID@temporary.domain", "username", false),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "already verified",
|
|
|
|
args: args{
|
2022-07-28 13:18:31 +02:00
|
|
|
a: agg,
|
|
|
|
domain: "domain",
|
|
|
|
claimedUserIDs: []string{"userID1"},
|
2022-04-12 16:20:17 +02:00
|
|
|
filter: func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewDomainAddedEvent(ctx, &agg.Aggregate, "domain"),
|
|
|
|
org.NewDomainVerificationAddedEvent(ctx, &agg.Aggregate, "domain", domain.OrgDomainValidationTypeHTTP, nil),
|
|
|
|
org.NewDomainVerifiedEvent(ctx, &agg.Aggregate, "domain"),
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-12-08 16:30:55 +02:00
|
|
|
CreateErr: zerrors.ThrowAlreadyExists(nil, "", ""),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-07-28 13:18:31 +02:00
|
|
|
AssertValidation(
|
|
|
|
t,
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
http.WithRequestedHost(context.Background(), "domain"),
|
2022-07-28 13:18:31 +02:00
|
|
|
(&Commands{idGenerator: tt.args.idGenerator}).prepareAddOrgDomain(tt.args.a, tt.args.domain, tt.args.claimedUserIDs),
|
|
|
|
tt.args.filter,
|
|
|
|
tt.want,
|
|
|
|
)
|
2022-04-12 16:20:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVerifyDomain(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
a *org.Aggregate
|
|
|
|
domain string
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want Want
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain",
|
|
|
|
args: args{
|
2022-04-20 16:59:37 +02:00
|
|
|
a: org.NewAggregate("test"),
|
2022-04-12 16:20:17 +02:00
|
|
|
domain: "",
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-12-08 16:30:55 +02:00
|
|
|
ValidationErr: zerrors.ThrowInvalidArgument(nil, "ORG-yqlVQ", "Errors.Invalid.Argument"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "correct",
|
|
|
|
args: args{
|
2022-04-20 16:59:37 +02:00
|
|
|
a: org.NewAggregate("test"),
|
2022-04-12 16:20:17 +02:00
|
|
|
domain: "domain",
|
|
|
|
},
|
|
|
|
want: Want{
|
|
|
|
Commands: []eventstore.Command{
|
2022-04-20 16:59:37 +02:00
|
|
|
org.NewDomainVerifiedEvent(context.Background(), &org.NewAggregate("test").Aggregate, "domain"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-07-28 15:42:35 +02:00
|
|
|
AssertValidation(t, context.Background(), verifyOrgDomain(tt.args.a, tt.args.domain), nil, tt.want)
|
2022-04-12 16:20:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetDomainPrimary(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
a *org.Aggregate
|
|
|
|
domain string
|
|
|
|
filter preparation.FilterToQueryReducer
|
|
|
|
}
|
|
|
|
|
2022-04-20 16:59:37 +02:00
|
|
|
agg := org.NewAggregate("test")
|
2022-04-12 16:20:17 +02:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want Want
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain",
|
|
|
|
args: args{
|
|
|
|
a: agg,
|
|
|
|
domain: "",
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-12-08 16:30:55 +02:00
|
|
|
ValidationErr: zerrors.ThrowInvalidArgument(nil, "ORG-gmNqY", "Errors.Invalid.Argument"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not exists",
|
|
|
|
args: args{
|
|
|
|
a: agg,
|
|
|
|
domain: "domain",
|
|
|
|
filter: func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return nil, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-12-08 16:30:55 +02:00
|
|
|
CreateErr: zerrors.ThrowNotFound(nil, "", ""),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not verified",
|
|
|
|
args: args{
|
|
|
|
a: agg,
|
|
|
|
domain: "domain",
|
|
|
|
filter: func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{org.NewDomainAddedEvent(ctx, &agg.Aggregate, "domain")}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-12-08 16:30:55 +02:00
|
|
|
CreateErr: zerrors.ThrowPreconditionFailed(nil, "", ""),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "already primary",
|
|
|
|
args: args{
|
|
|
|
a: agg,
|
|
|
|
domain: "domain",
|
|
|
|
filter: func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewDomainAddedEvent(ctx, &agg.Aggregate, "domain"),
|
|
|
|
org.NewDomainVerificationAddedEvent(ctx, &agg.Aggregate, "domain", domain.OrgDomainValidationTypeHTTP, nil),
|
|
|
|
org.NewDomainVerifiedEvent(ctx, &agg.Aggregate, "domain"),
|
|
|
|
org.NewDomainPrimarySetEvent(ctx, &agg.Aggregate, "domain"),
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-12-08 16:30:55 +02:00
|
|
|
CreateErr: zerrors.ThrowPreconditionFailed(nil, "", ""),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "correct",
|
|
|
|
args: args{
|
|
|
|
a: agg,
|
|
|
|
domain: "domain",
|
|
|
|
filter: func(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
|
|
return []eventstore.Event{
|
|
|
|
org.NewDomainAddedEvent(ctx, &agg.Aggregate, "domain"),
|
|
|
|
org.NewDomainVerificationAddedEvent(ctx, &agg.Aggregate, "domain", domain.OrgDomainValidationTypeHTTP, nil),
|
|
|
|
org.NewDomainVerifiedEvent(ctx, &agg.Aggregate, "domain"),
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: Want{
|
|
|
|
Commands: []eventstore.Command{
|
|
|
|
org.NewDomainPrimarySetEvent(context.Background(), &agg.Aggregate, "domain"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-07-28 15:42:35 +02:00
|
|
|
AssertValidation(t, context.Background(), setPrimaryOrgDomain(tt.args.a, tt.args.domain), tt.args.filter, tt.want)
|
2022-04-12 16:20:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 11:12:56 +01:00
|
|
|
func TestCommandSide_AddOrgDomain(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
2021-05-04 11:09:24 +02:00
|
|
|
ctx context.Context
|
2022-07-28 13:18:31 +02:00
|
|
|
orgID string
|
|
|
|
domain string
|
2021-05-04 11:09:24 +02:00
|
|
|
claimedUserIDs []string
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
type res struct {
|
2022-07-28 13:18:31 +02:00
|
|
|
want *domain.ObjectDetails
|
2021-03-19 11:12:56 +01:00
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-07-28 13:18:31 +02:00
|
|
|
ctx: context.Background(),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain already exists, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-07-28 13:18:31 +02:00
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
domain: "domain.ch",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorAlreadyExists,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain add, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-07-28 13:18:31 +02:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch",
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-07-28 13:18:31 +02:00
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
domain: "domain.ch",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
res: res{
|
2022-07-28 13:18:31 +02:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
2022-07-28 13:18:31 +02:00
|
|
|
got, err := r.AddOrgDomain(tt.args.ctx, tt.args.orgID, tt.args.domain, tt.args.claimedUserIDs)
|
2021-03-19 11:12:56 +01:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
2024-08-12 22:32:01 +02:00
|
|
|
assertObjectDetails(t, tt.res.want, got)
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_GenerateOrgDomainValidation(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
secretGenerator crypto.Generator
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
domain *domain.OrgDomain
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
wantToken string
|
|
|
|
wantURL string
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing aggregateid, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid validation type, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain not exists, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsNotFound,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain already verified, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add dns validation, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainVerificationAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch",
|
|
|
|
domain.OrgDomainValidationTypeDNS,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
wantToken: "a",
|
|
|
|
wantURL: "_zitadel-challenge.domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add http validation, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainVerificationAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch",
|
|
|
|
domain.OrgDomainValidationTypeHTTP,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
secretGenerator: GetMockSecretGenerator(t),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeHTTP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
wantToken: "a",
|
2023-07-07 13:50:45 +02:00
|
|
|
wantURL: "https://domain.ch/.well-known/zitadel-challenge/a.txt",
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
domainVerificationGenerator: tt.fields.secretGenerator,
|
|
|
|
}
|
|
|
|
token, url, err := r.GenerateOrgDomainValidation(tt.args.ctx, tt.args.domain)
|
|
|
|
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.wantToken, token)
|
|
|
|
assert.Equal(t, tt.res.wantURL, url)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_ValidateOrgDomain(t *testing.T) {
|
|
|
|
type fields struct {
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore func(*testing.T) *eventstore.Eventstore
|
2021-03-19 11:12:56 +01:00
|
|
|
idGenerator id.Generator
|
|
|
|
secretGenerator crypto.Generator
|
|
|
|
alg crypto.EncryptionAlgorithm
|
|
|
|
domainValidationFunc func(domain, token, verifier string, checkType http.CheckType) error
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
domain *domain.OrgDomain
|
|
|
|
claimedUserIDs []string
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain, error",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing aggregateid, error",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(),
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain not exists, precondition error",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsNotFound,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain already verified, precondition error",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no code existing, precondition error",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid domain verification, precondition error",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerificationAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
domain.OrgDomainValidationTypeDNS,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainVerificationFailedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch",
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
domainValidationFunc: invalidDomainVerification,
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain verification, ok",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerificationAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
domain.OrgDomainValidationTypeDNS,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch",
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
domainValidationFunc: validDomainVerification,
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain verification, claimed users not found, ok",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerificationAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
domain.OrgDomainValidationTypeDNS,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch",
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
domainValidationFunc: validDomainVerification,
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
claimedUserIDs: []string{"user1"},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain verification, claimed users, ok",
|
|
|
|
fields: fields{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: expectEventstore(
|
2021-03-19 11:12:56 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerificationAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
domain.OrgDomainValidationTypeDNS,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("a"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org2").Aggregate,
|
|
|
|
"username@domain.ch",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"nickname",
|
|
|
|
"displayname",
|
|
|
|
language.German,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-28 10:05:09 +02:00
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org2").Aggregate,
|
2022-05-16 16:08:47 +02:00
|
|
|
false, false, false))),
|
2021-03-19 11:12:56 +01:00
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch",
|
|
|
|
),
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
user.NewDomainClaimedEvent(http.WithRequestedHost(context.Background(), "zitadel.ch"),
|
2023-10-19 12:19:10 +02:00
|
|
|
&user.NewAggregate("user1", "org2").Aggregate,
|
|
|
|
"tempid@temporary.zitadel.ch",
|
|
|
|
"username@domain.ch",
|
|
|
|
false,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
domainValidationFunc: validDomainVerification,
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "tempid"),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
claimedUserIDs: []string{"user1"},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
eventstore: tt.fields.eventstore(t),
|
2021-03-19 11:12:56 +01:00
|
|
|
domainVerificationGenerator: tt.fields.secretGenerator,
|
|
|
|
domainVerificationAlg: tt.fields.alg,
|
|
|
|
domainVerificationValidator: tt.fields.domainValidationFunc,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
}
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 17:00:38 +02:00
|
|
|
got, err := r.ValidateOrgDomain(http.WithRequestedHost(tt.args.ctx, "zitadel.ch"), tt.args.domain, tt.args.claimedUserIDs)
|
2021-03-19 11:12:56 +01:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
2024-08-12 22:32:01 +02:00
|
|
|
assertObjectDetails(t, tt.res.want, got)
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_SetPrimaryDomain(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
domain *domain.OrgDomain
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing aggregateid, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain not exists, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsNotFound,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain not verified, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set primary, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch",
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
got, err := r.SetPrimaryOrgDomain(tt.args.ctx, tt.args.domain)
|
|
|
|
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 {
|
2024-08-12 22:32:01 +02:00
|
|
|
assertObjectDetails(t, tt.res.want, got)
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_RemoveOrgDomain(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
domain *domain.OrgDomain
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "missing aggregateid, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "domain not exists, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
ValidationType: domain.OrgDomainValidationTypeDNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsNotFound,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "remove verified domain, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPrimarySetEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2021-03-19 11:12:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "remove domain, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainRemovedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch", false,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "org1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "remove verified domain, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"name",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-19 11:12:56 +01:00
|
|
|
"domain.ch",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewDomainRemovedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"domain.ch", true,
|
|
|
|
),
|
2021-03-19 11:12:56 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
domain: &domain.OrgDomain{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org1",
|
|
|
|
},
|
|
|
|
Domain: "domain.ch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
got, err := r.RemoveOrgDomain(tt.args.ctx, tt.args.domain)
|
|
|
|
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 {
|
2024-08-12 22:32:01 +02:00
|
|
|
assertObjectDetails(t, tt.res.want, got)
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func invalidDomainVerification(domain, token, verifier string, checkType http.CheckType) error {
|
2023-12-08 16:30:55 +02:00
|
|
|
return zerrors.ThrowInvalidArgument(nil, "HTTP-GH422", "Errors.Internal")
|
2021-03-19 11:12:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func validDomainVerification(domain, token, verifier string, checkType http.CheckType) error {
|
|
|
|
return nil
|
|
|
|
}
|