2024-07-31 14:42:12 +02:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package action_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2025-04-02 16:53:06 +02:00
|
|
|
"time"
|
2024-07-31 14:42:12 +02:00
|
|
|
|
2025-04-02 16:53:06 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-31 14:42:12 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2025-04-02 16:53:06 +02:00
|
|
|
action "github.com/zitadel/zitadel/pkg/grpc/action/v2beta"
|
2024-07-31 14:42:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2024-09-06 15:47:57 +03:00
|
|
|
instance := integration.NewInstance(CTX)
|
|
|
|
ensureFeatureEnabled(t, instance)
|
|
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
tests := []struct {
|
2025-04-02 16:53:06 +02:00
|
|
|
name string
|
|
|
|
ctx context.Context
|
|
|
|
req *action.SetExecutionRequest
|
|
|
|
wantSetDate bool
|
|
|
|
wantErr bool
|
2024-07-31 14:42:12 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing permission",
|
2024-09-06 15:47:57 +03:00
|
|
|
ctx: instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
2024-07-31 14:42:12 +02:00
|
|
|
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",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "method, not existing",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
|
|
|
Method: "/zitadel.session.v2beta.NotExistingService/List",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "method, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
|
|
|
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service, not existing",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Service{
|
|
|
|
Service: "NotExistingService",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Service{
|
|
|
|
Service: "zitadel.session.v2beta.SessionService",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "all, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_All{
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
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
|
2025-04-02 16:53:06 +02:00
|
|
|
creationDate := time.Now().UTC()
|
|
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
|
|
setDate := time.Now().UTC()
|
2024-07-31 14:42:12 +02:00
|
|
|
if tt.wantErr {
|
2025-04-02 16:53:06 +02:00
|
|
|
assert.Error(t, err)
|
2024-07-31 14:42:12 +02:00
|
|
|
return
|
|
|
|
}
|
2025-04-02 16:53:06 +02:00
|
|
|
assert.NoError(t, err)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
2025-04-02 16:53:06 +02:00
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
// cleanup to not impact other requests
|
2024-09-06 15:47:57 +03:00
|
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
2024-07-31 14:42:12 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-02 16:53:06 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-31 14:42:12 +02:00
|
|
|
func TestServer_SetExecution_Request_Include(t *testing.T) {
|
2024-09-06 15:47:57 +03:00
|
|
|
instance := integration.NewInstance(CTX)
|
|
|
|
ensureFeatureEnabled(t, instance)
|
|
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
2024-07-31 14:42:12 +02:00
|
|
|
executionCond := &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_All{
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-09-06 15:47:57 +03:00
|
|
|
instance.SetExecution(isolatedIAMOwnerCTX, t,
|
2024-07-31 14:42:12 +02:00
|
|
|
executionCond,
|
2025-04-02 16:53:06 +02:00
|
|
|
executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
circularExecutionService := &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Service{
|
|
|
|
Service: "zitadel.session.v2beta.SessionService",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-09-06 15:47:57 +03:00
|
|
|
instance.SetExecution(isolatedIAMOwnerCTX, t,
|
2024-07-31 14:42:12 +02:00
|
|
|
circularExecutionService,
|
|
|
|
executionTargetsSingleInclude(executionCond),
|
|
|
|
)
|
|
|
|
circularExecutionMethod := &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
|
|
|
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-09-06 15:47:57 +03:00
|
|
|
instance.SetExecution(isolatedIAMOwnerCTX, t,
|
2024-07-31 14:42:12 +02:00
|
|
|
circularExecutionMethod,
|
|
|
|
executionTargetsSingleInclude(circularExecutionService),
|
|
|
|
)
|
|
|
|
|
|
|
|
tests := []struct {
|
2025-04-02 16:53:06 +02:00
|
|
|
name string
|
|
|
|
ctx context.Context
|
|
|
|
req *action.SetExecutionRequest
|
|
|
|
wantSetDate bool
|
|
|
|
wantErr bool
|
2024-07-31 14:42:12 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "method, circular error",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: circularExecutionService,
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleInclude(circularExecutionMethod),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "method, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
|
|
|
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleInclude(executionCond),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Service{
|
2025-04-02 16:53:06 +02:00
|
|
|
Service: "zitadel.user.v2beta.UserService",
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleInclude(executionCond),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2025-04-02 16:53:06 +02:00
|
|
|
creationDate := time.Now().UTC()
|
|
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
|
|
setDate := time.Now().UTC()
|
2024-07-31 14:42:12 +02:00
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2025-04-02 16:53:06 +02:00
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
// cleanup to not impact other requests
|
2024-09-06 15:47:57 +03:00
|
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
2024-07-31 14:42:12 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_SetExecution_Response(t *testing.T) {
|
2024-09-06 15:47:57 +03:00
|
|
|
instance := integration.NewInstance(CTX)
|
|
|
|
ensureFeatureEnabled(t, instance)
|
|
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
tests := []struct {
|
2025-04-02 16:53:06 +02:00
|
|
|
name string
|
|
|
|
ctx context.Context
|
|
|
|
req *action.SetExecutionRequest
|
|
|
|
wantSetDate bool
|
|
|
|
wantErr bool
|
2024-07-31 14:42:12 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing permission",
|
2024-09-06 15:47:57 +03:00
|
|
|
ctx: instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
2024-07-31 14:42:12 +02:00
|
|
|
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",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Response{
|
|
|
|
Response: &action.ResponseExecution{},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "method, not existing",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Response{
|
|
|
|
Response: &action.ResponseExecution{
|
|
|
|
Condition: &action.ResponseExecution_Method{
|
|
|
|
Method: "/zitadel.session.v2beta.NotExistingService/List",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "method, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Response{
|
|
|
|
Response: &action.ResponseExecution{
|
|
|
|
Condition: &action.ResponseExecution_Method{
|
|
|
|
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service, not existing",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Response{
|
|
|
|
Response: &action.ResponseExecution{
|
|
|
|
Condition: &action.ResponseExecution_Service{
|
|
|
|
Service: "NotExistingService",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Response{
|
|
|
|
Response: &action.ResponseExecution{
|
|
|
|
Condition: &action.ResponseExecution_Service{
|
|
|
|
Service: "zitadel.session.v2beta.SessionService",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "all, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Response{
|
|
|
|
Response: &action.ResponseExecution{
|
|
|
|
Condition: &action.ResponseExecution_All{
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2025-04-02 16:53:06 +02:00
|
|
|
creationDate := time.Now().UTC()
|
|
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
|
|
setDate := time.Now().UTC()
|
2024-07-31 14:42:12 +02:00
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2025-04-02 16:53:06 +02:00
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
// cleanup to not impact other requests
|
2024-09-06 15:47:57 +03:00
|
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
2024-07-31 14:42:12 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_SetExecution_Event(t *testing.T) {
|
2024-09-06 15:47:57 +03:00
|
|
|
instance := integration.NewInstance(CTX)
|
|
|
|
ensureFeatureEnabled(t, instance)
|
|
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
tests := []struct {
|
2025-04-02 16:53:06 +02:00
|
|
|
name string
|
|
|
|
ctx context.Context
|
|
|
|
req *action.SetExecutionRequest
|
|
|
|
wantSetDate bool
|
|
|
|
wantErr bool
|
2024-07-31 14:42:12 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing permission",
|
2024-09-06 15:47:57 +03:00
|
|
|
ctx: instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
2024-07-31 14:42:12 +02:00
|
|
|
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",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Event{
|
|
|
|
Event: &action.EventExecution{},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
{
|
|
|
|
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",
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantErr: true,
|
|
|
|
},
|
2024-07-31 14:42:12 +02:00
|
|
|
{
|
|
|
|
name: "event, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Event{
|
|
|
|
Event: &action.EventExecution{
|
|
|
|
Condition: &action.EventExecution_Event{
|
2025-04-02 16:53:06 +02:00
|
|
|
Event: "user.human.added",
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
{
|
|
|
|
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",
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantErr: true,
|
|
|
|
},
|
2024-07-31 14:42:12 +02:00
|
|
|
{
|
2025-04-02 16:53:06 +02:00
|
|
|
name: "group, level 1, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Event{
|
|
|
|
Event: &action.EventExecution{
|
|
|
|
Condition: &action.EventExecution_Group{
|
2025-04-02 16:53:06 +02:00
|
|
|
Group: "user",
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "all, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Event{
|
|
|
|
Event: &action.EventExecution{
|
|
|
|
Condition: &action.EventExecution_All{
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2025-04-02 16:53:06 +02:00
|
|
|
creationDate := time.Now().UTC()
|
|
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
|
|
setDate := time.Now().UTC()
|
2024-07-31 14:42:12 +02:00
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2025-04-02 16:53:06 +02:00
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
// cleanup to not impact other requests
|
2024-09-06 15:47:57 +03:00
|
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
2024-07-31 14:42:12 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_SetExecution_Function(t *testing.T) {
|
2024-09-06 15:47:57 +03:00
|
|
|
instance := integration.NewInstance(CTX)
|
|
|
|
ensureFeatureEnabled(t, instance)
|
|
|
|
isolatedIAMOwnerCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
|
|
|
|
targetResp := instance.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
tests := []struct {
|
2025-04-02 16:53:06 +02:00
|
|
|
name string
|
|
|
|
ctx context.Context
|
|
|
|
req *action.SetExecutionRequest
|
|
|
|
wantSetDate bool
|
|
|
|
wantErr bool
|
2024-07-31 14:42:12 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing permission",
|
2024-09-06 15:47:57 +03:00
|
|
|
ctx: instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
2024-07-31 14:42:12 +02:00
|
|
|
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",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Response{
|
|
|
|
Response: &action.ResponseExecution{},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "function, not existing",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Function{
|
|
|
|
Function: &action.FunctionExecution{Name: "xxx"},
|
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "function, ok",
|
2024-08-12 22:32:01 +02:00
|
|
|
ctx: isolatedIAMOwnerCTX,
|
2024-07-31 14:42:12 +02:00
|
|
|
req: &action.SetExecutionRequest{
|
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Function{
|
2025-03-04 12:09:30 +01:00
|
|
|
Function: &action.FunctionExecution{Name: "presamlresponse"},
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
2025-04-02 16:53:06 +02:00
|
|
|
wantSetDate: true,
|
2024-07-31 14:42:12 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2025-04-02 16:53:06 +02:00
|
|
|
creationDate := time.Now().UTC()
|
|
|
|
got, err := instance.Client.ActionV2beta.SetExecution(tt.ctx, tt.req)
|
|
|
|
setDate := time.Now().UTC()
|
2024-07-31 14:42:12 +02:00
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2025-04-02 16:53:06 +02:00
|
|
|
assertSetExecutionResponse(t, creationDate, setDate, tt.wantSetDate, got)
|
2024-07-31 14:42:12 +02:00
|
|
|
|
|
|
|
// cleanup to not impact other requests
|
2024-09-06 15:47:57 +03:00
|
|
|
instance.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
2024-07-31 14:42:12 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|