mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 20:38:00 +00:00
042c438813
# Which Problems Are Solved The current v3alpha actions APIs don't exactly adhere to the [new resources API design](https://zitadel.com/docs/apis/v3#standard-resources). # How the Problems Are Solved - **Improved ID access**: The aggregate ID is added to the resource details object, so accessing resource IDs and constructing proto messages for resources is easier - **Explicit Instances**: Optionally, the instance can be explicitly given in each request - **Pagination**: A default search limit and a max search limit are added to the defaults.yaml. They apply to the new v3 APIs (currently only actions). The search query defaults are changed to ascending by creation date, because this makes the pagination results the most deterministic. The creation date is also added to the object details. The bug with updated creation dates is fixed for executions and targets. - **Removed Sequences**: Removed Sequence from object details and ProcessedSequence from search details # Additional Changes Object details IDs are checked in unit test only if an empty ID is expected. Centralizing the details check also makes this internal object more flexible for future evolutions. # Additional Context - Closes #8169 - Depends on https://github.com/zitadel/zitadel/pull/8225 --------- Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
809 lines
22 KiB
Go
809 lines
22 KiB
Go
//go:build integration
|
|
|
|
package action_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/integration"
|
|
object "github.com/zitadel/zitadel/pkg/grpc/object/v3alpha"
|
|
action "github.com/zitadel/zitadel/pkg/grpc/resources/action/v3alpha"
|
|
resource_object "github.com/zitadel/zitadel/pkg/grpc/resources/object/v3alpha"
|
|
)
|
|
|
|
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) {
|
|
_, instanceID, _, isolatedIAMOwnerCTX := Tester.UseIsolatedInstance(t, IAMOwnerCTX, SystemCTX)
|
|
ensureFeatureEnabled(t, isolatedIAMOwnerCTX)
|
|
targetResp := Tester.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
want *action.SetExecutionResponse
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "missing permission",
|
|
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
|
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{},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "all, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
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
|
|
Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
got, err := Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
integration.AssertResourceDetails(t, tt.want.Details, got.Details)
|
|
|
|
// cleanup to not impact other requests
|
|
Tester.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServer_SetExecution_Request_Include(t *testing.T) {
|
|
_, instanceID, _, isolatedIAMOwnerCTX := Tester.UseIsolatedInstance(t, IAMOwnerCTX, SystemCTX)
|
|
ensureFeatureEnabled(t, isolatedIAMOwnerCTX)
|
|
targetResp := Tester.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
executionCond := &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
Tester.SetExecution(isolatedIAMOwnerCTX, t,
|
|
executionCond,
|
|
executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
)
|
|
|
|
circularExecutionService := &action.Condition{
|
|
ConditionType: &action.Condition_Request{
|
|
Request: &action.RequestExecution{
|
|
Condition: &action.RequestExecution_Service{
|
|
Service: "zitadel.session.v2beta.SessionService",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
Tester.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",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
Tester.SetExecution(isolatedIAMOwnerCTX, t,
|
|
circularExecutionMethod,
|
|
executionTargetsSingleInclude(circularExecutionService),
|
|
)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
want *action.SetExecutionResponse
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "method, circular error",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: circularExecutionService,
|
|
Execution: &action.Execution{
|
|
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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleInclude(executionCond),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleInclude(executionCond),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
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
|
|
Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
got, err := Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
integration.AssertResourceDetails(t, tt.want.Details, got.Details)
|
|
|
|
// cleanup to not impact other requests
|
|
Tester.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServer_SetExecution_Response(t *testing.T) {
|
|
_, instanceID, _, isolatedIAMOwnerCTX := Tester.UseIsolatedInstance(t, IAMOwnerCTX, SystemCTX)
|
|
ensureFeatureEnabled(t, isolatedIAMOwnerCTX)
|
|
targetResp := Tester.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
want *action.SetExecutionResponse
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "missing permission",
|
|
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
|
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{},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "all, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Response{
|
|
Response: &action.ResponseExecution{
|
|
Condition: &action.ResponseExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
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
|
|
Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
got, err := Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
integration.AssertResourceDetails(t, tt.want.Details, got.Details)
|
|
|
|
// cleanup to not impact other requests
|
|
Tester.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServer_SetExecution_Event(t *testing.T) {
|
|
_, instanceID, _, isolatedIAMOwnerCTX := Tester.UseIsolatedInstance(t, IAMOwnerCTX, SystemCTX)
|
|
ensureFeatureEnabled(t, isolatedIAMOwnerCTX)
|
|
targetResp := Tester.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
want *action.SetExecutionResponse
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "missing permission",
|
|
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
|
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{},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
/*
|
|
//TODO event existing check
|
|
|
|
{
|
|
name: "event, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_Event{
|
|
Event: "xxx",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: []string{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: "xxx",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
/*
|
|
// TODO:
|
|
|
|
{
|
|
name: "group, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_Group{
|
|
Group: "xxx",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Targets: []string{targetResp.GetId()},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
*/
|
|
{
|
|
name: "group, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_Group{
|
|
Group: "xxx",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "all, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Event{
|
|
Event: &action.EventExecution{
|
|
Condition: &action.EventExecution_All{
|
|
All: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
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
|
|
Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
got, err := Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
integration.AssertResourceDetails(t, tt.want.Details, got.Details)
|
|
|
|
// cleanup to not impact other requests
|
|
Tester.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServer_SetExecution_Function(t *testing.T) {
|
|
_, instanceID, _, isolatedIAMOwnerCTX := Tester.UseIsolatedInstance(t, IAMOwnerCTX, SystemCTX)
|
|
ensureFeatureEnabled(t, isolatedIAMOwnerCTX)
|
|
targetResp := Tester.CreateTarget(isolatedIAMOwnerCTX, t, "", "https://notexisting", domain.TargetTypeWebhook, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
req *action.SetExecutionRequest
|
|
want *action.SetExecutionResponse
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "missing permission",
|
|
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
|
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{},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "function, not existing",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Function{
|
|
Function: &action.FunctionExecution{Name: "xxx"},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "function, ok",
|
|
ctx: isolatedIAMOwnerCTX,
|
|
req: &action.SetExecutionRequest{
|
|
Condition: &action.Condition{
|
|
ConditionType: &action.Condition_Function{
|
|
Function: &action.FunctionExecution{Name: "Action.Flow.Type.ExternalAuthentication.Action.TriggerType.PostAuthentication"},
|
|
},
|
|
},
|
|
Execution: &action.Execution{
|
|
Targets: executionTargetsSingleTarget(targetResp.GetDetails().GetId()),
|
|
},
|
|
},
|
|
want: &action.SetExecutionResponse{
|
|
Details: &resource_object.Details{
|
|
Changed: timestamppb.Now(),
|
|
Owner: &object.Owner{
|
|
Type: object.OwnerType_OWNER_TYPE_INSTANCE,
|
|
Id: instanceID,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
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
|
|
Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
got, err := Tester.Client.ActionV3.SetExecution(tt.ctx, tt.req)
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
integration.AssertResourceDetails(t, tt.want.Details, got.Details)
|
|
|
|
// cleanup to not impact other requests
|
|
Tester.DeleteExecution(tt.ctx, t, tt.req.GetCondition())
|
|
})
|
|
}
|
|
}
|