mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
1c5ecba42a
* feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: split request and response logic to handle the different context information * feat: split request and response logic to handle the different context information * fix: integration test * fix: import alias * fix: refactor execution package * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * docs: basic documentation for executions and targets * fix: change order for interceptors * fix: merge back origin/main * fix: change target definition command and query side (#7735) * fix: change target definition command and query side * fix: correct refactoring name changes * fix: correct refactoring name changes * fix: changing execution defintion with target list and type * fix: changing execution definition with target list and type * fix: add back search queries for target and include * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * docs: add example to actions v2 * docs: add example to actions v2 * fix: correct integration tests on query for executions * fix: add separate event for execution v2 as content changed * fix: add separate event for execution v2 as content changed * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com> * fix: added review comment changes * fix: added review comment changes * Update internal/api/grpc/server/middleware/execution_interceptor.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com> Co-authored-by: Elio Bischof <elio@zitadel.com>
230 lines
6.1 KiB
Go
230 lines
6.1 KiB
Go
package action
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/muhlemmer/gu"
|
|
"github.com/stretchr/testify/assert"
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
action "github.com/zitadel/zitadel/pkg/grpc/action/v3alpha"
|
|
)
|
|
|
|
func Test_createTargetToCommand(t *testing.T) {
|
|
type args struct {
|
|
req *action.CreateTargetRequest
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *command.AddTarget
|
|
}{
|
|
{
|
|
name: "nil",
|
|
args: args{nil},
|
|
want: &command.AddTarget{
|
|
Name: "",
|
|
Endpoint: "",
|
|
Timeout: 0,
|
|
InterruptOnError: false,
|
|
},
|
|
},
|
|
{
|
|
name: "all fields (webhook)",
|
|
args: args{&action.CreateTargetRequest{
|
|
Name: "target 1",
|
|
Endpoint: "https://example.com/hooks/1",
|
|
TargetType: &action.CreateTargetRequest_RestWebhook{
|
|
RestWebhook: &action.SetRESTWebhook{},
|
|
},
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
}},
|
|
want: &command.AddTarget{
|
|
Name: "target 1",
|
|
TargetType: domain.TargetTypeWebhook,
|
|
Endpoint: "https://example.com/hooks/1",
|
|
Timeout: 10 * time.Second,
|
|
InterruptOnError: false,
|
|
},
|
|
},
|
|
{
|
|
name: "all fields (async)",
|
|
args: args{&action.CreateTargetRequest{
|
|
Name: "target 1",
|
|
Endpoint: "https://example.com/hooks/1",
|
|
TargetType: &action.CreateTargetRequest_RestAsync{
|
|
RestAsync: &action.SetRESTAsync{},
|
|
},
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
}},
|
|
want: &command.AddTarget{
|
|
Name: "target 1",
|
|
TargetType: domain.TargetTypeAsync,
|
|
Endpoint: "https://example.com/hooks/1",
|
|
Timeout: 10 * time.Second,
|
|
InterruptOnError: false,
|
|
},
|
|
},
|
|
{
|
|
name: "all fields (interrupting response)",
|
|
args: args{&action.CreateTargetRequest{
|
|
Name: "target 1",
|
|
Endpoint: "https://example.com/hooks/1",
|
|
TargetType: &action.CreateTargetRequest_RestCall{
|
|
RestCall: &action.SetRESTCall{
|
|
InterruptOnError: true,
|
|
},
|
|
},
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
}},
|
|
want: &command.AddTarget{
|
|
Name: "target 1",
|
|
TargetType: domain.TargetTypeCall,
|
|
Endpoint: "https://example.com/hooks/1",
|
|
Timeout: 10 * time.Second,
|
|
InterruptOnError: true,
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := createTargetToCommand(tt.args.req)
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_updateTargetToCommand(t *testing.T) {
|
|
type args struct {
|
|
req *action.UpdateTargetRequest
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *command.ChangeTarget
|
|
}{
|
|
{
|
|
name: "nil",
|
|
args: args{nil},
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "all fields nil",
|
|
args: args{&action.UpdateTargetRequest{
|
|
Name: nil,
|
|
TargetType: nil,
|
|
Timeout: nil,
|
|
}},
|
|
want: &command.ChangeTarget{
|
|
Name: nil,
|
|
TargetType: nil,
|
|
Endpoint: nil,
|
|
Timeout: nil,
|
|
InterruptOnError: nil,
|
|
},
|
|
},
|
|
{
|
|
name: "all fields empty",
|
|
args: args{&action.UpdateTargetRequest{
|
|
Name: gu.Ptr(""),
|
|
TargetType: nil,
|
|
Timeout: durationpb.New(0),
|
|
}},
|
|
want: &command.ChangeTarget{
|
|
Name: gu.Ptr(""),
|
|
TargetType: nil,
|
|
Endpoint: nil,
|
|
Timeout: gu.Ptr(0 * time.Second),
|
|
InterruptOnError: nil,
|
|
},
|
|
},
|
|
{
|
|
name: "all fields (webhook)",
|
|
args: args{&action.UpdateTargetRequest{
|
|
Name: gu.Ptr("target 1"),
|
|
Endpoint: gu.Ptr("https://example.com/hooks/1"),
|
|
TargetType: &action.UpdateTargetRequest_RestWebhook{
|
|
RestWebhook: &action.SetRESTWebhook{
|
|
InterruptOnError: false,
|
|
},
|
|
},
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
}},
|
|
want: &command.ChangeTarget{
|
|
Name: gu.Ptr("target 1"),
|
|
TargetType: gu.Ptr(domain.TargetTypeWebhook),
|
|
Endpoint: gu.Ptr("https://example.com/hooks/1"),
|
|
Timeout: gu.Ptr(10 * time.Second),
|
|
InterruptOnError: gu.Ptr(false),
|
|
},
|
|
},
|
|
{
|
|
name: "all fields (webhook interrupt)",
|
|
args: args{&action.UpdateTargetRequest{
|
|
Name: gu.Ptr("target 1"),
|
|
Endpoint: gu.Ptr("https://example.com/hooks/1"),
|
|
TargetType: &action.UpdateTargetRequest_RestWebhook{
|
|
RestWebhook: &action.SetRESTWebhook{
|
|
InterruptOnError: true,
|
|
},
|
|
},
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
}},
|
|
want: &command.ChangeTarget{
|
|
Name: gu.Ptr("target 1"),
|
|
TargetType: gu.Ptr(domain.TargetTypeWebhook),
|
|
Endpoint: gu.Ptr("https://example.com/hooks/1"),
|
|
Timeout: gu.Ptr(10 * time.Second),
|
|
InterruptOnError: gu.Ptr(true),
|
|
},
|
|
},
|
|
{
|
|
name: "all fields (async)",
|
|
args: args{&action.UpdateTargetRequest{
|
|
Name: gu.Ptr("target 1"),
|
|
Endpoint: gu.Ptr("https://example.com/hooks/1"),
|
|
TargetType: &action.UpdateTargetRequest_RestAsync{
|
|
RestAsync: &action.SetRESTAsync{},
|
|
},
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
}},
|
|
want: &command.ChangeTarget{
|
|
Name: gu.Ptr("target 1"),
|
|
TargetType: gu.Ptr(domain.TargetTypeAsync),
|
|
Endpoint: gu.Ptr("https://example.com/hooks/1"),
|
|
Timeout: gu.Ptr(10 * time.Second),
|
|
InterruptOnError: gu.Ptr(false),
|
|
},
|
|
},
|
|
{
|
|
name: "all fields (interrupting response)",
|
|
args: args{&action.UpdateTargetRequest{
|
|
Name: gu.Ptr("target 1"),
|
|
Endpoint: gu.Ptr("https://example.com/hooks/1"),
|
|
TargetType: &action.UpdateTargetRequest_RestCall{
|
|
RestCall: &action.SetRESTCall{
|
|
InterruptOnError: true,
|
|
},
|
|
},
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
}},
|
|
want: &command.ChangeTarget{
|
|
Name: gu.Ptr("target 1"),
|
|
TargetType: gu.Ptr(domain.TargetTypeCall),
|
|
Endpoint: gu.Ptr("https://example.com/hooks/1"),
|
|
Timeout: gu.Ptr(10 * time.Second),
|
|
InterruptOnError: gu.Ptr(true),
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := updateTargetToCommand(tt.args.req)
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|