mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
c5b99274d7
* commander * commander * selber! * move to packages * fix(errors): implement Is interface * test: command * test: commands * add init steps * setup tenant * add default step yaml * possibility to set password * merge v2 into v2-commander * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: rename iam command side to instance * fix: search query builder can filter events in memory * fix: filters for add member * fix(setup): add `ExternalSecure` to config * chore: name iam to instance * fix: matching * remove unsued func * base url * base url * test(command): filter funcs * test: commands * fix: rename orgiampolicy to domain policy * start from init * commands * config * fix indexes and add constraints * fixes * fix: merge conflicts * fix: protos * fix: md files * setup * add deprecated org iam policy again * typo * fix search query * fix filter * Apply suggestions from code review * remove custom org from org setup * add todos for verification * change apps creation * simplify package structure * fix error * move preparation helper for tests * fix unique constraints * fix config mapping in setup * fix error handling in encryption_keys.go * fix projection config * fix query from old views to projection * fix setup of mgmt api * set iam project and fix instance projection * imports Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
196 lines
5.0 KiB
Go
196 lines
5.0 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/caos/zitadel/internal/command/v2/preparation"
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"github.com/caos/zitadel/internal/repository/project"
|
|
)
|
|
|
|
func TestAddProject(t *testing.T) {
|
|
type args struct {
|
|
a *project.Aggregate
|
|
name string
|
|
owner string
|
|
privateLabelingSetting domain.PrivateLabelingSetting
|
|
}
|
|
|
|
ctx := context.Background()
|
|
agg := project.NewAggregate("test", "test")
|
|
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want Want
|
|
}{
|
|
{
|
|
name: "invalid name",
|
|
args: args{
|
|
a: agg,
|
|
name: "",
|
|
owner: "owner",
|
|
privateLabelingSetting: domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
|
|
},
|
|
want: Want{
|
|
ValidationErr: errors.ThrowInvalidArgument(nil, "PROJE-C01yo", "Errors.Invalid.Argument"),
|
|
},
|
|
},
|
|
{
|
|
name: "invalid private labeling setting",
|
|
args: args{
|
|
a: agg,
|
|
name: "name",
|
|
owner: "owner",
|
|
privateLabelingSetting: -1,
|
|
},
|
|
want: Want{
|
|
ValidationErr: errors.ThrowInvalidArgument(nil, "PROJE-AO52V", "Errors.Invalid.Argument"),
|
|
},
|
|
},
|
|
{
|
|
name: "invalid owner",
|
|
args: args{
|
|
a: agg,
|
|
name: "name",
|
|
owner: "",
|
|
privateLabelingSetting: domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
|
|
},
|
|
want: Want{
|
|
ValidationErr: errors.ThrowPreconditionFailed(nil, "PROJE-hzxwo", "Errors.Invalid.Argument"),
|
|
},
|
|
},
|
|
{
|
|
name: "correct",
|
|
args: args{
|
|
a: agg,
|
|
name: "ZITADEL",
|
|
owner: "CAOS AG",
|
|
privateLabelingSetting: domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
|
|
},
|
|
want: Want{
|
|
Commands: []eventstore.Command{
|
|
project.NewProjectAddedEvent(ctx, &agg.Aggregate,
|
|
"ZITADEL",
|
|
false,
|
|
false,
|
|
false,
|
|
domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
|
|
),
|
|
project.NewProjectMemberAddedEvent(ctx, &agg.Aggregate,
|
|
"CAOS AG",
|
|
domain.RoleProjectOwner),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
AssertValidation(t, AddProject(tt.args.a, tt.args.name, tt.args.owner, false, false, false, tt.args.privateLabelingSetting), nil, tt.want)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestExistsProject(t *testing.T) {
|
|
type args struct {
|
|
filter preparation.FilterToQueryReducer
|
|
id string
|
|
resourceOwner string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantExists bool
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "no events",
|
|
args: args{
|
|
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
return []eventstore.Event{}, nil
|
|
},
|
|
id: "id",
|
|
resourceOwner: "ro",
|
|
},
|
|
wantExists: false,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "project added",
|
|
args: args{
|
|
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
return []eventstore.Event{
|
|
project.NewProjectAddedEvent(
|
|
context.Background(),
|
|
&project.NewAggregate("id", "ro").Aggregate,
|
|
"name",
|
|
false,
|
|
false,
|
|
false,
|
|
domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy,
|
|
),
|
|
}, nil
|
|
},
|
|
id: "id",
|
|
resourceOwner: "ro",
|
|
},
|
|
wantExists: true,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "project removed",
|
|
args: args{
|
|
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
return []eventstore.Event{
|
|
project.NewProjectAddedEvent(
|
|
context.Background(),
|
|
&project.NewAggregate("id", "ro").Aggregate,
|
|
"name",
|
|
false,
|
|
false,
|
|
false,
|
|
domain.PrivateLabelingSettingEnforceProjectResourceOwnerPolicy,
|
|
),
|
|
project.NewProjectRemovedEvent(
|
|
context.Background(),
|
|
&project.NewAggregate("id", "ro").Aggregate,
|
|
"name",
|
|
),
|
|
}, nil
|
|
},
|
|
id: "id",
|
|
resourceOwner: "ro",
|
|
},
|
|
wantExists: false,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "error durring filter",
|
|
args: args{
|
|
filter: func(_ context.Context, _ *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
return nil, errors.ThrowInternal(nil, "PROJE-Op26p", "Errors.Internal")
|
|
},
|
|
id: "id",
|
|
resourceOwner: "ro",
|
|
},
|
|
wantExists: false,
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotExists, err := ExistsProject(context.Background(), tt.args.filter, tt.args.id, tt.args.resourceOwner)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ExistsUser() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if gotExists != tt.wantExists {
|
|
t.Errorf("ExistsUser() = %v, want %v", gotExists, tt.wantExists)
|
|
}
|
|
})
|
|
}
|
|
}
|