2024-03-14 09:56:23 +00:00
|
|
|
//go:build integration
|
|
|
|
|
2024-04-09 17:21:21 +00:00
|
|
|
package action_test
|
2024-03-14 09:56:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-05-04 09:55:57 +00:00
|
|
|
"reflect"
|
2024-03-14 09:56:23 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2024-03-14 09:56:23 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2024-04-09 17:21:21 +00:00
|
|
|
action "github.com/zitadel/zitadel/pkg/grpc/action/v3alpha"
|
2024-07-26 20:39:55 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/object/v2"
|
2024-03-14 09:56:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer_GetTargetByID(t *testing.T) {
|
2024-04-09 17:21:21 +00:00
|
|
|
ensureFeatureEnabled(t)
|
2024-03-14 09:56:23 +00:00
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
2024-04-09 17:21:21 +00:00
|
|
|
dep func(context.Context, *action.GetTargetByIDRequest, *action.GetTargetByIDResponse) error
|
|
|
|
req *action.GetTargetByIDRequest
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2024-04-09 17:21:21 +00:00
|
|
|
want *action.GetTargetByIDResponse
|
2024-03-14 09:56:23 +00:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing permission",
|
|
|
|
args: args{
|
|
|
|
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.GetTargetByIDRequest{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not found",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.GetTargetByIDRequest{TargetId: "notexisting"},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get, ok",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.GetTargetByIDRequest, response *action.GetTargetByIDResponse) error {
|
2024-03-14 09:56:23 +00:00
|
|
|
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
2024-05-04 09:55:57 +00:00
|
|
|
resp := Tester.CreateTarget(ctx, t, name, "https://example.com", domain.TargetTypeWebhook, false)
|
2024-03-14 09:56:23 +00:00
|
|
|
request.TargetId = resp.GetId()
|
|
|
|
|
|
|
|
response.Target.TargetId = resp.GetId()
|
|
|
|
response.Target.Name = name
|
|
|
|
response.Target.Details.ResourceOwner = resp.GetDetails().GetResourceOwner()
|
|
|
|
response.Target.Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Target.Details.Sequence = resp.GetDetails().GetSequence()
|
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.GetTargetByIDRequest{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.GetTargetByIDResponse{
|
|
|
|
Target: &action.Target{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: "https://example.com",
|
2024-04-09 17:21:21 +00:00
|
|
|
TargetType: &action.Target_RestWebhook{
|
2024-05-04 09:55:57 +00:00
|
|
|
RestWebhook: &action.SetRESTWebhook{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get, async, ok",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.GetTargetByIDRequest, response *action.GetTargetByIDResponse) error {
|
2024-03-14 09:56:23 +00:00
|
|
|
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
2024-05-04 09:55:57 +00:00
|
|
|
resp := Tester.CreateTarget(ctx, t, name, "https://example.com", domain.TargetTypeAsync, false)
|
2024-03-14 09:56:23 +00:00
|
|
|
request.TargetId = resp.GetId()
|
|
|
|
|
|
|
|
response.Target.TargetId = resp.GetId()
|
|
|
|
response.Target.Name = name
|
|
|
|
response.Target.Details.ResourceOwner = resp.GetDetails().GetResourceOwner()
|
|
|
|
response.Target.Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Target.Details.Sequence = resp.GetDetails().GetSequence()
|
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.GetTargetByIDRequest{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.GetTargetByIDResponse{
|
|
|
|
Target: &action.Target{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: "https://example.com",
|
|
|
|
TargetType: &action.Target_RestAsync{
|
|
|
|
RestAsync: &action.SetRESTAsync{},
|
|
|
|
},
|
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get, webhook interruptOnError, ok",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
dep: func(ctx context.Context, request *action.GetTargetByIDRequest, response *action.GetTargetByIDResponse) error {
|
|
|
|
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
|
|
|
resp := Tester.CreateTarget(ctx, t, name, "https://example.com", domain.TargetTypeWebhook, true)
|
|
|
|
request.TargetId = resp.GetId()
|
|
|
|
|
|
|
|
response.Target.TargetId = resp.GetId()
|
|
|
|
response.Target.Name = name
|
|
|
|
response.Target.Details.ResourceOwner = resp.GetDetails().GetResourceOwner()
|
|
|
|
response.Target.Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Target.Details.Sequence = resp.GetDetails().GetSequence()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
req: &action.GetTargetByIDRequest{},
|
|
|
|
},
|
|
|
|
want: &action.GetTargetByIDResponse{
|
|
|
|
Target: &action.Target{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
|
|
|
Endpoint: "https://example.com",
|
2024-04-09 17:21:21 +00:00
|
|
|
TargetType: &action.Target_RestWebhook{
|
|
|
|
RestWebhook: &action.SetRESTWebhook{
|
2024-05-04 09:55:57 +00:00
|
|
|
InterruptOnError: true,
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-05-04 09:55:57 +00:00
|
|
|
name: "get, call, ok",
|
2024-03-14 09:56:23 +00:00
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.GetTargetByIDRequest, response *action.GetTargetByIDResponse) error {
|
2024-03-14 09:56:23 +00:00
|
|
|
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
2024-05-04 09:55:57 +00:00
|
|
|
resp := Tester.CreateTarget(ctx, t, name, "https://example.com", domain.TargetTypeCall, false)
|
2024-03-14 09:56:23 +00:00
|
|
|
request.TargetId = resp.GetId()
|
|
|
|
|
|
|
|
response.Target.TargetId = resp.GetId()
|
|
|
|
response.Target.Name = name
|
|
|
|
response.Target.Details.ResourceOwner = resp.GetDetails().GetResourceOwner()
|
|
|
|
response.Target.Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Target.Details.Sequence = resp.GetDetails().GetSequence()
|
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.GetTargetByIDRequest{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.GetTargetByIDResponse{
|
|
|
|
Target: &action.Target{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: "https://example.com",
|
|
|
|
TargetType: &action.Target_RestCall{
|
|
|
|
RestCall: &action.SetRESTCall{
|
|
|
|
InterruptOnError: false,
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get, call interruptOnError, ok",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
dep: func(ctx context.Context, request *action.GetTargetByIDRequest, response *action.GetTargetByIDResponse) error {
|
|
|
|
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
|
|
|
resp := Tester.CreateTarget(ctx, t, name, "https://example.com", domain.TargetTypeCall, true)
|
|
|
|
request.TargetId = resp.GetId()
|
|
|
|
|
|
|
|
response.Target.TargetId = resp.GetId()
|
|
|
|
response.Target.Name = name
|
|
|
|
response.Target.Details.ResourceOwner = resp.GetDetails().GetResourceOwner()
|
|
|
|
response.Target.Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Target.Details.Sequence = resp.GetDetails().GetSequence()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
req: &action.GetTargetByIDRequest{},
|
|
|
|
},
|
|
|
|
want: &action.GetTargetByIDResponse{
|
|
|
|
Target: &action.Target{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
|
|
|
Endpoint: "https://example.com",
|
|
|
|
TargetType: &action.Target_RestCall{
|
|
|
|
RestCall: &action.SetRESTCall{
|
|
|
|
InterruptOnError: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if tt.args.dep != nil {
|
|
|
|
err := tt.args.dep(tt.args.ctx, tt.args.req, tt.want)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
retryDuration := 5 * time.Second
|
|
|
|
if ctxDeadline, ok := CTX.Deadline(); ok {
|
|
|
|
retryDuration = time.Until(ctxDeadline)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
|
|
|
got, getErr := Client.GetTargetByID(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
assert.Error(ttt, getErr, "Error: "+getErr.Error())
|
|
|
|
} else {
|
|
|
|
assert.NoError(ttt, getErr)
|
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
integration.AssertDetails(t, tt.want.GetTarget(), got.GetTarget())
|
2024-03-14 09:56:23 +00:00
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
assert.Equal(t, tt.want.Target, got.Target)
|
|
|
|
}
|
2024-03-14 09:56:23 +00:00
|
|
|
|
|
|
|
}, retryDuration, time.Millisecond*100, "timeout waiting for expected execution result")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_ListTargets(t *testing.T) {
|
2024-04-09 17:21:21 +00:00
|
|
|
ensureFeatureEnabled(t)
|
2024-03-14 09:56:23 +00:00
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
2024-04-09 17:21:21 +00:00
|
|
|
dep func(context.Context, *action.ListTargetsRequest, *action.ListTargetsResponse) error
|
|
|
|
req *action.ListTargetsRequest
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2024-04-09 17:21:21 +00:00
|
|
|
want *action.ListTargetsResponse
|
2024-03-14 09:56:23 +00:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing permission",
|
|
|
|
args: args{
|
|
|
|
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListTargetsRequest{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list, not found",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListTargetsRequest{
|
|
|
|
Queries: []*action.TargetSearchQuery{
|
|
|
|
{Query: &action.TargetSearchQuery_InTargetIdsQuery{
|
|
|
|
InTargetIdsQuery: &action.InTargetIDsQuery{
|
2024-03-14 09:56:23 +00:00
|
|
|
TargetIds: []string{"notfound"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.ListTargetsResponse{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 0,
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
Result: []*action.Target{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list single id",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.ListTargetsRequest, response *action.ListTargetsResponse) error {
|
2024-03-14 09:56:23 +00:00
|
|
|
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
2024-05-04 09:55:57 +00:00
|
|
|
resp := Tester.CreateTarget(ctx, t, name, "https://example.com", domain.TargetTypeWebhook, false)
|
2024-04-09 17:21:21 +00:00
|
|
|
request.Queries[0].Query = &action.TargetSearchQuery_InTargetIdsQuery{
|
|
|
|
InTargetIdsQuery: &action.InTargetIDsQuery{
|
2024-03-14 09:56:23 +00:00
|
|
|
TargetIds: []string{resp.GetId()},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
response.Details.Timestamp = resp.GetDetails().GetChangeDate()
|
2024-05-04 09:55:57 +00:00
|
|
|
//response.Details.ProcessedSequence = resp.GetDetails().GetSequence()
|
2024-03-14 09:56:23 +00:00
|
|
|
|
|
|
|
response.Result[0].Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Result[0].Details.Sequence = resp.GetDetails().GetSequence()
|
|
|
|
response.Result[0].TargetId = resp.GetId()
|
|
|
|
response.Result[0].Name = name
|
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListTargetsRequest{
|
|
|
|
Queries: []*action.TargetSearchQuery{{}},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.ListTargetsResponse{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
Result: []*action.Target{
|
2024-03-14 09:56:23 +00:00
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: "https://example.com",
|
2024-04-09 17:21:21 +00:00
|
|
|
TargetType: &action.Target_RestWebhook{
|
|
|
|
RestWebhook: &action.SetRESTWebhook{
|
2024-05-04 09:55:57 +00:00
|
|
|
InterruptOnError: false,
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "list single name",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.ListTargetsRequest, response *action.ListTargetsResponse) error {
|
2024-03-14 09:56:23 +00:00
|
|
|
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
2024-05-04 09:55:57 +00:00
|
|
|
resp := Tester.CreateTarget(ctx, t, name, "https://example.com", domain.TargetTypeWebhook, false)
|
2024-04-09 17:21:21 +00:00
|
|
|
request.Queries[0].Query = &action.TargetSearchQuery_TargetNameQuery{
|
|
|
|
TargetNameQuery: &action.TargetNameQuery{
|
2024-03-14 09:56:23 +00:00
|
|
|
TargetName: name,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
response.Details.Timestamp = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Details.ProcessedSequence = resp.GetDetails().GetSequence()
|
|
|
|
|
|
|
|
response.Result[0].Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Result[0].Details.Sequence = resp.GetDetails().GetSequence()
|
|
|
|
response.Result[0].TargetId = resp.GetId()
|
|
|
|
response.Result[0].Name = name
|
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListTargetsRequest{
|
|
|
|
Queries: []*action.TargetSearchQuery{{}},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.ListTargetsResponse{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
Result: []*action.Target{
|
2024-03-14 09:56:23 +00:00
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: "https://example.com",
|
2024-04-09 17:21:21 +00:00
|
|
|
TargetType: &action.Target_RestWebhook{
|
|
|
|
RestWebhook: &action.SetRESTWebhook{
|
2024-05-04 09:55:57 +00:00
|
|
|
InterruptOnError: false,
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list multiple id",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.ListTargetsRequest, response *action.ListTargetsResponse) error {
|
2024-03-14 09:56:23 +00:00
|
|
|
name1 := fmt.Sprint(time.Now().UnixNano() + 1)
|
|
|
|
name2 := fmt.Sprint(time.Now().UnixNano() + 3)
|
|
|
|
name3 := fmt.Sprint(time.Now().UnixNano() + 5)
|
2024-05-04 09:55:57 +00:00
|
|
|
resp1 := Tester.CreateTarget(ctx, t, name1, "https://example.com", domain.TargetTypeWebhook, false)
|
|
|
|
resp2 := Tester.CreateTarget(ctx, t, name2, "https://example.com", domain.TargetTypeCall, true)
|
|
|
|
resp3 := Tester.CreateTarget(ctx, t, name3, "https://example.com", domain.TargetTypeAsync, false)
|
2024-04-09 17:21:21 +00:00
|
|
|
request.Queries[0].Query = &action.TargetSearchQuery_InTargetIdsQuery{
|
|
|
|
InTargetIdsQuery: &action.InTargetIDsQuery{
|
2024-03-14 09:56:23 +00:00
|
|
|
TargetIds: []string{resp1.GetId(), resp2.GetId(), resp3.GetId()},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
response.Details.Timestamp = resp3.GetDetails().GetChangeDate()
|
|
|
|
response.Details.ProcessedSequence = resp3.GetDetails().GetSequence()
|
|
|
|
|
|
|
|
response.Result[0].Details.ChangeDate = resp1.GetDetails().GetChangeDate()
|
|
|
|
response.Result[0].Details.Sequence = resp1.GetDetails().GetSequence()
|
|
|
|
response.Result[0].TargetId = resp1.GetId()
|
|
|
|
response.Result[0].Name = name1
|
|
|
|
response.Result[1].Details.ChangeDate = resp2.GetDetails().GetChangeDate()
|
|
|
|
response.Result[1].Details.Sequence = resp2.GetDetails().GetSequence()
|
|
|
|
response.Result[1].TargetId = resp2.GetId()
|
|
|
|
response.Result[1].Name = name2
|
|
|
|
response.Result[2].Details.ChangeDate = resp3.GetDetails().GetChangeDate()
|
|
|
|
response.Result[2].Details.Sequence = resp3.GetDetails().GetSequence()
|
|
|
|
response.Result[2].TargetId = resp3.GetId()
|
|
|
|
response.Result[2].Name = name3
|
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListTargetsRequest{
|
|
|
|
Queries: []*action.TargetSearchQuery{{}},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.ListTargetsResponse{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 3,
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
Result: []*action.Target{
|
2024-03-14 09:56:23 +00:00
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: "https://example.com",
|
2024-04-09 17:21:21 +00:00
|
|
|
TargetType: &action.Target_RestWebhook{
|
|
|
|
RestWebhook: &action.SetRESTWebhook{
|
2024-05-04 09:55:57 +00:00
|
|
|
InterruptOnError: false,
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: "https://example.com",
|
|
|
|
TargetType: &action.Target_RestCall{
|
|
|
|
RestCall: &action.SetRESTCall{
|
|
|
|
InterruptOnError: true,
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: "https://example.com",
|
|
|
|
TargetType: &action.Target_RestAsync{
|
|
|
|
RestAsync: &action.SetRESTAsync{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if tt.args.dep != nil {
|
|
|
|
err := tt.args.dep(tt.args.ctx, tt.args.req, tt.want)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
retryDuration := 5 * time.Second
|
|
|
|
if ctxDeadline, ok := CTX.Deadline(); ok {
|
|
|
|
retryDuration = time.Until(ctxDeadline)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
|
|
|
got, listErr := Client.ListTargets(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
|
|
|
assert.Error(ttt, listErr, "Error: "+listErr.Error())
|
|
|
|
} else {
|
|
|
|
assert.NoError(ttt, listErr)
|
|
|
|
}
|
|
|
|
if listErr != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// always first check length, otherwise its failed anyway
|
|
|
|
assert.Len(ttt, got.Result, len(tt.want.Result))
|
|
|
|
for i := range tt.want.Result {
|
|
|
|
assert.Contains(ttt, got.Result, tt.want.Result[i])
|
|
|
|
}
|
|
|
|
integration.AssertListDetails(t, tt.want, got)
|
|
|
|
}, retryDuration, time.Millisecond*100, "timeout waiting for expected execution result")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
func TestServer_ListExecutions(t *testing.T) {
|
2024-04-09 17:21:21 +00:00
|
|
|
ensureFeatureEnabled(t)
|
2024-05-04 09:55:57 +00:00
|
|
|
targetResp := Tester.CreateTarget(CTX, t, "", "https://example.com", domain.TargetTypeWebhook, false)
|
2024-03-14 09:56:23 +00:00
|
|
|
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
2024-04-09 17:21:21 +00:00
|
|
|
dep func(context.Context, *action.ListExecutionsRequest, *action.ListExecutionsResponse) error
|
|
|
|
req *action.ListExecutionsRequest
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2024-04-09 17:21:21 +00:00
|
|
|
want *action.ListExecutionsResponse
|
2024-03-14 09:56:23 +00:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missing permission",
|
|
|
|
args: args{
|
|
|
|
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListExecutionsRequest{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
2024-05-04 09:55:57 +00:00
|
|
|
name: "list request single condition",
|
2024-03-14 09:56:23 +00:00
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.ListExecutionsRequest, response *action.ListExecutionsResponse) error {
|
2024-05-04 09:55:57 +00:00
|
|
|
cond := request.Queries[0].GetInConditionsQuery().GetConditions()[0]
|
|
|
|
resp := Tester.SetExecution(ctx, t, cond, executionTargetsSingleTarget(targetResp.GetId()))
|
2024-03-14 09:56:23 +00:00
|
|
|
|
|
|
|
response.Details.Timestamp = resp.GetDetails().GetChangeDate()
|
2024-05-04 09:55:57 +00:00
|
|
|
// response.Details.ProcessedSequence = resp.GetDetails().GetSequence()
|
2024-03-14 09:56:23 +00:00
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
// Set expected response with used values for SetExecution
|
2024-03-14 09:56:23 +00:00
|
|
|
response.Result[0].Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Result[0].Details.Sequence = resp.GetDetails().GetSequence()
|
2024-05-04 09:55:57 +00:00
|
|
|
response.Result[0].Condition = cond
|
2024-03-14 09:56:23 +00:00
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListExecutionsRequest{
|
|
|
|
Queries: []*action.SearchQuery{{
|
|
|
|
Query: &action.SearchQuery_InConditionsQuery{
|
|
|
|
InConditionsQuery: &action.InConditionsQuery{
|
|
|
|
Conditions: []*action.Condition{{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
2024-07-26 20:39:55 +00:00
|
|
|
Method: "/zitadel.session.v2.SessionService/GetSession",
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
}},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.ListExecutionsResponse{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
Result: []*action.Execution{
|
2024-03-14 09:56:23 +00:00
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Condition: &action.Condition{
|
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
2024-07-26 20:39:55 +00:00
|
|
|
Method: "/zitadel.session.v2.SessionService/GetSession",
|
2024-05-04 09:55:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Targets: executionTargetsSingleTarget(targetResp.GetId()),
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-05-04 09:55:57 +00:00
|
|
|
name: "list request single target",
|
2024-03-14 09:56:23 +00:00
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.ListExecutionsRequest, response *action.ListExecutionsResponse) error {
|
2024-05-04 09:55:57 +00:00
|
|
|
target := Tester.CreateTarget(CTX, t, "", "https://example.com", domain.TargetTypeWebhook, false)
|
2024-03-14 09:56:23 +00:00
|
|
|
// add target as query to the request
|
2024-04-09 17:21:21 +00:00
|
|
|
request.Queries[0] = &action.SearchQuery{
|
|
|
|
Query: &action.SearchQuery_TargetQuery{
|
|
|
|
TargetQuery: &action.TargetQuery{
|
2024-03-14 09:56:23 +00:00
|
|
|
TargetId: target.GetId(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-05-04 09:55:57 +00:00
|
|
|
cond := &action.Condition{
|
2024-04-09 17:21:21 +00:00
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
2024-03-14 09:56:23 +00:00
|
|
|
Method: "/zitadel.management.v1.ManagementService/UpdateAction",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
}
|
|
|
|
targets := executionTargetsSingleTarget(target.GetId())
|
|
|
|
resp := Tester.SetExecution(ctx, t, cond, targets)
|
2024-03-14 09:56:23 +00:00
|
|
|
|
|
|
|
response.Details.Timestamp = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Details.ProcessedSequence = resp.GetDetails().GetSequence()
|
|
|
|
|
|
|
|
response.Result[0].Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Result[0].Details.Sequence = resp.GetDetails().GetSequence()
|
2024-05-04 09:55:57 +00:00
|
|
|
response.Result[0].Condition = cond
|
|
|
|
response.Result[0].Targets = targets
|
2024-03-14 09:56:23 +00:00
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListExecutionsRequest{
|
|
|
|
Queries: []*action.SearchQuery{{}},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.ListExecutionsResponse{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
Result: []*action.Execution{
|
2024-03-14 09:56:23 +00:00
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
Condition: &action.Condition{},
|
|
|
|
Targets: executionTargetsSingleTarget(""),
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
2024-05-04 09:55:57 +00:00
|
|
|
name: "list request single include",
|
2024-03-14 09:56:23 +00:00
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.ListExecutionsRequest, response *action.ListExecutionsResponse) error {
|
2024-05-04 09:55:57 +00:00
|
|
|
cond := &action.Condition{
|
2024-04-09 17:21:21 +00:00
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
2024-03-14 09:56:23 +00:00
|
|
|
Method: "/zitadel.management.v1.ManagementService/GetAction",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
}
|
|
|
|
Tester.SetExecution(ctx, t, cond, executionTargetsSingleTarget(targetResp.GetId()))
|
|
|
|
request.Queries[0].GetIncludeQuery().Include = cond
|
|
|
|
|
|
|
|
includeCond := &action.Condition{
|
2024-04-09 17:21:21 +00:00
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
2024-03-14 09:56:23 +00:00
|
|
|
Method: "/zitadel.management.v1.ManagementService/ListActions",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
}
|
|
|
|
includeTargets := executionTargetsSingleInclude(cond)
|
|
|
|
resp2 := Tester.SetExecution(ctx, t, includeCond, includeTargets)
|
2024-03-14 09:56:23 +00:00
|
|
|
|
|
|
|
response.Details.Timestamp = resp2.GetDetails().GetChangeDate()
|
|
|
|
response.Details.ProcessedSequence = resp2.GetDetails().GetSequence()
|
|
|
|
|
|
|
|
response.Result[0].Details.ChangeDate = resp2.GetDetails().GetChangeDate()
|
|
|
|
response.Result[0].Details.Sequence = resp2.GetDetails().GetSequence()
|
2024-05-04 09:55:57 +00:00
|
|
|
response.Result[0].Condition = includeCond
|
|
|
|
response.Result[0].Targets = includeTargets
|
2024-03-14 09:56:23 +00:00
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListExecutionsRequest{
|
|
|
|
Queries: []*action.SearchQuery{{
|
|
|
|
Query: &action.SearchQuery_IncludeQuery{
|
2024-05-04 09:55:57 +00:00
|
|
|
IncludeQuery: &action.IncludeQuery{},
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.ListExecutionsResponse{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 1,
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
Result: []*action.Execution{
|
2024-03-14 09:56:23 +00:00
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "list multiple conditions",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
2024-04-09 17:21:21 +00:00
|
|
|
dep: func(ctx context.Context, request *action.ListExecutionsRequest, response *action.ListExecutionsResponse) error {
|
2024-03-14 09:56:23 +00:00
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
cond1 := request.Queries[0].GetInConditionsQuery().GetConditions()[0]
|
|
|
|
targets1 := executionTargetsSingleTarget(targetResp.GetId())
|
|
|
|
resp1 := Tester.SetExecution(ctx, t, cond1, targets1)
|
2024-03-14 09:56:23 +00:00
|
|
|
response.Result[0].Details.ChangeDate = resp1.GetDetails().GetChangeDate()
|
|
|
|
response.Result[0].Details.Sequence = resp1.GetDetails().GetSequence()
|
2024-05-04 09:55:57 +00:00
|
|
|
response.Result[0].Condition = cond1
|
|
|
|
response.Result[0].Targets = targets1
|
2024-03-14 09:56:23 +00:00
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
cond2 := request.Queries[0].GetInConditionsQuery().GetConditions()[1]
|
|
|
|
targets2 := executionTargetsSingleTarget(targetResp.GetId())
|
|
|
|
resp2 := Tester.SetExecution(ctx, t, cond2, targets2)
|
2024-03-14 09:56:23 +00:00
|
|
|
response.Result[1].Details.ChangeDate = resp2.GetDetails().GetChangeDate()
|
|
|
|
response.Result[1].Details.Sequence = resp2.GetDetails().GetSequence()
|
2024-05-04 09:55:57 +00:00
|
|
|
response.Result[1].Condition = cond2
|
|
|
|
response.Result[1].Targets = targets2
|
2024-03-14 09:56:23 +00:00
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
cond3 := request.Queries[0].GetInConditionsQuery().GetConditions()[2]
|
|
|
|
targets3 := executionTargetsSingleTarget(targetResp.GetId())
|
|
|
|
resp3 := Tester.SetExecution(ctx, t, cond3, targets3)
|
2024-03-14 09:56:23 +00:00
|
|
|
response.Result[2].Details.ChangeDate = resp3.GetDetails().GetChangeDate()
|
|
|
|
response.Result[2].Details.Sequence = resp3.GetDetails().GetSequence()
|
2024-05-04 09:55:57 +00:00
|
|
|
response.Result[2].Condition = cond3
|
|
|
|
response.Result[2].Targets = targets3
|
|
|
|
|
|
|
|
response.Details.Timestamp = resp3.GetDetails().GetChangeDate()
|
|
|
|
response.Details.ProcessedSequence = resp3.GetDetails().GetSequence()
|
2024-03-14 09:56:23 +00:00
|
|
|
return nil
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
req: &action.ListExecutionsRequest{
|
|
|
|
Queries: []*action.SearchQuery{{
|
|
|
|
Query: &action.SearchQuery_InConditionsQuery{
|
|
|
|
InConditionsQuery: &action.InConditionsQuery{
|
|
|
|
Conditions: []*action.Condition{
|
2024-03-14 09:56:23 +00:00
|
|
|
{
|
2024-04-09 17:21:21 +00:00
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
2024-07-26 20:39:55 +00:00
|
|
|
Method: "/zitadel.session.v2.SessionService/GetSession",
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-04-09 17:21:21 +00:00
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
2024-07-26 20:39:55 +00:00
|
|
|
Method: "/zitadel.session.v2.SessionService/CreateSession",
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-04-09 17:21:21 +00:00
|
|
|
ConditionType: &action.Condition_Request{
|
|
|
|
Request: &action.RequestExecution{
|
|
|
|
Condition: &action.RequestExecution_Method{
|
2024-07-26 20:39:55 +00:00
|
|
|
Method: "/zitadel.session.v2.SessionService/SetSession",
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
want: &action.ListExecutionsResponse{
|
2024-03-14 09:56:23 +00:00
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 3,
|
|
|
|
},
|
2024-04-09 17:21:21 +00:00
|
|
|
Result: []*action.Execution{
|
2024-03-14 09:56:23 +00:00
|
|
|
{
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
Details: &object.Details{
|
|
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
{
|
|
|
|
name: "list multiple conditions all types",
|
|
|
|
args: args{
|
|
|
|
ctx: CTX,
|
|
|
|
dep: func(ctx context.Context, request *action.ListExecutionsRequest, response *action.ListExecutionsResponse) error {
|
|
|
|
targets := executionTargetsSingleTarget(targetResp.GetId())
|
|
|
|
for i, cond := range request.Queries[0].GetInConditionsQuery().GetConditions() {
|
|
|
|
resp := Tester.SetExecution(ctx, t, cond, targets)
|
|
|
|
response.Result[i].Details.ChangeDate = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Result[i].Details.Sequence = resp.GetDetails().GetSequence()
|
|
|
|
response.Result[i].Condition = cond
|
|
|
|
response.Result[i].Targets = targets
|
|
|
|
|
|
|
|
// filled with info of last sequence
|
|
|
|
response.Details.Timestamp = resp.GetDetails().GetChangeDate()
|
|
|
|
response.Details.ProcessedSequence = resp.GetDetails().GetSequence()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
req: &action.ListExecutionsRequest{
|
|
|
|
Queries: []*action.SearchQuery{{
|
|
|
|
Query: &action.SearchQuery_InConditionsQuery{
|
|
|
|
InConditionsQuery: &action.InConditionsQuery{
|
|
|
|
Conditions: []*action.Condition{
|
2024-07-26 20:39:55 +00:00
|
|
|
{ConditionType: &action.Condition_Request{Request: &action.RequestExecution{Condition: &action.RequestExecution_Method{Method: "/zitadel.session.v2.SessionService/GetSession"}}}},
|
|
|
|
{ConditionType: &action.Condition_Request{Request: &action.RequestExecution{Condition: &action.RequestExecution_Service{Service: "zitadel.session.v2.SessionService"}}}},
|
2024-05-04 09:55:57 +00:00
|
|
|
{ConditionType: &action.Condition_Request{Request: &action.RequestExecution{Condition: &action.RequestExecution_All{All: true}}}},
|
2024-07-26 20:39:55 +00:00
|
|
|
{ConditionType: &action.Condition_Response{Response: &action.ResponseExecution{Condition: &action.ResponseExecution_Method{Method: "/zitadel.session.v2.SessionService/GetSession"}}}},
|
|
|
|
{ConditionType: &action.Condition_Response{Response: &action.ResponseExecution{Condition: &action.ResponseExecution_Service{Service: "zitadel.session.v2.SessionService"}}}},
|
2024-05-04 09:55:57 +00:00
|
|
|
{ConditionType: &action.Condition_Response{Response: &action.ResponseExecution{Condition: &action.ResponseExecution_All{All: true}}}},
|
|
|
|
{ConditionType: &action.Condition_Event{Event: &action.EventExecution{Condition: &action.EventExecution_Event{Event: "user.added"}}}},
|
|
|
|
{ConditionType: &action.Condition_Event{Event: &action.EventExecution{Condition: &action.EventExecution_Group{Group: "user"}}}},
|
|
|
|
{ConditionType: &action.Condition_Event{Event: &action.EventExecution{Condition: &action.EventExecution_All{All: true}}}},
|
|
|
|
{ConditionType: &action.Condition_Function{Function: &action.FunctionExecution{Name: "Action.Flow.Type.ExternalAuthentication.Action.TriggerType.PostAuthentication"}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &action.ListExecutionsResponse{
|
|
|
|
Details: &object.ListDetails{
|
|
|
|
TotalResult: 10,
|
|
|
|
},
|
|
|
|
Result: []*action.Execution{
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
{Details: &object.Details{ResourceOwner: Tester.Instance.InstanceID()}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if tt.args.dep != nil {
|
|
|
|
err := tt.args.dep(tt.args.ctx, tt.args.req, tt.want)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
retryDuration := 5 * time.Second
|
|
|
|
if ctxDeadline, ok := CTX.Deadline(); ok {
|
|
|
|
retryDuration = time.Until(ctxDeadline)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
|
|
|
got, listErr := Client.ListExecutions(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
2024-05-04 09:55:57 +00:00
|
|
|
assert.Error(t, listErr, "Error: "+listErr.Error())
|
2024-03-14 09:56:23 +00:00
|
|
|
} else {
|
2024-05-04 09:55:57 +00:00
|
|
|
assert.NoError(t, listErr)
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
|
|
|
if listErr != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// always first check length, otherwise its failed anyway
|
2024-05-04 09:55:57 +00:00
|
|
|
assert.Len(t, got.Result, len(tt.want.Result))
|
2024-03-14 09:56:23 +00:00
|
|
|
for i := range tt.want.Result {
|
2024-05-04 09:55:57 +00:00
|
|
|
// as not sorted, all elements have to be checked
|
|
|
|
// workaround as oneof elements can only be checked with assert.EqualExportedValues()
|
|
|
|
if j, found := containExecution(got.Result, tt.want.Result[i]); found {
|
|
|
|
assert.EqualExportedValues(t, tt.want.Result[i], got.Result[j])
|
|
|
|
}
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
|
|
|
integration.AssertListDetails(t, tt.want, got)
|
|
|
|
}, retryDuration, time.Millisecond*100, "timeout waiting for expected execution result")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-05-04 09:55:57 +00:00
|
|
|
|
|
|
|
func containExecution(executionList []*action.Execution, execution *action.Execution) (int, bool) {
|
|
|
|
for i, exec := range executionList {
|
|
|
|
if reflect.DeepEqual(exec.Details, execution.Details) {
|
|
|
|
return i, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0, false
|
|
|
|
}
|