mirror of
https://github.com/zitadel/zitadel.git
synced 2025-07-15 18:19:00 +00:00

This PR summarizes multiple changes specifically only available with ZITADEL v3: - feat: Web Keys management (https://github.com/zitadel/zitadel/pull/9526) - fix(cmd): ensure proper working of mirror (https://github.com/zitadel/zitadel/pull/9509) - feat(Authz): system user support for permission check v2 (https://github.com/zitadel/zitadel/pull/9640) - chore(license): change from Apache to AGPL (https://github.com/zitadel/zitadel/pull/9597) - feat(console): list v2 sessions (https://github.com/zitadel/zitadel/pull/9539) - fix(console): add loginV2 feature flag (https://github.com/zitadel/zitadel/pull/9682) - fix(feature flags): allow reading "own" flags (https://github.com/zitadel/zitadel/pull/9649) - feat(console): add Actions V2 UI (https://github.com/zitadel/zitadel/pull/9591) BREAKING CHANGE - feat(webkey): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9445) - chore!: remove CockroachDB Support (https://github.com/zitadel/zitadel/pull/9444) - feat(actions): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9489) --------- Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com> Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com> Co-authored-by: Ramon <mail@conblem.me> Co-authored-by: Elio Bischof <elio@zitadel.com> Co-authored-by: Kenta Yamaguchi <56732734+KEY60228@users.noreply.github.com> Co-authored-by: Harsha Reddy <harsha.reddy@klaviyo.com> Co-authored-by: Livio Spring <livio@zitadel.com> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Iraq <66622793+kkrime@users.noreply.github.com> Co-authored-by: Florian Forster <florian@zitadel.com> Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Max Peintner <peintnerm@gmail.com>
230 lines
6.0 KiB
Go
230 lines
6.0 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/v2beta"
|
|
)
|
|
|
|
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.RESTWebhook{},
|
|
},
|
|
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.RESTAsync{},
|
|
},
|
|
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.RESTCall{
|
|
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.RESTWebhook{
|
|
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.RESTWebhook{
|
|
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.RESTAsync{},
|
|
},
|
|
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.RESTCall{
|
|
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)
|
|
})
|
|
}
|
|
}
|