mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
6398349c24
* add token exchange feature flag * allow setting reason and actor to access tokens * impersonation * set token types and scopes in response * upgrade oidc to working draft state * fix tests * audience and scope validation * id toke and jwt as input * return id tokens * add grant type token exchange to app config * add integration tests * check and deny actors in api calls * fix instance setting tests by triggering projection on write and cleanup * insert sleep statements again * solve linting issues * add translations * pin oidc v3.15.0 * resolve comments, add event translation * fix refreshtoken test * use ValidateAuthReqScopes from oidc * apparently the linter can't make up its mind * persist actor thru refresh tokens and check in tests * remove unneeded triggers
172 lines
4.3 KiB
Go
172 lines
4.3 KiB
Go
//go:build integration
|
|
|
|
package admin_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
|
admin_pb "github.com/zitadel/zitadel/pkg/grpc/admin"
|
|
"github.com/zitadel/zitadel/pkg/grpc/object"
|
|
"github.com/zitadel/zitadel/pkg/grpc/settings"
|
|
)
|
|
|
|
func TestServer_GetSecurityPolicy(t *testing.T) {
|
|
_, err := Client.SetSecurityPolicy(AdminCTX, &admin_pb.SetSecurityPolicyRequest{
|
|
EnableIframeEmbedding: true,
|
|
AllowedOrigins: []string{"foo.com", "bar.com"},
|
|
EnableImpersonation: true,
|
|
})
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
_, err := Client.SetSecurityPolicy(AdminCTX, &admin_pb.SetSecurityPolicyRequest{
|
|
EnableIframeEmbedding: false,
|
|
AllowedOrigins: []string{},
|
|
EnableImpersonation: false,
|
|
})
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
tests := []struct {
|
|
name string
|
|
ctx context.Context
|
|
want *admin_pb.GetSecurityPolicyResponse
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "permission error",
|
|
ctx: Tester.WithAuthorization(CTX, integration.OrgOwner),
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "success",
|
|
ctx: AdminCTX,
|
|
want: &admin_pb.GetSecurityPolicyResponse{
|
|
Policy: &settings.SecurityPolicy{
|
|
EnableIframeEmbedding: true,
|
|
AllowedOrigins: []string{"foo.com", "bar.com"},
|
|
EnableImpersonation: true,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
resp, err := Client.GetSecurityPolicy(tt.ctx, &admin_pb.GetSecurityPolicyRequest{})
|
|
if tt.wantErr {
|
|
assert.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
got, want := resp.GetPolicy(), tt.want.GetPolicy()
|
|
assert.Equal(t, want.GetEnableIframeEmbedding(), got.GetEnableIframeEmbedding(), "enable iframe embedding")
|
|
assert.Equal(t, want.GetAllowedOrigins(), got.GetAllowedOrigins(), "allowed origins")
|
|
assert.Equal(t, want.GetEnableImpersonation(), got.GetEnableImpersonation(), "enable impersonation")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServer_SetSecurityPolicy(t *testing.T) {
|
|
type args struct {
|
|
ctx context.Context
|
|
req *admin_pb.SetSecurityPolicyRequest
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *admin_pb.SetSecurityPolicyResponse
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "permission error",
|
|
args: args{
|
|
ctx: Tester.WithAuthorization(CTX, integration.OrgOwner),
|
|
req: &admin_pb.SetSecurityPolicyRequest{
|
|
EnableIframeEmbedding: true,
|
|
AllowedOrigins: []string{"foo.com", "bar.com"},
|
|
EnableImpersonation: true,
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "success allowed origins",
|
|
args: args{
|
|
ctx: AdminCTX,
|
|
req: &admin_pb.SetSecurityPolicyRequest{
|
|
AllowedOrigins: []string{"foo.com", "bar.com"},
|
|
},
|
|
},
|
|
want: &admin_pb.SetSecurityPolicyResponse{
|
|
Details: &object.ObjectDetails{
|
|
ChangeDate: timestamppb.Now(),
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "success iframe embedding",
|
|
args: args{
|
|
ctx: AdminCTX,
|
|
req: &admin_pb.SetSecurityPolicyRequest{
|
|
EnableIframeEmbedding: true,
|
|
},
|
|
},
|
|
want: &admin_pb.SetSecurityPolicyResponse{
|
|
Details: &object.ObjectDetails{
|
|
ChangeDate: timestamppb.Now(),
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "success impersonation",
|
|
args: args{
|
|
ctx: AdminCTX,
|
|
req: &admin_pb.SetSecurityPolicyRequest{
|
|
EnableImpersonation: true,
|
|
},
|
|
},
|
|
want: &admin_pb.SetSecurityPolicyResponse{
|
|
Details: &object.ObjectDetails{
|
|
ChangeDate: timestamppb.Now(),
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "success all",
|
|
args: args{
|
|
ctx: AdminCTX,
|
|
req: &admin_pb.SetSecurityPolicyRequest{
|
|
EnableIframeEmbedding: true,
|
|
AllowedOrigins: []string{"foo.com", "bar.com"},
|
|
EnableImpersonation: true,
|
|
},
|
|
},
|
|
want: &admin_pb.SetSecurityPolicyResponse{
|
|
Details: &object.ObjectDetails{
|
|
ChangeDate: timestamppb.Now(),
|
|
ResourceOwner: Tester.Instance.InstanceID(),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := Client.SetSecurityPolicy(tt.args.ctx, tt.args.req)
|
|
if tt.wantErr {
|
|
assert.Error(t, err)
|
|
return
|
|
}
|
|
require.NoError(t, err)
|
|
integration.AssertDetails(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|