2024-02-28 10:21:11 +00:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package settings_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2024-09-06 12:47:57 +00:00
|
|
|
"time"
|
2024-02-28 10:21:11 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2024-07-26 20:39:55 +00:00
|
|
|
object_pb "github.com/zitadel/zitadel/pkg/grpc/object/v2"
|
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/settings/v2"
|
2024-02-28 10:21:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer_GetSecuritySettings(t *testing.T) {
|
|
|
|
_, err := Client.SetSecuritySettings(AdminCTX, &settings.SetSecuritySettingsRequest{
|
|
|
|
EmbeddedIframe: &settings.EmbeddedIframeSettings{
|
|
|
|
Enabled: true,
|
|
|
|
AllowedOrigins: []string{"foo", "bar"},
|
|
|
|
},
|
|
|
|
EnableImpersonation: true,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
ctx context.Context
|
|
|
|
want *settings.GetSecuritySettingsResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "permission error",
|
2024-09-06 12:47:57 +00:00
|
|
|
ctx: Instance.WithAuthorization(CTX, integration.UserTypeOrgOwner),
|
2024-02-28 10:21:11 +00:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success",
|
|
|
|
ctx: AdminCTX,
|
|
|
|
want: &settings.GetSecuritySettingsResponse{
|
|
|
|
Settings: &settings.SecuritySettings{
|
|
|
|
EmbeddedIframe: &settings.EmbeddedIframeSettings{
|
|
|
|
Enabled: true,
|
|
|
|
AllowedOrigins: []string{"foo", "bar"},
|
|
|
|
},
|
|
|
|
EnableImpersonation: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2024-10-21 19:15:02 +00:00
|
|
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(tt.ctx, time.Minute)
|
2024-09-06 12:47:57 +00:00
|
|
|
assert.EventuallyWithT(t, func(ct *assert.CollectT) {
|
|
|
|
resp, err := Client.GetSecuritySettings(tt.ctx, &settings.GetSecuritySettingsRequest{})
|
|
|
|
if tt.wantErr {
|
2024-10-21 19:15:02 +00:00
|
|
|
assert.Error(ct, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !assert.NoError(ct, err) {
|
2024-09-06 12:47:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
got, want := resp.GetSettings(), tt.want.GetSettings()
|
|
|
|
assert.Equal(ct, want.GetEmbeddedIframe().GetEnabled(), got.GetEmbeddedIframe().GetEnabled(), "enable iframe embedding")
|
|
|
|
assert.Equal(ct, want.GetEmbeddedIframe().GetAllowedOrigins(), got.GetEmbeddedIframe().GetAllowedOrigins(), "allowed origins")
|
|
|
|
assert.Equal(ct, want.GetEnableImpersonation(), got.GetEnableImpersonation(), "enable impersonation")
|
2024-10-17 21:20:57 +00:00
|
|
|
}, retryDuration, tick)
|
2024-02-28 10:21:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_SetSecuritySettings(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *settings.SetSecuritySettingsRequest
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *settings.SetSecuritySettingsResponse
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "permission error",
|
|
|
|
args: args{
|
2024-09-06 12:47:57 +00:00
|
|
|
ctx: Instance.WithAuthorization(CTX, integration.UserTypeOrgOwner),
|
2024-02-28 10:21:11 +00:00
|
|
|
req: &settings.SetSecuritySettingsRequest{
|
|
|
|
EmbeddedIframe: &settings.EmbeddedIframeSettings{
|
|
|
|
Enabled: true,
|
|
|
|
AllowedOrigins: []string{"foo.com", "bar.com"},
|
|
|
|
},
|
|
|
|
EnableImpersonation: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success allowed origins",
|
|
|
|
args: args{
|
|
|
|
ctx: AdminCTX,
|
|
|
|
req: &settings.SetSecuritySettingsRequest{
|
|
|
|
EmbeddedIframe: &settings.EmbeddedIframeSettings{
|
|
|
|
AllowedOrigins: []string{"foo.com", "bar.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &settings.SetSecuritySettingsResponse{
|
|
|
|
Details: &object_pb.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.ID(),
|
2024-02-28 10:21:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success enable iframe embedding",
|
|
|
|
args: args{
|
|
|
|
ctx: AdminCTX,
|
|
|
|
req: &settings.SetSecuritySettingsRequest{
|
|
|
|
EmbeddedIframe: &settings.EmbeddedIframeSettings{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &settings.SetSecuritySettingsResponse{
|
|
|
|
Details: &object_pb.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.ID(),
|
2024-02-28 10:21:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success impersonation",
|
|
|
|
args: args{
|
|
|
|
ctx: AdminCTX,
|
|
|
|
req: &settings.SetSecuritySettingsRequest{
|
|
|
|
EnableImpersonation: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &settings.SetSecuritySettingsResponse{
|
|
|
|
Details: &object_pb.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.ID(),
|
2024-02-28 10:21:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success all",
|
|
|
|
args: args{
|
|
|
|
ctx: AdminCTX,
|
|
|
|
req: &settings.SetSecuritySettingsRequest{
|
|
|
|
EmbeddedIframe: &settings.EmbeddedIframeSettings{
|
|
|
|
Enabled: true,
|
|
|
|
AllowedOrigins: []string{"foo.com", "bar.com"},
|
|
|
|
},
|
|
|
|
EnableImpersonation: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: &settings.SetSecuritySettingsResponse{
|
|
|
|
Details: &object_pb.Details{
|
|
|
|
ChangeDate: timestamppb.Now(),
|
2024-09-06 12:47:57 +00:00
|
|
|
ResourceOwner: Instance.ID(),
|
2024-02-28 10:21:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := Client.SetSecuritySettings(tt.args.ctx, tt.args.req)
|
|
|
|
if tt.wantErr {
|
2024-10-17 21:20:57 +00:00
|
|
|
require.Error(t, err)
|
2024-02-28 10:21:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
integration.AssertDetails(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|