mirror of
https://github.com/zitadel/zitadel.git
synced 2025-07-18 05:28:36 +00:00

This PR summarizes multiple changes specifically only available with ZITADEL v3: - feat: Web Keys management (https://github.com/zitadel/zitadel/pull/9526) - fix(cmd): ensure proper working of mirror (https://github.com/zitadel/zitadel/pull/9509) - feat(Authz): system user support for permission check v2 (https://github.com/zitadel/zitadel/pull/9640) - chore(license): change from Apache to AGPL (https://github.com/zitadel/zitadel/pull/9597) - feat(console): list v2 sessions (https://github.com/zitadel/zitadel/pull/9539) - fix(console): add loginV2 feature flag (https://github.com/zitadel/zitadel/pull/9682) - fix(feature flags): allow reading "own" flags (https://github.com/zitadel/zitadel/pull/9649) - feat(console): add Actions V2 UI (https://github.com/zitadel/zitadel/pull/9591) BREAKING CHANGE - feat(webkey): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9445) - chore!: remove CockroachDB Support (https://github.com/zitadel/zitadel/pull/9444) - feat(actions): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9489) --------- Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com> Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com> Co-authored-by: Ramon <mail@conblem.me> Co-authored-by: Elio Bischof <elio@zitadel.com> Co-authored-by: Kenta Yamaguchi <56732734+KEY60228@users.noreply.github.com> Co-authored-by: Harsha Reddy <harsha.reddy@klaviyo.com> Co-authored-by: Livio Spring <livio@zitadel.com> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Iraq <66622793+kkrime@users.noreply.github.com> Co-authored-by: Florian Forster <florian@zitadel.com> Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Max Peintner <peintnerm@gmail.com>
694 lines
19 KiB
Go
694 lines
19 KiB
Go
//go:build integration
|
|
|
|
package action_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/integration"
|
|
action "github.com/zitadel/zitadel/pkg/grpc/action/v2beta"
|
|
)
|
|
|
|
func executionTargetsSingleTarget(id string) []*action.ExecutionTargetType {
|
|
return []*action.ExecutionTargetType{{Type: &action.ExecutionTargetType_Target{Target: id}}}
|
|
}
|
|
|
|
func executionTargetsSingleInclude(include *action.Condition) []*action.ExecutionTargetType {
|
|
return []*action.ExecutionTargetType{{Type: &action.ExecutionTargetType_Include{Include: include}}}
|
|
}
|
|
|
|
func TestServer_SetExecution_Request(t *testing.T) {
|
|
instance := integration.NewInstance(CTX)
|
|
ensureFeatureEnabled(t, instance)
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
wantSetDate bool
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "missing permission",
|
|
ctx: instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_All{All: true},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "no condition, error",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "method, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Method{
|
|
Method: "/zitadel.session.v2beta.NotExistingService/List",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "method, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Method{
|
|
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
{
|
|
name: "service, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Service{
|
|
Service: "NotExistingService",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "service, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Service{
|
|
Service: "zitadel.session.v2beta.SessionService",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
{
|
|
name: "all, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
// We want to have the same response no matter how often we call the function
|
|
creationDate := time.Now().UTC()
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
setDate := time.Now().UTC()
|
|
if tt.wantErr {
|
|
assert.Error(t, err)
|
|
return
|
|
}
|
|
assert.NoError(t, err)
|
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
|
|
|
// cleanup to not impact other requests
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|
|
|
|
func assertSetExecutionResponse(t *testing.T, creationDate, setDate time.Time, expectedSetDate bool, actualResp *action.SetExecutionResponse) {
|
|
if expectedSetDate {
|
|
if !setDate.IsZero() {
|
|
assert.WithinRange(t, actualResp.GetSetDate().AsTime(), creationDate, setDate)
|
|
} else {
|
|
assert.WithinRange(t, actualResp.GetSetDate().AsTime(), creationDate, time.Now().UTC())
|
|
}
|
|
} else {
|
|
assert.Nil(t, actualResp.SetDate)
|
|
}
|
|
}
|
|
|
|
func TestServer_SetExecution_Request_Include(t *testing.T) {
|
|
instance := integration.NewInstance(CTX)
|
|
ensureFeatureEnabled(t, instance)
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
executionCond := &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
instance.SetExecution(isolatedIAMOwnerCTX, t,
|
|
executionCond,
|
|
executionTargetsSingleTarget(targetResp.GetId()),
|
|
)
|
|
|
|
circularExecutionService := &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Service{
|
|
Service: "zitadel.session.v2beta.SessionService",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
instance.SetExecution(isolatedIAMOwnerCTX, t,
|
|
circularExecutionService,
|
|
executionTargetsSingleInclude(executionCond),
|
|
)
|
|
circularExecutionMethod := &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Method{
|
|
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
instance.SetExecution(isolatedIAMOwnerCTX, t,
|
|
circularExecutionMethod,
|
|
executionTargetsSingleInclude(circularExecutionService),
|
|
)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
wantSetDate bool
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "method, circular error",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: circularExecutionService,
|
|
Targets: executionTargetsSingleInclude(circularExecutionMethod),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "method, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Method{
|
|
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleInclude(executionCond),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
{
|
|
name: "service, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Service{
|
|
Service: "zitadel.user.v2beta.UserService",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleInclude(executionCond),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
creationDate := time.Now().UTC()
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
setDate := time.Now().UTC()
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
|
|
|
// cleanup to not impact other requests
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServer_SetExecution_Response(t *testing.T) {
|
|
instance := integration.NewInstance(CTX)
|
|
ensureFeatureEnabled(t, instance)
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
wantSetDate bool
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "missing permission",
|
|
ctx: instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{
|
|
Condition: &action.ResponseExecution_All{All: true},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "no condition, error",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "method, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{
|
|
Condition: &action.ResponseExecution_Method{
|
|
Method: "/zitadel.session.v2beta.NotExistingService/List",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "method, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{
|
|
Condition: &action.ResponseExecution_Method{
|
|
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
{
|
|
name: "service, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{
|
|
Condition: &action.ResponseExecution_Service{
|
|
Service: "NotExistingService",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "service, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{
|
|
Condition: &action.ResponseExecution_Service{
|
|
Service: "zitadel.session.v2beta.SessionService",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
{
|
|
name: "all, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{
|
|
Condition: &action.ResponseExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
creationDate := time.Now().UTC()
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
setDate := time.Now().UTC()
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
|
|
|
// cleanup to not impact other requests
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServer_SetExecution_Event(t *testing.T) {
|
|
instance := integration.NewInstance(CTX)
|
|
ensureFeatureEnabled(t, instance)
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
wantSetDate bool
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "missing permission",
|
|
ctx: instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "no condition, error",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "event, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_Event{
|
|
Event: "user.human.notexisting",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "event, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_Event{
|
|
Event: "user.human.added",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
{
|
|
name: "group, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_Group{
|
|
Group: "user.notexisting",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "group, level 1, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_Group{
|
|
Group: "user",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
{
|
|
name: "group, level 2, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_Group{
|
|
Group: "user.human",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
{
|
|
name: "all, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
creationDate := time.Now().UTC()
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
setDate := time.Now().UTC()
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
|
|
|
// cleanup to not impact other requests
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServer_SetExecution_Function(t *testing.T) {
|
|
instance := integration.NewInstance(CTX)
|
|
ensureFeatureEnabled(t, instance)
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
wantSetDate bool
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "missing permission",
|
|
ctx: instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{
|
|
Condition: &action.ResponseExecution_All{All: true},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "no condition, error",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "function, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Function{
|
|
Function: &action.FunctionExecution{Name: "xxx"},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "function, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Function{
|
|
Function: &action.FunctionExecution{Name: "presamlresponse"},
|
|
},
|
|
},
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
|
},
|
|
wantSetDate: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
creationDate := time.Now().UTC()
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
setDate := time.Now().UTC()
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
|
|
|
// cleanup to not impact other requests
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|