mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:17:32 +00:00
fix: v2 human command (#3435)
* add/register human command done * validations * crypto * move clientid * keys * fix: clientID * remove v2 package * tests * tests running * revert old code * instance domain from ctx * chore: rename zitadel app ids * comments * fix: test
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
@@ -20,6 +20,53 @@ import (
|
||||
"github.com/caos/zitadel/internal/repository/user"
|
||||
)
|
||||
|
||||
func TestAddOrg(t *testing.T) {
|
||||
type args struct {
|
||||
a *org.Aggregate
|
||||
name string
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
agg := org.NewAggregate("test", "test")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want Want
|
||||
}{
|
||||
{
|
||||
name: "invalid domain",
|
||||
args: args{
|
||||
a: agg,
|
||||
name: "",
|
||||
},
|
||||
want: Want{
|
||||
ValidationErr: errors.ThrowInvalidArgument(nil, "ORG-mruNY", "Errors.Invalid.Argument"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "correct",
|
||||
args: args{
|
||||
a: agg,
|
||||
name: "caos ag",
|
||||
},
|
||||
want: Want{
|
||||
Commands: []eventstore.Command{
|
||||
org.NewOrgAddedEvent(ctx, &agg.Aggregate, "caos ag"),
|
||||
org.NewDomainAddedEvent(ctx, &agg.Aggregate, "caos-ag.localhost"),
|
||||
org.NewDomainVerifiedEvent(ctx, &agg.Aggregate, "caos-ag.localhost"),
|
||||
org.NewDomainPrimarySetEvent(ctx, &agg.Aggregate, "caos-ag.localhost"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
AssertValidation(t, AddOrgCommand(authz.WithRequestedDomain(context.Background(), "localhost"), tt.args.a, tt.args.name), nil, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandSide_AddOrg(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore *eventstore.Eventstore
|
||||
@@ -57,7 +104,7 @@ func TestCommandSide_AddOrg(t *testing.T) {
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
err: errors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -101,7 +148,7 @@ func TestCommandSide_AddOrg(t *testing.T) {
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsPreconditionFailed,
|
||||
err: errors.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -127,7 +174,7 @@ func TestCommandSide_AddOrg(t *testing.T) {
|
||||
),
|
||||
),
|
||||
expectFilterOrgMemberNotFound(),
|
||||
expectPushFailed(caos_errs.ThrowAlreadyExists(nil, "id", "internal"),
|
||||
expectPushFailed(errors.ThrowAlreadyExists(nil, "id", "internal"),
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(org.NewOrgAddedEvent(
|
||||
context.Background(),
|
||||
@@ -170,7 +217,7 @@ func TestCommandSide_AddOrg(t *testing.T) {
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorAlreadyExists,
|
||||
err: errors.IsErrorAlreadyExists,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -196,7 +243,7 @@ func TestCommandSide_AddOrg(t *testing.T) {
|
||||
),
|
||||
),
|
||||
expectFilterOrgMemberNotFound(),
|
||||
expectPushFailed(caos_errs.ThrowInternal(nil, "id", "internal"),
|
||||
expectPushFailed(errors.ThrowInternal(nil, "id", "internal"),
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(org.NewOrgAddedEvent(
|
||||
context.Background(),
|
||||
@@ -239,7 +286,7 @@ func TestCommandSide_AddOrg(t *testing.T) {
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
err: errors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -374,7 +421,7 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
err: errors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -391,7 +438,7 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
|
||||
name: "org",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
err: errors.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -409,7 +456,7 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
|
||||
),
|
||||
expectFilter(),
|
||||
expectPushFailed(
|
||||
caos_errs.ThrowInternal(nil, "id", "message"),
|
||||
errors.ThrowInternal(nil, "id", "message"),
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(org.NewOrgChangedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate, "org", "neworg")),
|
||||
@@ -425,7 +472,7 @@ func TestCommandSide_ChangeOrg(t *testing.T) {
|
||||
name: "neworg",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
err: errors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -596,7 +643,7 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
err: errors.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -622,7 +669,7 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsPreconditionFailed,
|
||||
err: errors.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -638,7 +685,7 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
|
||||
),
|
||||
),
|
||||
expectPushFailed(
|
||||
caos_errs.ThrowInternal(nil, "id", "message"),
|
||||
errors.ThrowInternal(nil, "id", "message"),
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(org.NewOrgDeactivatedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate)),
|
||||
@@ -651,7 +698,7 @@ func TestCommandSide_DeactivateOrg(t *testing.T) {
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
err: errors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -731,7 +778,7 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
err: errors.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -753,7 +800,7 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsPreconditionFailed,
|
||||
err: errors.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -774,7 +821,7 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
|
||||
),
|
||||
),
|
||||
expectPushFailed(
|
||||
caos_errs.ThrowInternal(nil, "id", "message"),
|
||||
errors.ThrowInternal(nil, "id", "message"),
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(org.NewOrgReactivatedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
@@ -788,7 +835,7 @@ func TestCommandSide_ReactivateOrg(t *testing.T) {
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
err: errors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user