mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-15 20:41:30 +00:00
fix: ensure domain policy is read for the correct org (#4872)
This commit is contained in:
parent
e4531291f5
commit
33e973f015
@ -30,7 +30,7 @@ func (c *Commands) prepareAddOrgDomain(a *org.Aggregate, addDomain string, userI
|
|||||||
if existing != nil && existing.State == domain.OrgDomainStateActive {
|
if existing != nil && existing.State == domain.OrgDomainStateActive {
|
||||||
return nil, errors.ThrowAlreadyExists(nil, "V2-e1wse", "Errors.Already.Exists")
|
return nil, errors.ThrowAlreadyExists(nil, "V2-e1wse", "Errors.Already.Exists")
|
||||||
}
|
}
|
||||||
domainPolicy, err := domainPolicyWriteModel(ctx, filter)
|
domainPolicy, err := domainPolicyWriteModel(ctx, filter, a.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func prepareAddOrgDomainPolicy(
|
|||||||
) preparation.Validation {
|
) preparation.Validation {
|
||||||
return func() (preparation.CreateCommands, error) {
|
return func() (preparation.CreateCommands, error) {
|
||||||
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||||||
writeModel, err := orgDomainPolicy(ctx, filter)
|
writeModel, err := orgDomainPolicy(ctx, filter, a.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ func prepareChangeOrgDomainPolicy(
|
|||||||
) preparation.Validation {
|
) preparation.Validation {
|
||||||
return func() (preparation.CreateCommands, error) {
|
return func() (preparation.CreateCommands, error) {
|
||||||
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||||||
writeModel, err := orgDomainPolicy(ctx, filter)
|
writeModel, err := orgDomainPolicy(ctx, filter, a.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ func prepareRemoveOrgDomainPolicy(
|
|||||||
) preparation.Validation {
|
) preparation.Validation {
|
||||||
return func() (preparation.CreateCommands, error) {
|
return func() (preparation.CreateCommands, error) {
|
||||||
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||||||
writeModel, err := orgDomainPolicy(ctx, filter)
|
writeModel, err := orgDomainPolicy(ctx, filter, a.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ func (c *Commands) prepareUserDomainClaimed(ctx context.Context, filter preparat
|
|||||||
if !userWriteModel.UserState.Exists() {
|
if !userWriteModel.UserState.Exists() {
|
||||||
return nil, errors.ThrowNotFound(nil, "COMMAND-ii9K0", "Errors.User.NotFound")
|
return nil, errors.ThrowNotFound(nil, "COMMAND-ii9K0", "Errors.User.NotFound")
|
||||||
}
|
}
|
||||||
domainPolicy, err := domainPolicyWriteModel(ctx, filter)
|
domainPolicy, err := domainPolicyWriteModel(ctx, filter, userWriteModel.ResourceOwner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,12 @@ package command
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/api/authz"
|
|
||||||
"github.com/zitadel/zitadel/internal/command/preparation"
|
"github.com/zitadel/zitadel/internal/command/preparation"
|
||||||
"github.com/zitadel/zitadel/internal/errors"
|
"github.com/zitadel/zitadel/internal/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func domainPolicyWriteModel(ctx context.Context, filter preparation.FilterToQueryReducer) (*PolicyDomainWriteModel, error) {
|
func domainPolicyWriteModel(ctx context.Context, filter preparation.FilterToQueryReducer, orgID string) (*PolicyDomainWriteModel, error) {
|
||||||
wm, err := orgDomainPolicy(ctx, filter)
|
wm, err := orgDomainPolicy(ctx, filter, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -26,8 +25,8 @@ func domainPolicyWriteModel(ctx context.Context, filter preparation.FilterToQuer
|
|||||||
return nil, errors.ThrowInternal(nil, "USER-Ggk9n", "Errors.Internal")
|
return nil, errors.ThrowInternal(nil, "USER-Ggk9n", "Errors.Internal")
|
||||||
}
|
}
|
||||||
|
|
||||||
func orgDomainPolicy(ctx context.Context, filter preparation.FilterToQueryReducer) (*OrgDomainPolicyWriteModel, error) {
|
func orgDomainPolicy(ctx context.Context, filter preparation.FilterToQueryReducer, orgID string) (*OrgDomainPolicyWriteModel, error) {
|
||||||
policy := NewOrgDomainPolicyWriteModel(authz.GetCtxData(ctx).OrgID)
|
policy := NewOrgDomainPolicyWriteModel(orgID)
|
||||||
events, err := filter(ctx, policy.Query())
|
events, err := filter(ctx, policy.Query())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
func Test_customDomainPolicy(t *testing.T) {
|
func Test_customDomainPolicy(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
filter preparation.FilterToQueryReducer
|
filter preparation.FilterToQueryReducer
|
||||||
|
orgID string
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -30,6 +31,7 @@ func Test_customDomainPolicy(t *testing.T) {
|
|||||||
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
||||||
return nil, errors.ThrowInternal(nil, "USER-IgYlN", "Errors.Internal")
|
return nil, errors.ThrowInternal(nil, "USER-IgYlN", "Errors.Internal")
|
||||||
},
|
},
|
||||||
|
orgID: "id",
|
||||||
},
|
},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
@ -40,11 +42,15 @@ func Test_customDomainPolicy(t *testing.T) {
|
|||||||
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
||||||
return []eventstore.Event{}, nil
|
return []eventstore.Event{}, nil
|
||||||
},
|
},
|
||||||
|
orgID: "id",
|
||||||
},
|
},
|
||||||
want: &OrgDomainPolicyWriteModel{
|
want: &OrgDomainPolicyWriteModel{
|
||||||
PolicyDomainWriteModel: PolicyDomainWriteModel{
|
PolicyDomainWriteModel: PolicyDomainWriteModel{
|
||||||
WriteModel: eventstore.WriteModel{},
|
WriteModel: eventstore.WriteModel{
|
||||||
State: domain.PolicyStateUnspecified,
|
AggregateID: "id",
|
||||||
|
ResourceOwner: "id",
|
||||||
|
},
|
||||||
|
State: domain.PolicyStateUnspecified,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -63,6 +69,7 @@ func Test_customDomainPolicy(t *testing.T) {
|
|||||||
),
|
),
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
orgID: "id",
|
||||||
},
|
},
|
||||||
want: &OrgDomainPolicyWriteModel{
|
want: &OrgDomainPolicyWriteModel{
|
||||||
PolicyDomainWriteModel: PolicyDomainWriteModel{
|
PolicyDomainWriteModel: PolicyDomainWriteModel{
|
||||||
@ -82,7 +89,7 @@ func Test_customDomainPolicy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := orgDomainPolicy(context.Background(), tt.args.filter)
|
got, err := orgDomainPolicy(context.Background(), tt.args.filter, tt.args.orgID)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("customDomainPolicy() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("customDomainPolicy() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
@ -181,6 +188,7 @@ func Test_defaultDomainPolicy(t *testing.T) {
|
|||||||
func Test_DomainPolicy(t *testing.T) {
|
func Test_DomainPolicy(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
filter preparation.FilterToQueryReducer
|
filter preparation.FilterToQueryReducer
|
||||||
|
orgID string
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -194,6 +202,7 @@ func Test_DomainPolicy(t *testing.T) {
|
|||||||
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
||||||
return nil, errors.ThrowInternal(nil, "USER-IgYlN", "Errors.Internal")
|
return nil, errors.ThrowInternal(nil, "USER-IgYlN", "Errors.Internal")
|
||||||
},
|
},
|
||||||
|
orgID: "id",
|
||||||
},
|
},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
@ -212,6 +221,7 @@ func Test_DomainPolicy(t *testing.T) {
|
|||||||
),
|
),
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
orgID: "id",
|
||||||
},
|
},
|
||||||
want: &PolicyDomainWriteModel{
|
want: &PolicyDomainWriteModel{
|
||||||
WriteModel: eventstore.WriteModel{
|
WriteModel: eventstore.WriteModel{
|
||||||
@ -237,6 +247,7 @@ func Test_DomainPolicy(t *testing.T) {
|
|||||||
return nil, errors.ThrowInternal(nil, "USER-6HnsD", "Errors.Internal")
|
return nil, errors.ThrowInternal(nil, "USER-6HnsD", "Errors.Internal")
|
||||||
}).
|
}).
|
||||||
Filter(),
|
Filter(),
|
||||||
|
orgID: "id",
|
||||||
},
|
},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
@ -260,6 +271,7 @@ func Test_DomainPolicy(t *testing.T) {
|
|||||||
}, nil
|
}, nil
|
||||||
}).
|
}).
|
||||||
Filter(),
|
Filter(),
|
||||||
|
orgID: "id",
|
||||||
},
|
},
|
||||||
want: &PolicyDomainWriteModel{
|
want: &PolicyDomainWriteModel{
|
||||||
WriteModel: eventstore.WriteModel{
|
WriteModel: eventstore.WriteModel{
|
||||||
@ -288,7 +300,7 @@ func Test_DomainPolicy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := domainPolicyWriteModel(authz.WithInstanceID(context.Background(), "INSTANCE"), tt.args.filter)
|
got, err := domainPolicyWriteModel(authz.WithInstanceID(context.Background(), "INSTANCE"), tt.args.filter, tt.args.orgID)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("defaultDomainPolicy() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("defaultDomainPolicy() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
|
@ -130,7 +130,7 @@ func AddHumanCommand(a *user.Aggregate, human *AddHuman, passwordAlg crypto.Hash
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||||||
domainPolicy, err := domainPolicyWriteModel(ctx, filter)
|
domainPolicy, err := domainPolicyWriteModel(ctx, filter, a.ResourceOwner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func AddMachineCommand(a *user.Aggregate, machine *Machine) preparation.Validati
|
|||||||
if isUserStateExists(writeModel.UserState) {
|
if isUserStateExists(writeModel.UserState) {
|
||||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-k2una", "Errors.User.AlreadyExisting")
|
return nil, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-k2una", "Errors.User.AlreadyExisting")
|
||||||
}
|
}
|
||||||
domainPolicy, err := domainPolicyWriteModel(ctx, filter)
|
domainPolicy, err := domainPolicyWriteModel(ctx, filter, a.ResourceOwner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, caos_errs.ThrowPreconditionFailed(err, "COMMAND-3M9fs", "Errors.Org.DomainPolicy.NotFound")
|
return nil, caos_errs.ThrowPreconditionFailed(err, "COMMAND-3M9fs", "Errors.Org.DomainPolicy.NotFound")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user