mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
feat: query side for executions and targets for actions v2 (#7524)
* feat: add projections and query side to executions and targets * feat: add list and get endpoints for targets * feat: add integration tests for query endpoints target and execution * fix: linting * fix: linting * fix: review changes, renames and corrections * fix: review changes, renames and corrections * fix: review changes, renames and corrections * fix: review changes, renames and corrections * fix: review changes, renames and corrections * fix: review changes, renames and corrections * fix: remove position from list details
This commit is contained in:
@@ -37,7 +37,7 @@ func (s *Server) SetExecution(ctx context.Context, req *execution.SetExecutionRe
|
||||
var err error
|
||||
var details *domain.ObjectDetails
|
||||
switch t := req.GetCondition().GetConditionType().(type) {
|
||||
case *execution.SetConditions_Request:
|
||||
case *execution.Condition_Request:
|
||||
cond := &command.ExecutionAPICondition{
|
||||
Method: t.Request.GetMethod(),
|
||||
Service: t.Request.GetService(),
|
||||
@@ -47,7 +47,7 @@ func (s *Server) SetExecution(ctx context.Context, req *execution.SetExecutionRe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *execution.SetConditions_Response:
|
||||
case *execution.Condition_Response:
|
||||
cond := &command.ExecutionAPICondition{
|
||||
Method: t.Response.GetMethod(),
|
||||
Service: t.Response.GetService(),
|
||||
@@ -57,7 +57,7 @@ func (s *Server) SetExecution(ctx context.Context, req *execution.SetExecutionRe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *execution.SetConditions_Event:
|
||||
case *execution.Condition_Event:
|
||||
cond := &command.ExecutionEventCondition{
|
||||
Event: t.Event.GetEvent(),
|
||||
Group: t.Event.GetGroup(),
|
||||
@@ -67,7 +67,7 @@ func (s *Server) SetExecution(ctx context.Context, req *execution.SetExecutionRe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *execution.SetConditions_Function:
|
||||
case *execution.Condition_Function:
|
||||
details, err = s.command.SetExecutionFunction(ctx, command.ExecutionFunctionCondition(t.Function), set, authz.GetInstance(ctx).InstanceID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -82,7 +82,7 @@ func (s *Server) DeleteExecution(ctx context.Context, req *execution.DeleteExecu
|
||||
var err error
|
||||
var details *domain.ObjectDetails
|
||||
switch t := req.GetCondition().GetConditionType().(type) {
|
||||
case *execution.SetConditions_Request:
|
||||
case *execution.Condition_Request:
|
||||
cond := &command.ExecutionAPICondition{
|
||||
Method: t.Request.GetMethod(),
|
||||
Service: t.Request.GetService(),
|
||||
@@ -92,7 +92,7 @@ func (s *Server) DeleteExecution(ctx context.Context, req *execution.DeleteExecu
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *execution.SetConditions_Response:
|
||||
case *execution.Condition_Response:
|
||||
cond := &command.ExecutionAPICondition{
|
||||
Method: t.Response.GetMethod(),
|
||||
Service: t.Response.GetService(),
|
||||
@@ -102,7 +102,7 @@ func (s *Server) DeleteExecution(ctx context.Context, req *execution.DeleteExecu
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *execution.SetConditions_Event:
|
||||
case *execution.Condition_Event:
|
||||
cond := &command.ExecutionEventCondition{
|
||||
Event: t.Event.GetEvent(),
|
||||
Group: t.Event.GetGroup(),
|
||||
@@ -112,7 +112,7 @@ func (s *Server) DeleteExecution(ctx context.Context, req *execution.DeleteExecu
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *execution.SetConditions_Function:
|
||||
case *execution.Condition_Function:
|
||||
details, err = s.command.DeleteExecutionFunction(ctx, command.ExecutionFunctionCondition(t.Function), authz.GetInstance(ctx).InstanceID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -28,10 +28,10 @@ func TestServer_SetExecution_Request(t *testing.T) {
|
||||
name: "missing permission",
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_All{All: true},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_All{All: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -42,9 +42,9 @@ func TestServer_SetExecution_Request(t *testing.T) {
|
||||
name: "no condition, error",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{},
|
||||
},
|
||||
},
|
||||
Targets: []string{targetResp.GetId()},
|
||||
@@ -55,10 +55,10 @@ func TestServer_SetExecution_Request(t *testing.T) {
|
||||
name: "method, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.NotExistingService/List",
|
||||
},
|
||||
},
|
||||
@@ -72,10 +72,10 @@ func TestServer_SetExecution_Request(t *testing.T) {
|
||||
name: "method, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
||||
},
|
||||
},
|
||||
@@ -94,10 +94,10 @@ func TestServer_SetExecution_Request(t *testing.T) {
|
||||
name: "service, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Service{
|
||||
Service: "NotExistingService",
|
||||
},
|
||||
},
|
||||
@@ -111,10 +111,10 @@ func TestServer_SetExecution_Request(t *testing.T) {
|
||||
name: "service, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Service{
|
||||
Service: "zitadel.session.v2beta.SessionService",
|
||||
},
|
||||
},
|
||||
@@ -133,10 +133,10 @@ func TestServer_SetExecution_Request(t *testing.T) {
|
||||
name: "all, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -170,16 +170,17 @@ func TestServer_SetExecution_Request_Include(t *testing.T) {
|
||||
targetResp := Tester.CreateTarget(CTX, t)
|
||||
executionCond := "request"
|
||||
Tester.SetExecution(CTX, t,
|
||||
&execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_All{
|
||||
&execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
[]string{targetResp.GetId()},
|
||||
[]string{},
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
@@ -193,10 +194,10 @@ func TestServer_SetExecution_Request_Include(t *testing.T) {
|
||||
name: "method, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
||||
},
|
||||
},
|
||||
@@ -215,10 +216,10 @@ func TestServer_SetExecution_Request_Include(t *testing.T) {
|
||||
name: "service, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Service{
|
||||
Service: "zitadel.session.v2beta.SessionService",
|
||||
},
|
||||
},
|
||||
@@ -237,10 +238,10 @@ func TestServer_SetExecution_Request_Include(t *testing.T) {
|
||||
name: "all, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -285,10 +286,10 @@ func TestServer_DeleteExecution_Request(t *testing.T) {
|
||||
name: "missing permission",
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_All{All: true},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_All{All: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -299,9 +300,9 @@ func TestServer_DeleteExecution_Request(t *testing.T) {
|
||||
name: "no condition, error",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -311,10 +312,10 @@ func TestServer_DeleteExecution_Request(t *testing.T) {
|
||||
name: "method, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/NotExisting",
|
||||
},
|
||||
},
|
||||
@@ -327,14 +328,14 @@ func TestServer_DeleteExecution_Request(t *testing.T) {
|
||||
name: "method, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/GetSession",
|
||||
},
|
||||
},
|
||||
@@ -352,10 +353,10 @@ func TestServer_DeleteExecution_Request(t *testing.T) {
|
||||
name: "service, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Service{
|
||||
Service: "NotExistingService",
|
||||
},
|
||||
},
|
||||
@@ -368,14 +369,14 @@ func TestServer_DeleteExecution_Request(t *testing.T) {
|
||||
name: "service, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Service{
|
||||
Service: "zitadel.user.v2beta.UserService",
|
||||
},
|
||||
},
|
||||
@@ -393,14 +394,14 @@ func TestServer_DeleteExecution_Request(t *testing.T) {
|
||||
name: "all, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Request{
|
||||
Request: &execution.SetRequestExecution{
|
||||
Condition: &execution.SetRequestExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -448,10 +449,10 @@ func TestServer_SetExecution_Response(t *testing.T) {
|
||||
name: "missing permission",
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_All{All: true},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_All{All: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -462,9 +463,9 @@ func TestServer_SetExecution_Response(t *testing.T) {
|
||||
name: "no condition, error",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{},
|
||||
},
|
||||
},
|
||||
Targets: []string{targetResp.GetId()},
|
||||
@@ -475,10 +476,10 @@ func TestServer_SetExecution_Response(t *testing.T) {
|
||||
name: "method, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.NotExistingService/List",
|
||||
},
|
||||
},
|
||||
@@ -492,10 +493,10 @@ func TestServer_SetExecution_Response(t *testing.T) {
|
||||
name: "method, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/ListSessions",
|
||||
},
|
||||
},
|
||||
@@ -514,10 +515,10 @@ func TestServer_SetExecution_Response(t *testing.T) {
|
||||
name: "service, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_Service{
|
||||
Service: "NotExistingService",
|
||||
},
|
||||
},
|
||||
@@ -531,10 +532,10 @@ func TestServer_SetExecution_Response(t *testing.T) {
|
||||
name: "service, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_Service{
|
||||
Service: "zitadel.session.v2beta.SessionService",
|
||||
},
|
||||
},
|
||||
@@ -553,10 +554,10 @@ func TestServer_SetExecution_Response(t *testing.T) {
|
||||
name: "all, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -601,10 +602,10 @@ func TestServer_DeleteExecution_Response(t *testing.T) {
|
||||
name: "missing permission",
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -617,9 +618,9 @@ func TestServer_DeleteExecution_Response(t *testing.T) {
|
||||
name: "no condition, error",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -629,10 +630,10 @@ func TestServer_DeleteExecution_Response(t *testing.T) {
|
||||
name: "method, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/NotExisting",
|
||||
},
|
||||
},
|
||||
@@ -645,14 +646,14 @@ func TestServer_DeleteExecution_Response(t *testing.T) {
|
||||
name: "method, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_Method{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/GetSession",
|
||||
},
|
||||
},
|
||||
@@ -670,10 +671,10 @@ func TestServer_DeleteExecution_Response(t *testing.T) {
|
||||
name: "service, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_Service{
|
||||
Service: "NotExistingService",
|
||||
},
|
||||
},
|
||||
@@ -686,14 +687,14 @@ func TestServer_DeleteExecution_Response(t *testing.T) {
|
||||
name: "service, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_Service{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_Service{
|
||||
Service: "zitadel.user.v2beta.UserService",
|
||||
},
|
||||
},
|
||||
@@ -711,14 +712,14 @@ func TestServer_DeleteExecution_Response(t *testing.T) {
|
||||
name: "all, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -766,10 +767,10 @@ func TestServer_SetExecution_Event(t *testing.T) {
|
||||
name: "missing permission",
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -782,9 +783,9 @@ func TestServer_SetExecution_Event(t *testing.T) {
|
||||
name: "no condition, error",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{},
|
||||
},
|
||||
},
|
||||
Targets: []string{targetResp.GetId()},
|
||||
@@ -798,10 +799,10 @@ func TestServer_SetExecution_Event(t *testing.T) {
|
||||
name: "event, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_Event{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_Event{
|
||||
Event: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -816,10 +817,10 @@ func TestServer_SetExecution_Event(t *testing.T) {
|
||||
name: "event, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_Event{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_Event{
|
||||
Event: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -841,10 +842,10 @@ func TestServer_SetExecution_Event(t *testing.T) {
|
||||
name: "group, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_Group{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_Group{
|
||||
Group: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -859,10 +860,10 @@ func TestServer_SetExecution_Event(t *testing.T) {
|
||||
name: "group, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_Group{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_Group{
|
||||
Group: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -881,10 +882,10 @@ func TestServer_SetExecution_Event(t *testing.T) {
|
||||
name: "all, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -929,10 +930,10 @@ func TestServer_DeleteExecution_Event(t *testing.T) {
|
||||
name: "missing permission",
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -945,9 +946,9 @@ func TestServer_DeleteExecution_Event(t *testing.T) {
|
||||
name: "no condition, error",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -959,10 +960,10 @@ func TestServer_DeleteExecution_Event(t *testing.T) {
|
||||
name: "event, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_Event{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_Event{
|
||||
Event: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -976,14 +977,14 @@ func TestServer_DeleteExecution_Event(t *testing.T) {
|
||||
name: "event, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_Event{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_Event{
|
||||
Event: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -1001,10 +1002,10 @@ func TestServer_DeleteExecution_Event(t *testing.T) {
|
||||
name: "group, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_Group{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_Group{
|
||||
Group: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -1017,14 +1018,14 @@ func TestServer_DeleteExecution_Event(t *testing.T) {
|
||||
name: "group, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_Group{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_Group{
|
||||
Group: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -1042,10 +1043,10 @@ func TestServer_DeleteExecution_Event(t *testing.T) {
|
||||
name: "all, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -1063,14 +1064,14 @@ func TestServer_DeleteExecution_Event(t *testing.T) {
|
||||
name: "all, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Event{
|
||||
Event: &execution.SetEventExecution{
|
||||
Condition: &execution.SetEventExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Event{
|
||||
Event: &execution.EventExecution{
|
||||
Condition: &execution.EventExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -1118,10 +1119,10 @@ func TestServer_SetExecution_Function(t *testing.T) {
|
||||
name: "missing permission",
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_All{All: true},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_All{All: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1132,9 +1133,9 @@ func TestServer_SetExecution_Function(t *testing.T) {
|
||||
name: "no condition, error",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{},
|
||||
},
|
||||
},
|
||||
Targets: []string{targetResp.GetId()},
|
||||
@@ -1145,8 +1146,8 @@ func TestServer_SetExecution_Function(t *testing.T) {
|
||||
name: "function, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Function{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Function{
|
||||
Function: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -1158,8 +1159,8 @@ func TestServer_SetExecution_Function(t *testing.T) {
|
||||
name: "function, ok",
|
||||
ctx: CTX,
|
||||
req: &execution.SetExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Function{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Function{
|
||||
Function: "Action.Flow.Type.ExternalAuthentication.Action.TriggerType.PostAuthentication",
|
||||
},
|
||||
},
|
||||
@@ -1202,10 +1203,10 @@ func TestServer_DeleteExecution_Function(t *testing.T) {
|
||||
name: "missing permission",
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{
|
||||
Condition: &execution.SetResponseExecution_All{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{
|
||||
Condition: &execution.ResponseExecution_All{
|
||||
All: true,
|
||||
},
|
||||
},
|
||||
@@ -1218,9 +1219,9 @@ func TestServer_DeleteExecution_Function(t *testing.T) {
|
||||
name: "no condition, error",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Response{
|
||||
Response: &execution.SetResponseExecution{},
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Response{
|
||||
Response: &execution.ResponseExecution{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1230,8 +1231,8 @@ func TestServer_DeleteExecution_Function(t *testing.T) {
|
||||
name: "function, not existing",
|
||||
ctx: CTX,
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Function{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Function{
|
||||
Function: "xxx",
|
||||
},
|
||||
},
|
||||
@@ -1242,12 +1243,12 @@ func TestServer_DeleteExecution_Function(t *testing.T) {
|
||||
name: "function, ok",
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.DeleteExecutionRequest) error {
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()})
|
||||
Tester.SetExecution(ctx, t, request.GetCondition(), []string{targetResp.GetId()}, []string{})
|
||||
return nil
|
||||
},
|
||||
req: &execution.DeleteExecutionRequest{
|
||||
Condition: &execution.SetConditions{
|
||||
ConditionType: &execution.SetConditions_Function{
|
||||
Condition: &execution.Condition{
|
||||
ConditionType: &execution.Condition_Function{
|
||||
Function: "Action.Flow.Type.ExternalAuthentication.Action.TriggerType.PostAuthentication",
|
||||
},
|
||||
},
|
||||
|
286
internal/api/grpc/execution/v3alpha/query.go
Normal file
286
internal/api/grpc/execution/v3alpha/query.go
Normal file
@@ -0,0 +1,286 @@
|
||||
package execution
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/grpc/object/v2"
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
execution "github.com/zitadel/zitadel/pkg/grpc/execution/v3alpha"
|
||||
)
|
||||
|
||||
func (s *Server) ListTargets(ctx context.Context, req *execution.ListTargetsRequest) (*execution.ListTargetsResponse, error) {
|
||||
queries, err := listTargetsRequestToModel(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := s.query.SearchTargets(ctx, queries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &execution.ListTargetsResponse{
|
||||
Result: targetsToPb(resp.Targets),
|
||||
Details: object.ToListDetails(resp.SearchResponse),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func listTargetsRequestToModel(req *execution.ListTargetsRequest) (*query.TargetSearchQueries, error) {
|
||||
offset, limit, asc := object.ListQueryToQuery(req.Query)
|
||||
queries, err := targetQueriesToQuery(req.Queries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &query.TargetSearchQueries{
|
||||
SearchRequest: query.SearchRequest{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
SortingColumn: targetFieldNameToSortingColumn(req.SortingColumn),
|
||||
},
|
||||
Queries: queries,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func targetFieldNameToSortingColumn(field execution.TargetFieldName) query.Column {
|
||||
switch field {
|
||||
case execution.TargetFieldName_FIELD_NAME_UNSPECIFIED:
|
||||
return query.TargetColumnID
|
||||
case execution.TargetFieldName_FIELD_NAME_ID:
|
||||
return query.TargetColumnID
|
||||
case execution.TargetFieldName_FIELD_NAME_CREATION_DATE:
|
||||
return query.TargetColumnCreationDate
|
||||
case execution.TargetFieldName_FIELD_NAME_CHANGE_DATE:
|
||||
return query.TargetColumnChangeDate
|
||||
case execution.TargetFieldName_FIELD_NAME_NAME:
|
||||
return query.TargetColumnName
|
||||
case execution.TargetFieldName_FIELD_NAME_TARGET_TYPE:
|
||||
return query.TargetColumnTargetType
|
||||
case execution.TargetFieldName_FIELD_NAME_URL:
|
||||
return query.TargetColumnURL
|
||||
case execution.TargetFieldName_FIELD_NAME_TIMEOUT:
|
||||
return query.TargetColumnTimeout
|
||||
case execution.TargetFieldName_FIELD_NAME_ASYNC:
|
||||
return query.TargetColumnAsync
|
||||
case execution.TargetFieldName_FIELD_NAME_INTERRUPT_ON_ERROR:
|
||||
return query.TargetColumnInterruptOnError
|
||||
default:
|
||||
return query.TargetColumnID
|
||||
}
|
||||
}
|
||||
|
||||
func targetQueriesToQuery(queries []*execution.TargetSearchQuery) (_ []query.SearchQuery, err error) {
|
||||
q := make([]query.SearchQuery, len(queries))
|
||||
for i, query := range queries {
|
||||
q[i], err = targetQueryToQuery(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func targetQueryToQuery(query *execution.TargetSearchQuery) (query.SearchQuery, error) {
|
||||
switch q := query.Query.(type) {
|
||||
case *execution.TargetSearchQuery_TargetNameQuery:
|
||||
return targetNameQueryToQuery(q.TargetNameQuery)
|
||||
case *execution.TargetSearchQuery_InTargetIdsQuery:
|
||||
return targetInTargetIdsQueryToQuery(q.InTargetIdsQuery)
|
||||
default:
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "GRPC-vR9nC", "List.Query.Invalid")
|
||||
}
|
||||
}
|
||||
|
||||
func targetNameQueryToQuery(q *execution.TargetNameQuery) (query.SearchQuery, error) {
|
||||
return query.NewTargetNameSearchQuery(object.TextMethodToQuery(q.Method), q.GetTargetName())
|
||||
}
|
||||
|
||||
func targetInTargetIdsQueryToQuery(q *execution.InTargetIDsQuery) (query.SearchQuery, error) {
|
||||
return query.NewTargetInIDsSearchQuery(q.GetTargetIds())
|
||||
}
|
||||
|
||||
func (s *Server) GetTargetByID(ctx context.Context, req *execution.GetTargetByIDRequest) (_ *execution.GetTargetByIDResponse, err error) {
|
||||
resp, err := s.query.GetTargetByID(ctx, req.GetTargetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &execution.GetTargetByIDResponse{
|
||||
Target: targetToPb(resp),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func targetsToPb(targets []*query.Target) []*execution.Target {
|
||||
t := make([]*execution.Target, len(targets))
|
||||
for i, target := range targets {
|
||||
t[i] = targetToPb(target)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func targetToPb(t *query.Target) *execution.Target {
|
||||
target := &execution.Target{
|
||||
Details: object.DomainToDetailsPb(&t.ObjectDetails),
|
||||
TargetId: t.ID,
|
||||
Name: t.Name,
|
||||
Timeout: durationpb.New(t.Timeout),
|
||||
}
|
||||
if t.Async {
|
||||
target.ExecutionType = &execution.Target_IsAsync{IsAsync: t.Async}
|
||||
}
|
||||
if t.InterruptOnError {
|
||||
target.ExecutionType = &execution.Target_InterruptOnError{InterruptOnError: t.InterruptOnError}
|
||||
}
|
||||
|
||||
switch t.TargetType {
|
||||
case domain.TargetTypeWebhook:
|
||||
target.TargetType = &execution.Target_RestWebhook{RestWebhook: &execution.SetRESTWebhook{Url: t.URL}}
|
||||
case domain.TargetTypeRequestResponse:
|
||||
target.TargetType = &execution.Target_RestRequestResponse{RestRequestResponse: &execution.SetRESTRequestResponse{Url: t.URL}}
|
||||
default:
|
||||
target.TargetType = nil
|
||||
}
|
||||
return target
|
||||
}
|
||||
|
||||
func (s *Server) ListExecutions(ctx context.Context, req *execution.ListExecutionsRequest) (*execution.ListExecutionsResponse, error) {
|
||||
queries, err := listExecutionsRequestToModel(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := s.query.SearchExecutions(ctx, queries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &execution.ListExecutionsResponse{
|
||||
Result: executionsToPb(resp.Executions),
|
||||
Details: object.ToListDetails(resp.SearchResponse),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func listExecutionsRequestToModel(req *execution.ListExecutionsRequest) (*query.ExecutionSearchQueries, error) {
|
||||
offset, limit, asc := object.ListQueryToQuery(req.Query)
|
||||
queries, err := executionQueriesToQuery(req.Queries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &query.ExecutionSearchQueries{
|
||||
SearchRequest: query.SearchRequest{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
},
|
||||
Queries: queries,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func executionQueriesToQuery(queries []*execution.SearchQuery) (_ []query.SearchQuery, err error) {
|
||||
q := make([]query.SearchQuery, len(queries))
|
||||
for i, query := range queries {
|
||||
q[i], err = executionQueryToQuery(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func executionQueryToQuery(searchQuery *execution.SearchQuery) (query.SearchQuery, error) {
|
||||
switch q := searchQuery.Query.(type) {
|
||||
case *execution.SearchQuery_InConditionsQuery:
|
||||
return inConditionsQueryToQuery(q.InConditionsQuery)
|
||||
case *execution.SearchQuery_ExecutionTypeQuery:
|
||||
return executionTypeToQuery(q.ExecutionTypeQuery)
|
||||
case *execution.SearchQuery_TargetQuery:
|
||||
return query.NewExecutionTargetSearchQuery(q.TargetQuery.GetTargetId())
|
||||
case *execution.SearchQuery_IncludeQuery:
|
||||
return query.NewExecutionIncludeSearchQuery(q.IncludeQuery.GetInclude())
|
||||
default:
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "GRPC-vR9nC", "List.Query.Invalid")
|
||||
}
|
||||
}
|
||||
|
||||
func executionTypeToQuery(q *execution.ExecutionTypeQuery) (query.SearchQuery, error) {
|
||||
switch q.ExecutionType {
|
||||
case execution.ExecutionType_EXECUTION_TYPE_UNSPECIFIED:
|
||||
return query.NewExecutionTypeSearchQuery(domain.ExecutionTypeUnspecified)
|
||||
case execution.ExecutionType_EXECUTION_TYPE_REQUEST:
|
||||
return query.NewExecutionTypeSearchQuery(domain.ExecutionTypeRequest)
|
||||
case execution.ExecutionType_EXECUTION_TYPE_RESPONSE:
|
||||
return query.NewExecutionTypeSearchQuery(domain.ExecutionTypeResponse)
|
||||
case execution.ExecutionType_EXECUTION_TYPE_EVENT:
|
||||
return query.NewExecutionTypeSearchQuery(domain.ExecutionTypeEvent)
|
||||
case execution.ExecutionType_EXECUTION_TYPE_FUNCTION:
|
||||
return query.NewExecutionTypeSearchQuery(domain.ExecutionTypeFunction)
|
||||
default:
|
||||
return query.NewExecutionTypeSearchQuery(domain.ExecutionTypeUnspecified)
|
||||
}
|
||||
}
|
||||
|
||||
func inConditionsQueryToQuery(q *execution.InConditionsQuery) (query.SearchQuery, error) {
|
||||
values := make([]string, len(q.GetConditions()))
|
||||
for i, condition := range q.GetConditions() {
|
||||
id, err := conditionToID(condition)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values[i] = id
|
||||
}
|
||||
return query.NewExecutionInIDsSearchQuery(values)
|
||||
}
|
||||
|
||||
func conditionToID(q *execution.Condition) (string, error) {
|
||||
switch t := q.GetConditionType().(type) {
|
||||
case *execution.Condition_Request:
|
||||
cond := &command.ExecutionAPICondition{
|
||||
Method: t.Request.GetMethod(),
|
||||
Service: t.Request.GetService(),
|
||||
All: t.Request.GetAll(),
|
||||
}
|
||||
return cond.ID(domain.ExecutionTypeRequest), nil
|
||||
case *execution.Condition_Response:
|
||||
cond := &command.ExecutionAPICondition{
|
||||
Method: t.Response.GetMethod(),
|
||||
Service: t.Response.GetService(),
|
||||
All: t.Response.GetAll(),
|
||||
}
|
||||
return cond.ID(domain.ExecutionTypeResponse), nil
|
||||
case *execution.Condition_Event:
|
||||
cond := &command.ExecutionEventCondition{
|
||||
Event: t.Event.GetEvent(),
|
||||
Group: t.Event.GetGroup(),
|
||||
All: t.Event.GetAll(),
|
||||
}
|
||||
return cond.ID(), nil
|
||||
case *execution.Condition_Function:
|
||||
return t.Function, nil
|
||||
default:
|
||||
return "", zerrors.ThrowInvalidArgument(nil, "GRPC-vR9nC", "List.Query.Invalid")
|
||||
}
|
||||
}
|
||||
|
||||
func executionsToPb(executions []*query.Execution) []*execution.Execution {
|
||||
e := make([]*execution.Execution, len(executions))
|
||||
for i, execution := range executions {
|
||||
e[i] = executionToPb(execution)
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func executionToPb(e *query.Execution) *execution.Execution {
|
||||
var targets, includes []string
|
||||
if len(e.Targets) > 0 {
|
||||
targets = e.Targets
|
||||
}
|
||||
if len(e.Includes) > 0 {
|
||||
includes = e.Includes
|
||||
}
|
||||
return &execution.Execution{
|
||||
Details: object.DomainToDetailsPb(&e.ObjectDetails),
|
||||
ExecutionId: e.ID,
|
||||
Targets: targets,
|
||||
Includes: includes,
|
||||
}
|
||||
}
|
715
internal/api/grpc/execution/v3alpha/query_integration_test.go
Normal file
715
internal/api/grpc/execution/v3alpha/query_integration_test.go
Normal file
@@ -0,0 +1,715 @@
|
||||
//go:build integration
|
||||
|
||||
package execution_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/integration"
|
||||
execution "github.com/zitadel/zitadel/pkg/grpc/execution/v3alpha"
|
||||
object "github.com/zitadel/zitadel/pkg/grpc/object/v2beta"
|
||||
)
|
||||
|
||||
func TestServer_GetTargetByID(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
dep func(context.Context, *execution.GetTargetByIDRequest, *execution.GetTargetByIDResponse) error
|
||||
req *execution.GetTargetByIDRequest
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *execution.GetTargetByIDResponse
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "missing permission",
|
||||
args: args{
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.GetTargetByIDRequest{},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "not found",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
req: &execution.GetTargetByIDRequest{TargetId: "notexisting"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "get, ok",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.GetTargetByIDRequest, response *execution.GetTargetByIDResponse) error {
|
||||
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
||||
resp := Tester.CreateTargetWithNameAndType(ctx, t, name, false, false)
|
||||
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: &execution.GetTargetByIDRequest{},
|
||||
},
|
||||
want: &execution.GetTargetByIDResponse{
|
||||
Target: &execution.Target{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
TargetType: &execution.Target_RestWebhook{
|
||||
RestWebhook: &execution.SetRESTWebhook{
|
||||
Url: "https://example.com",
|
||||
},
|
||||
},
|
||||
Timeout: durationpb.New(10 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "get, async, ok",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.GetTargetByIDRequest, response *execution.GetTargetByIDResponse) error {
|
||||
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
||||
resp := Tester.CreateTargetWithNameAndType(ctx, t, name, true, false)
|
||||
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: &execution.GetTargetByIDRequest{},
|
||||
},
|
||||
want: &execution.GetTargetByIDResponse{
|
||||
Target: &execution.Target{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
TargetType: &execution.Target_RestWebhook{
|
||||
RestWebhook: &execution.SetRESTWebhook{
|
||||
Url: "https://example.com",
|
||||
},
|
||||
},
|
||||
Timeout: durationpb.New(10 * time.Second),
|
||||
ExecutionType: &execution.Target_IsAsync{IsAsync: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "get, interruptOnError, ok",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.GetTargetByIDRequest, response *execution.GetTargetByIDResponse) error {
|
||||
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
||||
resp := Tester.CreateTargetWithNameAndType(ctx, t, name, false, 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: &execution.GetTargetByIDRequest{},
|
||||
},
|
||||
want: &execution.GetTargetByIDResponse{
|
||||
Target: &execution.Target{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
TargetType: &execution.Target_RestWebhook{
|
||||
RestWebhook: &execution.SetRESTWebhook{
|
||||
Url: "https://example.com",
|
||||
},
|
||||
},
|
||||
Timeout: durationpb.New(10 * time.Second),
|
||||
ExecutionType: &execution.Target_InterruptOnError{InterruptOnError: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
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)
|
||||
}
|
||||
if getErr != nil {
|
||||
fmt.Println("Error: " + getErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
integration.AssertDetails(t, tt.want.GetTarget(), got.GetTarget())
|
||||
|
||||
assert.Equal(t, tt.want.Target, got.Target)
|
||||
|
||||
}, retryDuration, time.Millisecond*100, "timeout waiting for expected execution result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_ListTargets(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
dep func(context.Context, *execution.ListTargetsRequest, *execution.ListTargetsResponse) error
|
||||
req *execution.ListTargetsRequest
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *execution.ListTargetsResponse
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "missing permission",
|
||||
args: args{
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.ListTargetsRequest{},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "list, not found",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
req: &execution.ListTargetsRequest{
|
||||
Queries: []*execution.TargetSearchQuery{
|
||||
{Query: &execution.TargetSearchQuery_InTargetIdsQuery{
|
||||
InTargetIdsQuery: &execution.InTargetIDsQuery{
|
||||
TargetIds: []string{"notfound"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &execution.ListTargetsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 0,
|
||||
},
|
||||
Result: []*execution.Target{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list single id",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.ListTargetsRequest, response *execution.ListTargetsResponse) error {
|
||||
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
||||
resp := Tester.CreateTargetWithNameAndType(ctx, t, name, false, false)
|
||||
request.Queries[0].Query = &execution.TargetSearchQuery_InTargetIdsQuery{
|
||||
InTargetIdsQuery: &execution.InTargetIDsQuery{
|
||||
TargetIds: []string{resp.GetId()},
|
||||
},
|
||||
}
|
||||
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
|
||||
},
|
||||
req: &execution.ListTargetsRequest{
|
||||
Queries: []*execution.TargetSearchQuery{{}},
|
||||
},
|
||||
},
|
||||
want: &execution.ListTargetsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*execution.Target{
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
TargetType: &execution.Target_RestWebhook{
|
||||
RestWebhook: &execution.SetRESTWebhook{
|
||||
Url: "https://example.com",
|
||||
},
|
||||
},
|
||||
Timeout: durationpb.New(10 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "list single name",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.ListTargetsRequest, response *execution.ListTargetsResponse) error {
|
||||
name := fmt.Sprint(time.Now().UnixNano() + 1)
|
||||
resp := Tester.CreateTargetWithNameAndType(ctx, t, name, false, false)
|
||||
request.Queries[0].Query = &execution.TargetSearchQuery_TargetNameQuery{
|
||||
TargetNameQuery: &execution.TargetNameQuery{
|
||||
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
|
||||
},
|
||||
req: &execution.ListTargetsRequest{
|
||||
Queries: []*execution.TargetSearchQuery{{}},
|
||||
},
|
||||
},
|
||||
want: &execution.ListTargetsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*execution.Target{
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
TargetType: &execution.Target_RestWebhook{
|
||||
RestWebhook: &execution.SetRESTWebhook{
|
||||
Url: "https://example.com",
|
||||
},
|
||||
},
|
||||
Timeout: durationpb.New(10 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list multiple id",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.ListTargetsRequest, response *execution.ListTargetsResponse) error {
|
||||
name1 := fmt.Sprint(time.Now().UnixNano() + 1)
|
||||
name2 := fmt.Sprint(time.Now().UnixNano() + 3)
|
||||
name3 := fmt.Sprint(time.Now().UnixNano() + 5)
|
||||
resp1 := Tester.CreateTargetWithNameAndType(ctx, t, name1, false, false)
|
||||
resp2 := Tester.CreateTargetWithNameAndType(ctx, t, name2, true, false)
|
||||
resp3 := Tester.CreateTargetWithNameAndType(ctx, t, name3, false, true)
|
||||
request.Queries[0].Query = &execution.TargetSearchQuery_InTargetIdsQuery{
|
||||
InTargetIdsQuery: &execution.InTargetIDsQuery{
|
||||
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
|
||||
},
|
||||
req: &execution.ListTargetsRequest{
|
||||
Queries: []*execution.TargetSearchQuery{{}},
|
||||
},
|
||||
},
|
||||
want: &execution.ListTargetsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 3,
|
||||
},
|
||||
Result: []*execution.Target{
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
TargetType: &execution.Target_RestWebhook{
|
||||
RestWebhook: &execution.SetRESTWebhook{
|
||||
Url: "https://example.com",
|
||||
},
|
||||
},
|
||||
Timeout: durationpb.New(10 * time.Second),
|
||||
},
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
TargetType: &execution.Target_RestWebhook{
|
||||
RestWebhook: &execution.SetRESTWebhook{
|
||||
Url: "https://example.com",
|
||||
},
|
||||
},
|
||||
Timeout: durationpb.New(10 * time.Second),
|
||||
ExecutionType: &execution.Target_IsAsync{IsAsync: true},
|
||||
},
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
TargetType: &execution.Target_RestWebhook{
|
||||
RestWebhook: &execution.SetRESTWebhook{
|
||||
Url: "https://example.com",
|
||||
},
|
||||
},
|
||||
Timeout: durationpb.New(10 * time.Second),
|
||||
ExecutionType: &execution.Target_InterruptOnError{InterruptOnError: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
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")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_ListExecutions_Request(t *testing.T) {
|
||||
targetResp := Tester.CreateTarget(CTX, t)
|
||||
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
dep func(context.Context, *execution.ListExecutionsRequest, *execution.ListExecutionsResponse) error
|
||||
req *execution.ListExecutionsRequest
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *execution.ListExecutionsResponse
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "missing permission",
|
||||
args: args{
|
||||
ctx: Tester.WithAuthorization(context.Background(), integration.OrgOwner),
|
||||
req: &execution.ListExecutionsRequest{},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "list single condition",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.ListExecutionsRequest, response *execution.ListExecutionsResponse) error {
|
||||
resp := Tester.SetExecution(ctx, t, request.Queries[0].GetInConditionsQuery().GetConditions()[0], []string{targetResp.GetId()}, []string{})
|
||||
|
||||
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()
|
||||
return nil
|
||||
},
|
||||
req: &execution.ListExecutionsRequest{
|
||||
Queries: []*execution.SearchQuery{{
|
||||
Query: &execution.SearchQuery_InConditionsQuery{
|
||||
InConditionsQuery: &execution.InConditionsQuery{
|
||||
Conditions: []*execution.Condition{{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/GetSession",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
want: &execution.ListExecutionsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*execution.Execution{
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
ExecutionId: "request./zitadel.session.v2beta.SessionService/GetSession",
|
||||
Targets: []string{targetResp.GetId()},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list single target",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.ListExecutionsRequest, response *execution.ListExecutionsResponse) error {
|
||||
target := Tester.CreateTarget(ctx, t)
|
||||
// add target as query to the request
|
||||
request.Queries[0] = &execution.SearchQuery{
|
||||
Query: &execution.SearchQuery_TargetQuery{
|
||||
TargetQuery: &execution.TargetQuery{
|
||||
TargetId: target.GetId(),
|
||||
},
|
||||
},
|
||||
}
|
||||
resp := Tester.SetExecution(ctx, t, &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.management.v1.ManagementService/UpdateAction",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, []string{target.GetId()}, []string{})
|
||||
|
||||
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].Targets[0] = target.GetId()
|
||||
return nil
|
||||
},
|
||||
req: &execution.ListExecutionsRequest{
|
||||
Queries: []*execution.SearchQuery{{}},
|
||||
},
|
||||
},
|
||||
want: &execution.ListExecutionsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*execution.Execution{
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
ExecutionId: "request./zitadel.management.v1.ManagementService/UpdateAction",
|
||||
Targets: []string{""},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "list single include",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.ListExecutionsRequest, response *execution.ListExecutionsResponse) error {
|
||||
Tester.SetExecution(ctx, t, &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.management.v1.ManagementService/GetAction",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, []string{targetResp.GetId()}, []string{})
|
||||
resp2 := Tester.SetExecution(ctx, t, &execution.Condition{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.management.v1.ManagementService/ListActions",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, []string{}, []string{"request./zitadel.management.v1.ManagementService/GetAction"})
|
||||
|
||||
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()
|
||||
return nil
|
||||
},
|
||||
req: &execution.ListExecutionsRequest{
|
||||
Queries: []*execution.SearchQuery{{
|
||||
Query: &execution.SearchQuery_IncludeQuery{
|
||||
IncludeQuery: &execution.IncludeQuery{Include: "request./zitadel.management.v1.ManagementService/GetAction"},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
want: &execution.ListExecutionsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*execution.Execution{
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
ExecutionId: "request./zitadel.management.v1.ManagementService/ListActions",
|
||||
Includes: []string{"request./zitadel.management.v1.ManagementService/GetAction"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list multiple conditions",
|
||||
args: args{
|
||||
ctx: CTX,
|
||||
dep: func(ctx context.Context, request *execution.ListExecutionsRequest, response *execution.ListExecutionsResponse) error {
|
||||
|
||||
resp1 := Tester.SetExecution(ctx, t, request.Queries[0].GetInConditionsQuery().GetConditions()[0], []string{targetResp.GetId()}, []string{})
|
||||
response.Result[0].Details.ChangeDate = resp1.GetDetails().GetChangeDate()
|
||||
response.Result[0].Details.Sequence = resp1.GetDetails().GetSequence()
|
||||
|
||||
resp2 := Tester.SetExecution(ctx, t, request.Queries[0].GetInConditionsQuery().GetConditions()[1], []string{targetResp.GetId()}, []string{})
|
||||
response.Result[1].Details.ChangeDate = resp2.GetDetails().GetChangeDate()
|
||||
response.Result[1].Details.Sequence = resp2.GetDetails().GetSequence()
|
||||
|
||||
resp3 := Tester.SetExecution(ctx, t, request.Queries[0].GetInConditionsQuery().GetConditions()[2], []string{targetResp.GetId()}, []string{})
|
||||
response.Details.Timestamp = resp3.GetDetails().GetChangeDate()
|
||||
response.Details.ProcessedSequence = resp3.GetDetails().GetSequence()
|
||||
response.Result[2].Details.ChangeDate = resp3.GetDetails().GetChangeDate()
|
||||
response.Result[2].Details.Sequence = resp3.GetDetails().GetSequence()
|
||||
return nil
|
||||
},
|
||||
req: &execution.ListExecutionsRequest{
|
||||
Queries: []*execution.SearchQuery{{
|
||||
Query: &execution.SearchQuery_InConditionsQuery{
|
||||
InConditionsQuery: &execution.InConditionsQuery{
|
||||
Conditions: []*execution.Condition{
|
||||
{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/GetSession",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/CreateSession",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ConditionType: &execution.Condition_Request{
|
||||
Request: &execution.RequestExecution{
|
||||
Condition: &execution.RequestExecution_Method{
|
||||
Method: "/zitadel.session.v2beta.SessionService/SetSession",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
want: &execution.ListExecutionsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 3,
|
||||
},
|
||||
Result: []*execution.Execution{
|
||||
{
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
ExecutionId: "request./zitadel.session.v2beta.SessionService/GetSession",
|
||||
Targets: []string{targetResp.GetId()},
|
||||
}, {
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
ExecutionId: "request./zitadel.session.v2beta.SessionService/CreateSession",
|
||||
Targets: []string{targetResp.GetId()},
|
||||
}, {
|
||||
Details: &object.Details{
|
||||
ResourceOwner: Tester.Instance.InstanceID(),
|
||||
},
|
||||
ExecutionId: "request./zitadel.session.v2beta.SessionService/SetSession",
|
||||
Targets: []string{targetResp.GetId()},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
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 {
|
||||
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")
|
||||
})
|
||||
}
|
||||
}
|
@@ -27,7 +27,6 @@ func Test_createTargetToCommand(t *testing.T) {
|
||||
args: args{nil},
|
||||
want: &command.AddTarget{
|
||||
Name: "",
|
||||
TargetType: domain.TargetTypeUnspecified,
|
||||
URL: "",
|
||||
Timeout: 0,
|
||||
Async: false,
|
||||
|
Reference in New Issue
Block a user