mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-18 03:15:11 +00:00
feat: get/list Zitadel IdP (#12394)
# Which Problems Are Solved This PR extends the functionality of `GetProviderByID`, `ListProviders` v1 endpoints and `GetIDPByID` v2 endpoint to also return Zitadel IdP when queried. # How the Problems Are Solved - Add `PROVIDER_TYPE_ZITADEL` and a `ZitadelConfig` to `zitadel.idp.v1.ProviderConfig` (v1 APIs). - Add `IDP_TYPE_ZITADEL`, `ZitadelConfig`, `InstanceRolesInfo` in v2 `idp.proto` - Extend internal/query IDP template querying to include a `ZitadelIDPTemplate` (incl. issuer, client credentials, scopes, instance roles info). - Add/extend integration tests for updating + fetching providers by ID and listing providers. # Additional Changes N/A # Additional Context Closes https://github.com/zitadel/zitadel/issues/12051 --------- Co-authored-by: Copilot Autofix powered by AI <[email protected]>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
39ad66bded
commit
77169181a3
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/integration"
|
||||
admin_pb "github.com/zitadel/zitadel/pkg/grpc/admin"
|
||||
@@ -227,41 +228,22 @@ func Test_AddZitadelProvider(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
existingProvider, err := Instance.Client.Admin.AddZitadelProvider(AdminCTX, &admin_pb.AddZitadelProviderRequest{
|
||||
Name: "Zitadel Support IdP",
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
ClientSecret: "test-secret",
|
||||
Scopes: []string{"email", "profile"},
|
||||
ProviderOptions: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, existingProvider.GetId())
|
||||
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req *admin_pb.UpdateZitadelProviderRequest
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr error
|
||||
wantResponse *admin_pb.UpdateZitadelProviderResponse
|
||||
name string
|
||||
args args
|
||||
wantErr error
|
||||
wantResponse *admin_pb.UpdateZitadelProviderResponse
|
||||
wantUpdatedProvider *idp_pb.Provider
|
||||
}{
|
||||
{
|
||||
name: "no permissions, error",
|
||||
args: args{
|
||||
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeNoPermission),
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
ClientSecret: "test-secret",
|
||||
@@ -278,7 +260,6 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
args: args{
|
||||
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeLogin),
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Issuer: "acme.example.com",
|
||||
Scopes: []string{"email", "profile"},
|
||||
ProviderOptions: &idp_pb.Options{
|
||||
@@ -289,21 +270,11 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
},
|
||||
wantErr: status.Error(codes.PermissionDenied, "No matching permissions found (AUTH-5mWD2)"),
|
||||
},
|
||||
{
|
||||
name: "missing required field: id",
|
||||
args: args{
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{},
|
||||
},
|
||||
wantErr: status.Error(codes.InvalidArgument, "invalid UpdateZitadelProviderRequest.Id: value length must be between 1 and 200 runes, inclusive"),
|
||||
},
|
||||
{
|
||||
name: "missing required field: name",
|
||||
args: args{
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
},
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{},
|
||||
},
|
||||
wantErr: status.Error(codes.InvalidArgument, "invalid UpdateZitadelProviderRequest.Name: value length must be between 1 and 200 runes, inclusive"),
|
||||
},
|
||||
@@ -312,7 +283,6 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
args: args{
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Name: "Zitadel Support IdP updated",
|
||||
},
|
||||
},
|
||||
@@ -323,7 +293,6 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
args: args{
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Name: "Zitadel Support IdP updated",
|
||||
Issuer: "acme.example.com",
|
||||
},
|
||||
@@ -335,7 +304,6 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
args: args{
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Name: "Zitadel Support IdP updated",
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
@@ -361,22 +329,54 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
ResourceOwner: Instance.Instance.Id,
|
||||
},
|
||||
},
|
||||
wantUpdatedProvider: &idp_pb.Provider{
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: "Zitadel Support IdP updated",
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_SYSTEM,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile", "openid", "offline_access"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
{
|
||||
OrganizationId: "org2",
|
||||
OrganizationDomain: "org2.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update with scopes unset, ok",
|
||||
args: args{
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Name: "Zitadel Support IdP updated again",
|
||||
Name: "Zitadel Support IdP updated 1",
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: nil,
|
||||
Scopes: []string{},
|
||||
ProviderOptions: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsAutoCreation: false,
|
||||
},
|
||||
InstanceRolesInfo: nil,
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org3",
|
||||
OrganizationDomain: "org3.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantResponse: &admin_pb.UpdateZitadelProviderResponse{
|
||||
@@ -384,12 +384,42 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
ResourceOwner: Instance.Instance.Id,
|
||||
},
|
||||
},
|
||||
wantUpdatedProvider: &idp_pb.Provider{
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: "Zitadel Support IdP updated 1",
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_SYSTEM,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: nil, // unset scopes
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org3",
|
||||
OrganizationDomain: "org3.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// create a new provider per subtest
|
||||
existingProvider := Instance.AddZitadelProvider(AdminCTX, integration.IDPName())
|
||||
|
||||
// build request using this provider ID
|
||||
tt.args.req.Id = existingProvider.GetId()
|
||||
|
||||
before := time.Now()
|
||||
got, err := Client.UpdateZitadelProvider(tt.args.ctx, tt.args.req)
|
||||
updateResp, err := Client.UpdateZitadelProvider(tt.args.ctx, tt.args.req)
|
||||
after := time.Now()
|
||||
if tt.wantErr != nil {
|
||||
require.Error(t, err)
|
||||
@@ -400,11 +430,292 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, got)
|
||||
assert.WithinRange(t, got.GetDetails().GetChangeDate().AsTime(), before, after)
|
||||
assert.Equal(t, tt.wantResponse.GetDetails().GetResourceOwner(), got.GetDetails().GetResourceOwner())
|
||||
assert.NotNil(t, updateResp)
|
||||
assert.WithinRange(t, updateResp.GetDetails().GetChangeDate().AsTime(), before, after)
|
||||
assert.Equal(t, tt.wantResponse.GetDetails().GetResourceOwner(), updateResp.GetDetails().GetResourceOwner())
|
||||
|
||||
// todo: check if the update was actually applied by fetching the provider and checking its fields when the functionality is implemented
|
||||
// get provider by ID and assert that the updated provider matches the expected values
|
||||
getResp, err := Client.GetProviderByID(AdminCTX, &admin_pb.GetProviderByIDRequest{Id: existingProvider.GetId()})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, updateResp.GetDetails().GetChangeDate().AsTime(), getResp.GetIdp().GetDetails().GetChangeDate().AsTime())
|
||||
tt.wantUpdatedProvider.Id = existingProvider.GetId()
|
||||
assertProvider(t, tt.wantUpdatedProvider, getResp.GetIdp())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_UpdateZitadelProvider_MissingID(t *testing.T) {
|
||||
_ = Instance.AddZitadelProvider(AdminCTX, integration.IDPName())
|
||||
// Attempt to update the provider without specifying the ID
|
||||
updateResp, err := Client.UpdateZitadelProvider(AdminCTX, &admin_pb.UpdateZitadelProviderRequest{})
|
||||
require.Error(t, err)
|
||||
grpcStatus, ok := status.FromError(err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, codes.InvalidArgument, grpcStatus.Code())
|
||||
assert.Equal(t, "invalid UpdateZitadelProviderRequest.Id: value length must be between 1 and 200 runes, inclusive", grpcStatus.Message())
|
||||
require.Nil(t, updateResp)
|
||||
}
|
||||
|
||||
func Test_GetProviderByID(t *testing.T) {
|
||||
providerName := integration.IDPName()
|
||||
existingProvider := Instance.AddZitadelProvider(AdminCTX, providerName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
req *admin_pb.GetProviderByIDRequest
|
||||
wantErr error
|
||||
wantResp *admin_pb.GetProviderByIDResponse
|
||||
}{
|
||||
{
|
||||
name: "no permissions",
|
||||
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeNoPermission),
|
||||
req: &admin_pb.GetProviderByIDRequest{
|
||||
Id: "idp-id",
|
||||
},
|
||||
wantErr: status.Error(codes.NotFound, "membership not found (AUTHZ-cdgFk)"),
|
||||
},
|
||||
{
|
||||
name: "invalid ID",
|
||||
ctx: AdminCTX,
|
||||
wantErr: status.Error(codes.InvalidArgument, "invalid GetProviderByIDRequest.Id: value length must be between 1 and 200 runes, inclusive"),
|
||||
},
|
||||
{
|
||||
name: "non-existing ID",
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.GetProviderByIDRequest{
|
||||
Id: "non-existing-id",
|
||||
},
|
||||
wantErr: status.Error(codes.NotFound, "Identity Provider Configuration doesn't exist (QUERY-SAFrt)"),
|
||||
},
|
||||
{
|
||||
name: "insufficient permissions", // no iam.idp.read permissions set
|
||||
ctx: integration.WithSystemUserWithNoPermissionsAuthorization(CTX),
|
||||
req: &admin_pb.GetProviderByIDRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
},
|
||||
wantErr: status.Error(codes.PermissionDenied, "No matching permissions found (AUTH-5mWD2)"),
|
||||
},
|
||||
{
|
||||
name: "found",
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.GetProviderByIDRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
},
|
||||
wantResp: &admin_pb.GetProviderByIDResponse{
|
||||
Idp: &idp_pb.Provider{
|
||||
Id: existingProvider.GetId(),
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: providerName,
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_SYSTEM,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Client.GetProviderByID(tt.ctx, tt.req)
|
||||
if tt.wantErr != nil {
|
||||
require.Error(t, err)
|
||||
grpcStatus, ok := status.FromError(err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, status.Code(tt.wantErr), grpcStatus.Code())
|
||||
assert.Equal(t, status.Convert(tt.wantErr).Message(), grpcStatus.Message())
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, got)
|
||||
assert.Equal(t, existingProvider.GetDetails().GetCreationDate().AsTime(), got.GetIdp().GetDetails().GetCreationDate().AsTime())
|
||||
assert.Equal(t, existingProvider.GetDetails().GetResourceOwner(), got.GetIdp().GetDetails().GetResourceOwner())
|
||||
assertProvider(t, tt.wantResp.GetIdp(), got.GetIdp())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ListProviders(t *testing.T) {
|
||||
provider1Name := integration.IDPName()
|
||||
provider1 := Instance.AddZitadelProvider(AdminCTX, provider1Name)
|
||||
|
||||
provider2Name := integration.IDPName()
|
||||
provider2 := Instance.AddZitadelProvider(AdminCTX, provider2Name)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
req *admin_pb.ListProvidersRequest
|
||||
wantResp *admin_pb.ListProvidersResponse
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "no permissions",
|
||||
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeNoPermission),
|
||||
req: &admin_pb.ListProvidersRequest{},
|
||||
wantErr: status.Error(codes.NotFound, "membership not found (AUTHZ-cdgFk)"),
|
||||
},
|
||||
{
|
||||
name: "insufficient permissions", // no iam.idp.read permissions set
|
||||
ctx: integration.WithSystemUserWithNoPermissionsAuthorization(CTX),
|
||||
req: &admin_pb.ListProvidersRequest{},
|
||||
wantErr: status.Error(codes.PermissionDenied, "No matching permissions found (AUTH-5mWD2)"),
|
||||
},
|
||||
{
|
||||
name: "list by id",
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.ListProvidersRequest{
|
||||
Query: &object_pb.ListQuery{
|
||||
Asc: false,
|
||||
},
|
||||
Queries: []*admin_pb.ProviderQuery{
|
||||
{
|
||||
Query: &admin_pb.ProviderQuery_IdpIdQuery{
|
||||
IdpIdQuery: &idp_pb.IDPIDQuery{
|
||||
Id: provider2.GetId(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantResp: &admin_pb.ListProvidersResponse{
|
||||
Details: &object_pb.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*idp_pb.Provider{
|
||||
{
|
||||
Id: provider2.GetId(),
|
||||
Details: &object_pb.ObjectDetails{
|
||||
CreationDate: provider2.GetDetails().GetCreationDate(),
|
||||
ChangeDate: provider2.GetDetails().GetChangeDate(),
|
||||
ResourceOwner: provider2.GetDetails().GetResourceOwner(),
|
||||
},
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: provider2Name,
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_SYSTEM,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list by name",
|
||||
ctx: AdminCTX,
|
||||
req: &admin_pb.ListProvidersRequest{
|
||||
Query: &object_pb.ListQuery{
|
||||
Asc: false,
|
||||
},
|
||||
Queries: []*admin_pb.ProviderQuery{
|
||||
{
|
||||
Query: &admin_pb.ProviderQuery_IdpNameQuery{
|
||||
IdpNameQuery: &idp_pb.IDPNameQuery{
|
||||
Name: provider1Name,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantResp: &admin_pb.ListProvidersResponse{
|
||||
Details: &object_pb.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*idp_pb.Provider{
|
||||
{
|
||||
Id: provider1.GetId(),
|
||||
Details: &object_pb.ObjectDetails{
|
||||
CreationDate: provider1.GetDetails().GetCreationDate(),
|
||||
ChangeDate: provider1.GetDetails().GetChangeDate(),
|
||||
ResourceOwner: provider1.GetDetails().GetResourceOwner(),
|
||||
},
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: provider1Name,
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_SYSTEM,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Client.ListProviders(tt.ctx, tt.req)
|
||||
if tt.wantErr != nil {
|
||||
require.Error(t, err)
|
||||
grpcStatus, ok := status.FromError(err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, status.Code(tt.wantErr), grpcStatus.Code())
|
||||
assert.Equal(t, status.Convert(tt.wantErr).Message(), grpcStatus.Message())
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, got)
|
||||
assert.Equal(t, tt.wantResp.GetDetails().GetTotalResult(), got.GetDetails().GetTotalResult())
|
||||
for i, want := range tt.wantResp.GetResult() {
|
||||
assert.Equal(t, want.GetDetails().GetCreationDate().AsTime(), got.GetResult()[i].GetDetails().GetCreationDate().AsTime())
|
||||
assert.Equal(t, Instance.ID(), got.GetResult()[i].GetDetails().GetResourceOwner())
|
||||
assertProvider(t, want, got.GetResult()[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func assertProvider(t *testing.T, expected, actual *idp_pb.Provider) {
|
||||
assert.Equal(t, expected.GetId(), actual.GetId())
|
||||
assert.Equal(t, expected.GetState(), actual.GetState())
|
||||
assert.Equal(t, expected.GetName(), actual.GetName())
|
||||
assert.Equal(t, expected.GetOwner(), actual.GetOwner())
|
||||
assert.Equal(t, expected.GetType(), actual.GetType())
|
||||
assert.True(t, proto.Equal(expected.GetConfig(), actual.GetConfig()), "expected: %v, actual: %v", expected.GetConfig(), actual.GetConfig())
|
||||
}
|
||||
|
||||
@@ -415,6 +415,8 @@ func providerTypeToPb(idpType domain.IDPType) idp_pb.ProviderType {
|
||||
return idp_pb.ProviderType_PROVIDER_TYPE_APPLE
|
||||
case domain.IDPTypeSAML:
|
||||
return idp_pb.ProviderType_PROVIDER_TYPE_SAML
|
||||
case domain.IDPTypeZitadel:
|
||||
return idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL
|
||||
case domain.IDPTypeUnspecified:
|
||||
return idp_pb.ProviderType_PROVIDER_TYPE_UNSPECIFIED
|
||||
default:
|
||||
@@ -480,6 +482,10 @@ func configToPb(config *query.IDPTemplate) *idp_pb.ProviderConfig {
|
||||
samlConfigToPb(providerConfig, config.SAMLIDPTemplate)
|
||||
return providerConfig
|
||||
}
|
||||
if config.ZitadelIDPTemplate != nil {
|
||||
zitadelConfigToPb(providerConfig, config.ZitadelIDPTemplate)
|
||||
return providerConfig
|
||||
}
|
||||
return providerConfig
|
||||
}
|
||||
|
||||
@@ -677,6 +683,24 @@ func samlConfigToPb(providerConfig *idp_pb.ProviderConfig, template *query.SAMLI
|
||||
}
|
||||
}
|
||||
|
||||
func zitadelConfigToPb(providerConfig *idp_pb.ProviderConfig, template *query.ZitadelIDPTemplate) {
|
||||
instanceRolesInfo := make([]*idp_pb.InstanceRolesInfo, 0, len(template.InstanceRolesInfo))
|
||||
for _, role := range template.InstanceRolesInfo {
|
||||
instanceRolesInfo = append(instanceRolesInfo, &idp_pb.InstanceRolesInfo{
|
||||
OrganizationDomain: role.OrganizationDomain,
|
||||
OrganizationId: role.OrganizationID,
|
||||
})
|
||||
}
|
||||
providerConfig.Config = &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
ClientId: template.ClientID,
|
||||
Issuer: template.Issuer,
|
||||
Scopes: template.Scopes,
|
||||
InstanceRolesInfo: instanceRolesInfo,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func bindingToPb(binding string) idp_pb.SAMLBinding {
|
||||
switch binding {
|
||||
case "":
|
||||
|
||||
@@ -202,6 +202,102 @@ func TestServer_GetIDPByID(t *testing.T) {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "idp by ID, instance, Zitadel provider, ok",
|
||||
args: args{
|
||||
IamCTX,
|
||||
&idp.GetIDPByIDRequest{},
|
||||
func(ctx context.Context, request *idp.GetIDPByIDRequest) *idpAttr {
|
||||
name := integration.IDPName()
|
||||
resp := Instance.AddZitadelProvider(ctx, name)
|
||||
request.Id = resp.Id
|
||||
return &idpAttr{
|
||||
resp.GetId(),
|
||||
name,
|
||||
&object.Details{
|
||||
Sequence: resp.Details.Sequence,
|
||||
CreationDate: resp.Details.CreationDate,
|
||||
ChangeDate: resp.Details.ChangeDate,
|
||||
ResourceOwner: resp.Details.ResourceOwner,
|
||||
}}
|
||||
},
|
||||
},
|
||||
want: &idp.GetIDPByIDResponse{
|
||||
Idp: &idp.IDP{
|
||||
Details: &object.Details{
|
||||
ChangeDate: timestamppb.Now(),
|
||||
},
|
||||
State: idp.IDPState_IDP_STATE_ACTIVE,
|
||||
Type: idp.IDPType_IDP_TYPE_ZITADEL,
|
||||
Config: &idp.IDPConfig{
|
||||
Config: &idp.IDPConfig_Zitadel{
|
||||
Zitadel: &idp.ZitadelConfig{
|
||||
ClientId: "test-client",
|
||||
Issuer: "zitadel.example.com",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Options: &idp.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "idp by ID, org, Zitadel provider, ok",
|
||||
args: args{
|
||||
CTX,
|
||||
&idp.GetIDPByIDRequest{},
|
||||
func(ctx context.Context, request *idp.GetIDPByIDRequest) *idpAttr {
|
||||
name := integration.IDPName()
|
||||
resp := Instance.AddOrgZitadelProvider(ctx, name)
|
||||
request.Id = resp.Id
|
||||
return &idpAttr{
|
||||
resp.GetId(),
|
||||
name,
|
||||
&object.Details{
|
||||
Sequence: resp.Details.Sequence,
|
||||
CreationDate: resp.Details.CreationDate,
|
||||
ChangeDate: resp.Details.ChangeDate,
|
||||
ResourceOwner: resp.Details.ResourceOwner,
|
||||
}}
|
||||
},
|
||||
},
|
||||
want: &idp.GetIDPByIDResponse{
|
||||
Idp: &idp.IDP{
|
||||
Details: &object.Details{
|
||||
ChangeDate: timestamppb.Now(),
|
||||
},
|
||||
State: idp.IDPState_IDP_STATE_ACTIVE,
|
||||
Type: idp.IDPType_IDP_TYPE_ZITADEL,
|
||||
Config: &idp.IDPConfig{
|
||||
Config: &idp.IDPConfig_Zitadel{
|
||||
Zitadel: &idp.ZitadelConfig{
|
||||
ClientId: "test-client",
|
||||
Issuer: "zitadel.example.com",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Options: &idp.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
@@ -85,6 +85,8 @@ func idpTypeToPb(idpType domain.IDPType) idp_pb.IDPType {
|
||||
return idp_pb.IDPType_IDP_TYPE_APPLE
|
||||
case domain.IDPTypeSAML:
|
||||
return idp_pb.IDPType_IDP_TYPE_SAML
|
||||
case domain.IDPTypeZitadel:
|
||||
return idp_pb.IDPType_IDP_TYPE_ZITADEL
|
||||
case domain.IDPTypeUnspecified:
|
||||
return idp_pb.IDPType_IDP_TYPE_UNSPECIFIED
|
||||
default:
|
||||
@@ -150,6 +152,10 @@ func configToPb(config *query.IDPTemplate) *idp_pb.IDPConfig {
|
||||
samlConfigToPb(idpConfig, config.SAMLIDPTemplate)
|
||||
return idpConfig
|
||||
}
|
||||
if config.ZitadelIDPTemplate != nil {
|
||||
zitadelConfigToPb(idpConfig, config.ZitadelIDPTemplate)
|
||||
return idpConfig
|
||||
}
|
||||
return idpConfig
|
||||
}
|
||||
|
||||
@@ -387,3 +393,21 @@ func signatureAlgorithmToPb(signatureAlgorithm string) idp_pb.SAMLSignatureAlgor
|
||||
return idp_pb.SAMLSignatureAlgorithm_SAML_SIGNATURE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func zitadelConfigToPb(idpConfig *idp_pb.IDPConfig, template *query.ZitadelIDPTemplate) {
|
||||
instanceRolesInfo := make([]*idp_pb.InstanceRolesInfo, 0, len(template.InstanceRolesInfo))
|
||||
for _, role := range template.InstanceRolesInfo {
|
||||
instanceRolesInfo = append(instanceRolesInfo, &idp_pb.InstanceRolesInfo{
|
||||
OrganizationId: role.OrganizationID,
|
||||
OrganizationDomain: role.OrganizationDomain,
|
||||
})
|
||||
}
|
||||
idpConfig.Config = &idp_pb.IDPConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
ClientId: template.ClientID,
|
||||
Issuer: template.Issuer,
|
||||
Scopes: template.Scopes,
|
||||
InstanceRolesInfo: instanceRolesInfo,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/integration"
|
||||
idp_pb "github.com/zitadel/zitadel/pkg/grpc/idp"
|
||||
@@ -233,41 +234,22 @@ func Test_AddZitadelProvider(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
existingProvider, err := Instance.Client.Mgmt.AddZitadelProvider(OrgCTX, &mgmt_pb.AddZitadelProviderRequest{
|
||||
Name: "Zitadel Support IdP",
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
ClientSecret: "test-secret",
|
||||
Scopes: []string{"email", "profile"},
|
||||
ProviderOptions: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, existingProvider.GetId())
|
||||
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req *mgmt_pb.UpdateZitadelProviderRequest
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr error
|
||||
wantResponse *mgmt_pb.UpdateZitadelProviderResponse
|
||||
name string
|
||||
args args
|
||||
wantErr error
|
||||
wantResponse *mgmt_pb.UpdateZitadelProviderResponse
|
||||
wantUpdatedProvider *idp_pb.Provider
|
||||
}{
|
||||
{
|
||||
name: "no permissions, error",
|
||||
args: args{
|
||||
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeNoPermission),
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
ClientSecret: "test-secret",
|
||||
@@ -284,7 +266,6 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
args: args{
|
||||
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeLogin),
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Issuer: "acme.example.com",
|
||||
Scopes: []string{"email", "profile"},
|
||||
ProviderOptions: &idp_pb.Options{
|
||||
@@ -295,21 +276,11 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
},
|
||||
wantErr: status.Error(codes.PermissionDenied, "No matching permissions found (AUTH-5mWD2)"),
|
||||
},
|
||||
{
|
||||
name: "missing required field: id",
|
||||
args: args{
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{},
|
||||
},
|
||||
wantErr: status.Error(codes.InvalidArgument, "invalid UpdateZitadelProviderRequest.Id: value length must be between 1 and 200 runes, inclusive"),
|
||||
},
|
||||
{
|
||||
name: "missing required field: name",
|
||||
args: args{
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
},
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{},
|
||||
},
|
||||
wantErr: status.Error(codes.InvalidArgument, "invalid UpdateZitadelProviderRequest.Name: value length must be between 1 and 200 runes, inclusive"),
|
||||
},
|
||||
@@ -318,7 +289,6 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
args: args{
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Name: "Zitadel Support IdP updated",
|
||||
},
|
||||
},
|
||||
@@ -329,7 +299,6 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
args: args{
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Name: "Zitadel Support IdP updated",
|
||||
Issuer: "acme.example.com",
|
||||
},
|
||||
@@ -341,15 +310,10 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
args: args{
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Name: "Zitadel Support IdP updated",
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile", "openid", "offline_access"},
|
||||
ProviderOptions: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsAutoCreation: false,
|
||||
},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
@@ -367,22 +331,51 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
ResourceOwner: Instance.DefaultOrg.Id,
|
||||
},
|
||||
},
|
||||
wantUpdatedProvider: &idp_pb.Provider{
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: "Zitadel Support IdP updated",
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_ORG,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile", "openid", "offline_access"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
{
|
||||
OrganizationId: "org2",
|
||||
OrganizationDomain: "org2.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update with scopes unset, ok",
|
||||
args: args{
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
Name: "Zitadel Support IdP updated again",
|
||||
Name: "Zitadel Support IdP updated 1",
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{},
|
||||
Scopes: []string{}, // scopes unset -> will be updated by the API
|
||||
ProviderOptions: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsAutoCreation: false,
|
||||
IsAutoCreation: true,
|
||||
},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org3",
|
||||
OrganizationDomain: "org3.com",
|
||||
},
|
||||
},
|
||||
InstanceRolesInfo: nil,
|
||||
},
|
||||
},
|
||||
wantResponse: &mgmt_pb.UpdateZitadelProviderResponse{
|
||||
@@ -390,12 +383,80 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
ResourceOwner: Instance.DefaultOrg.Id,
|
||||
},
|
||||
},
|
||||
wantUpdatedProvider: &idp_pb.Provider{
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: "Zitadel Support IdP updated 1",
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_ORG,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsAutoCreation: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: nil, // unset scopes
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org3",
|
||||
OrganizationDomain: "org3.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update with instance roles info not set, ok",
|
||||
args: args{
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.UpdateZitadelProviderRequest{
|
||||
Name: "Zitadel Support IdP updated 2",
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "openid"},
|
||||
ProviderOptions: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
InstanceRolesInfo: nil, // instance roles info isn't set -> will be unset by the API
|
||||
},
|
||||
},
|
||||
wantResponse: &mgmt_pb.UpdateZitadelProviderResponse{
|
||||
Details: &object_pb.ObjectDetails{
|
||||
ResourceOwner: Instance.DefaultOrg.Id,
|
||||
},
|
||||
},
|
||||
wantUpdatedProvider: &idp_pb.Provider{
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: "Zitadel Support IdP updated 2",
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_ORG,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "acme.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "openid"},
|
||||
InstanceRolesInfo: nil, // instance roles info isn't set
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// create a new provider per subtest and set the ID in the request
|
||||
zitadelProvider := Instance.AddOrgZitadelProvider(OrgCTX, integration.IDPName())
|
||||
tt.args.req.Id = zitadelProvider.Id
|
||||
|
||||
before := time.Now()
|
||||
got, err := Client.UpdateZitadelProvider(tt.args.ctx, tt.args.req)
|
||||
updateResp, err := Client.UpdateZitadelProvider(tt.args.ctx, tt.args.req)
|
||||
after := time.Now()
|
||||
if tt.wantErr != nil {
|
||||
require.Error(t, err)
|
||||
@@ -406,11 +467,371 @@ func Test_UpdateZitadelProvider(t *testing.T) {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, got)
|
||||
assert.WithinRange(t, got.GetDetails().GetChangeDate().AsTime(), before, after)
|
||||
assert.Equal(t, tt.wantResponse.GetDetails().GetResourceOwner(), got.GetDetails().GetResourceOwner())
|
||||
assert.NotNil(t, updateResp)
|
||||
assert.WithinRange(t, updateResp.GetDetails().GetChangeDate().AsTime(), before, after)
|
||||
assert.Equal(t, tt.wantResponse.GetDetails().GetResourceOwner(), updateResp.GetDetails().GetResourceOwner())
|
||||
|
||||
// todo: check if the update was actually applied by fetching the provider and checking its fields when the functionality is implemented
|
||||
// get provider by ID and assert that the updated provider matches the expected values
|
||||
getResp, err := Client.GetProviderByID(OrgCTX, &mgmt_pb.GetProviderByIDRequest{Id: zitadelProvider.Id})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, updateResp.GetDetails().GetChangeDate().AsTime(), getResp.GetIdp().GetDetails().GetChangeDate().AsTime())
|
||||
tt.wantUpdatedProvider.Id = zitadelProvider.Id
|
||||
assertProvider(t, tt.wantUpdatedProvider, getResp.GetIdp())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_UpdateZitadelProvider_MissingID(t *testing.T) {
|
||||
_ = Instance.AddOrgZitadelProvider(OrgCTX, integration.IDPName())
|
||||
// Attempt to update the provider without specifying the ID
|
||||
updateResp, err := Client.UpdateZitadelProvider(OrgCTX, &mgmt_pb.UpdateZitadelProviderRequest{})
|
||||
require.Error(t, err)
|
||||
grpcStatus, ok := status.FromError(err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, codes.InvalidArgument, grpcStatus.Code())
|
||||
assert.Equal(t, "invalid UpdateZitadelProviderRequest.Id: value length must be between 1 and 200 runes, inclusive", grpcStatus.Message())
|
||||
require.Nil(t, updateResp)
|
||||
}
|
||||
|
||||
func Test_GetProviderByID(t *testing.T) {
|
||||
name := integration.IDPName()
|
||||
existingProvider := Instance.AddOrgZitadelProvider(OrgCTX, name)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
req *mgmt_pb.GetProviderByIDRequest
|
||||
wantErr error
|
||||
wantResp *mgmt_pb.GetProviderByIDResponse
|
||||
}{
|
||||
{
|
||||
name: "no permissions",
|
||||
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeNoPermission),
|
||||
req: &mgmt_pb.GetProviderByIDRequest{
|
||||
Id: "idp-id",
|
||||
},
|
||||
wantErr: status.Error(codes.NotFound, "membership not found (AUTHZ-cdgFk)"),
|
||||
},
|
||||
{
|
||||
name: "invalid ID",
|
||||
ctx: OrgCTX,
|
||||
wantErr: status.Error(codes.InvalidArgument, "invalid GetProviderByIDRequest.Id: value length must be between 1 and 200 runes, inclusive"),
|
||||
},
|
||||
{
|
||||
name: "non-existing ID",
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.GetProviderByIDRequest{
|
||||
Id: "non-existing-id",
|
||||
},
|
||||
wantErr: status.Error(codes.NotFound, "Identity Provider Configuration doesn't exist (QUERY-SAFrt)"),
|
||||
},
|
||||
{
|
||||
name: "insufficient permissions", // no org.idp.read permissions set
|
||||
ctx: integration.WithSystemUserWithNoPermissionsAuthorization(CTX),
|
||||
req: &mgmt_pb.GetProviderByIDRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
},
|
||||
wantErr: status.Error(codes.PermissionDenied, "No matching permissions found (AUTH-5mWD2)"),
|
||||
},
|
||||
{
|
||||
name: "found",
|
||||
ctx: OrgCTX,
|
||||
req: &mgmt_pb.GetProviderByIDRequest{
|
||||
Id: existingProvider.GetId(),
|
||||
},
|
||||
wantResp: &mgmt_pb.GetProviderByIDResponse{
|
||||
Idp: &idp_pb.Provider{
|
||||
Id: existingProvider.GetId(),
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: name,
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_ORG,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Client.GetProviderByID(tt.ctx, tt.req)
|
||||
if tt.wantErr != nil {
|
||||
require.Error(t, err)
|
||||
grpcStatus, ok := status.FromError(err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, status.Code(tt.wantErr), grpcStatus.Code())
|
||||
assert.Equal(t, status.Convert(tt.wantErr).Message(), grpcStatus.Message())
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, got)
|
||||
assert.Equal(t, existingProvider.GetDetails().GetCreationDate().AsTime(), got.GetIdp().GetDetails().GetCreationDate().AsTime())
|
||||
assert.Equal(t, existingProvider.GetDetails().GetResourceOwner(), got.GetIdp().GetDetails().GetResourceOwner())
|
||||
assertProvider(t, tt.wantResp.GetIdp(), got.GetIdp())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ListProviders(t *testing.T) {
|
||||
org := Instance.CreateOrganization(IAMOwnerCTX, integration.OrganizationName(), integration.Email())
|
||||
require.NotEmpty(t, org.GetOrganizationId())
|
||||
orgCtx := integration.SetOrgID(IAMOwnerCTX, org.GetOrganizationId())
|
||||
|
||||
provider1Name := integration.IDPName()
|
||||
provider1 := Instance.AddOrgZitadelProvider(orgCtx, provider1Name)
|
||||
provider2Name := integration.IDPName()
|
||||
provider2 := Instance.AddOrgZitadelProvider(orgCtx, provider2Name)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
req *mgmt_pb.ListProvidersRequest
|
||||
wantResp *mgmt_pb.ListProvidersResponse
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "no permissions",
|
||||
ctx: Instance.WithAuthorizationToken(CTX, integration.UserTypeNoPermission),
|
||||
req: &mgmt_pb.ListProvidersRequest{},
|
||||
wantErr: status.Error(codes.NotFound, "membership not found (AUTHZ-cdgFk)"),
|
||||
},
|
||||
{
|
||||
name: "insufficient permissions", // no iam.idp.read permissions set
|
||||
ctx: integration.WithSystemUserWithNoPermissionsAuthorization(CTX),
|
||||
req: &mgmt_pb.ListProvidersRequest{},
|
||||
wantErr: status.Error(codes.PermissionDenied, "No matching permissions found (AUTH-5mWD2)"),
|
||||
},
|
||||
{
|
||||
name: "list by id",
|
||||
ctx: orgCtx,
|
||||
req: &mgmt_pb.ListProvidersRequest{
|
||||
Query: &object_pb.ListQuery{
|
||||
Asc: false,
|
||||
},
|
||||
Queries: []*mgmt_pb.ProviderQuery{
|
||||
{
|
||||
Query: &mgmt_pb.ProviderQuery_IdpIdQuery{
|
||||
IdpIdQuery: &idp_pb.IDPIDQuery{
|
||||
Id: provider2.GetId(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantResp: &mgmt_pb.ListProvidersResponse{
|
||||
Details: &object_pb.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*idp_pb.Provider{
|
||||
{
|
||||
Id: provider2.GetId(),
|
||||
Details: &object_pb.ObjectDetails{
|
||||
CreationDate: provider2.GetDetails().GetCreationDate(),
|
||||
ChangeDate: provider2.GetDetails().GetChangeDate(),
|
||||
ResourceOwner: provider2.GetDetails().GetResourceOwner(),
|
||||
},
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: provider2Name,
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_ORG,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list by name",
|
||||
ctx: orgCtx,
|
||||
req: &mgmt_pb.ListProvidersRequest{
|
||||
Query: &object_pb.ListQuery{
|
||||
Asc: false,
|
||||
},
|
||||
Queries: []*mgmt_pb.ProviderQuery{
|
||||
{
|
||||
Query: &mgmt_pb.ProviderQuery_IdpNameQuery{
|
||||
IdpNameQuery: &idp_pb.IDPNameQuery{
|
||||
Name: provider1Name,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantResp: &mgmt_pb.ListProvidersResponse{
|
||||
Details: &object_pb.ListDetails{
|
||||
TotalResult: 1,
|
||||
},
|
||||
Result: []*idp_pb.Provider{
|
||||
{
|
||||
Id: provider1.GetId(),
|
||||
Details: &object_pb.ObjectDetails{
|
||||
CreationDate: provider1.GetDetails().GetCreationDate(),
|
||||
ChangeDate: provider1.GetDetails().GetChangeDate(),
|
||||
ResourceOwner: provider1.GetDetails().GetResourceOwner(),
|
||||
},
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: provider1Name,
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_ORG,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list all providers",
|
||||
ctx: orgCtx,
|
||||
req: &mgmt_pb.ListProvidersRequest{
|
||||
Query: &object_pb.ListQuery{
|
||||
Asc: true,
|
||||
},
|
||||
},
|
||||
wantResp: &mgmt_pb.ListProvidersResponse{
|
||||
Details: &object_pb.ListDetails{
|
||||
TotalResult: 2,
|
||||
},
|
||||
Result: []*idp_pb.Provider{
|
||||
{
|
||||
Id: provider1.GetId(),
|
||||
Details: &object_pb.ObjectDetails{
|
||||
CreationDate: provider1.GetDetails().GetCreationDate(),
|
||||
ChangeDate: provider1.GetDetails().GetChangeDate(),
|
||||
ResourceOwner: provider1.GetDetails().GetResourceOwner(),
|
||||
},
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: provider1Name,
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_ORG,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: provider2.GetId(),
|
||||
Details: &object_pb.ObjectDetails{
|
||||
CreationDate: provider2.GetDetails().GetCreationDate(),
|
||||
ChangeDate: provider2.GetDetails().GetChangeDate(),
|
||||
ResourceOwner: provider2.GetDetails().GetResourceOwner(),
|
||||
},
|
||||
State: idp_pb.IDPState_IDP_STATE_ACTIVE,
|
||||
Name: provider2Name,
|
||||
Owner: idp_pb.IDPOwnerType_IDP_OWNER_TYPE_ORG,
|
||||
Type: idp_pb.ProviderType_PROVIDER_TYPE_ZITADEL,
|
||||
Config: &idp_pb.ProviderConfig{
|
||||
Options: &idp_pb.Options{
|
||||
IsCreationAllowed: true,
|
||||
},
|
||||
Config: &idp_pb.ProviderConfig_Zitadel{
|
||||
Zitadel: &idp_pb.ZitadelConfig{
|
||||
Issuer: "zitadel.example.com",
|
||||
ClientId: "test-client",
|
||||
Scopes: []string{"email", "profile"},
|
||||
InstanceRolesInfo: []*idp_pb.InstanceRolesInfo{
|
||||
{
|
||||
OrganizationId: "org1",
|
||||
OrganizationDomain: "org1.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Client.ListProviders(tt.ctx, tt.req)
|
||||
if tt.wantErr != nil {
|
||||
require.Error(t, err)
|
||||
grpcStatus, ok := status.FromError(err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, status.Code(tt.wantErr), grpcStatus.Code())
|
||||
assert.Equal(t, status.Convert(tt.wantErr).Message(), grpcStatus.Message())
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, got)
|
||||
assert.Equal(t, tt.wantResp.GetDetails().GetTotalResult(), got.GetDetails().GetTotalResult())
|
||||
for i, want := range tt.wantResp.GetResult() {
|
||||
assert.Equal(t, want.GetDetails().GetCreationDate().AsTime(), got.GetResult()[i].GetDetails().GetCreationDate().AsTime())
|
||||
assert.Equal(t, org.GetOrganizationId(), got.GetResult()[i].GetDetails().GetResourceOwner())
|
||||
assertProvider(t, want, got.GetResult()[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func assertProvider(t *testing.T, expected, actual *idp_pb.Provider) {
|
||||
assert.Equal(t, expected.GetId(), actual.GetId())
|
||||
assert.Equal(t, expected.GetState(), actual.GetState())
|
||||
assert.Equal(t, expected.GetName(), actual.GetName())
|
||||
assert.Equal(t, expected.GetOwner(), actual.GetOwner())
|
||||
assert.Equal(t, expected.GetType(), actual.GetType())
|
||||
assert.True(t, proto.Equal(expected.GetConfig(), actual.GetConfig()), "expected: %v, actual: %v", expected.GetConfig(), actual.GetConfig())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user