mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-02 14:12:27 +00:00
# Which Problems Are Solved As part of our efforts to simplify the structure and versions of our APIs, were moving all existing v2beta endpoints to v2 and deprecate them. They will be removed in Zitadel V5. # How the Problems Are Solved - This PR moves app v2beta service and its endpoints to a corresponding to application v2 version. The v2beta service and endpoints are deprecated. - The comments and have been improved and, where not already done, moved from swagger annotations to proto. - All required fields have been marked with (google.api.field_behavior) = REQUIRED and validation rules have been added where missing. - Name ID of the application always `application_id`, previously was also `id` and `app_id`. - Get rid of all `app` abbreviations and name it `application` including the service name, `AppState` -> `ApplicationState` and `AppSorting` -> `ApplicationSorting` - Updated `CreateApplicationRequest`: - renamed `creation_request_type` to `application_type` and all its options to `XY_configuration` instead of `XY_request` - `RegenerateClientSecret` - renamed method to `GenerateClientSecret` - removed `app_type` from request - `ListApplicationRequest`: - removed required `project_id` and provided it as a filter - Type `ApplicationNameQuery` has been renamed to `ApplicationNameFilter` as its usage in the request - Renamed all fields and types from `config` to `configuration` - Updated `DeleteApplicationKeyRequest` - removed `organization_id` - Updated `GetApplicationKeyRequest`: - removed `project_id`, `application_id` and `organization_id`` - Updated `ListApplicationKeysRequest`: - removed oneOf `resource_id` and moved the options into filters - Name ID of the application key always `key_id`. - removed unnecessary package prefixed (`zitadel.application.v2`) - formatted using `buf` # Additional Changes None # Additional Context - part of https://github.com/zitadel/zitadel/issues/10772 - requires backport to v4.x
254 lines
6.6 KiB
Go
254 lines
6.6 KiB
Go
package convert
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/muhlemmer/gu"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
"github.com/zitadel/zitadel/internal/integration"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
"github.com/zitadel/zitadel/pkg/grpc/application/v2"
|
|
)
|
|
|
|
func samlMetadataGen(entityID string) []byte {
|
|
str := fmt.Sprintf(`<?xml version="1.0"?>
|
|
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
|
|
validUntil="2022-08-26T14:08:16Z"
|
|
cacheDuration="PT604800S"
|
|
entityID="%s">
|
|
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
|
|
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
|
|
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
|
|
Location="https://test.com/saml/acs"
|
|
index="1" />
|
|
|
|
</md:SPSSODescriptor>
|
|
</md:EntityDescriptor>
|
|
`,
|
|
entityID)
|
|
|
|
return []byte(str)
|
|
}
|
|
|
|
func TestCreateSAMLAppRequestToDomain(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
genMetaForValidRequest := samlMetadataGen(integration.URL())
|
|
|
|
tt := []struct {
|
|
testName string
|
|
appName string
|
|
projectID string
|
|
req *application.CreateSAMLApplicationRequest
|
|
|
|
expectedResponse *domain.SAMLApp
|
|
expectedError error
|
|
}{
|
|
{
|
|
testName: "login version error",
|
|
appName: "test-application",
|
|
projectID: "proj-1",
|
|
req: &application.CreateSAMLApplicationRequest{
|
|
Metadata: &application.CreateSAMLApplicationRequest_MetadataXml{
|
|
MetadataXml: samlMetadataGen(integration.URL()),
|
|
},
|
|
LoginVersion: &application.LoginVersion{
|
|
Version: &application.LoginVersion_LoginV2{
|
|
LoginV2: &application.LoginV2{BaseUri: gu.Ptr("%+o")},
|
|
},
|
|
},
|
|
},
|
|
expectedError: &url.Error{
|
|
URL: "%+o",
|
|
Op: "parse",
|
|
Err: url.EscapeError("%+o"),
|
|
},
|
|
},
|
|
{
|
|
testName: "valid request",
|
|
appName: "test-application",
|
|
projectID: "proj-1",
|
|
req: &application.CreateSAMLApplicationRequest{
|
|
Metadata: &application.CreateSAMLApplicationRequest_MetadataXml{
|
|
MetadataXml: genMetaForValidRequest,
|
|
},
|
|
LoginVersion: nil,
|
|
},
|
|
|
|
expectedResponse: &domain.SAMLApp{
|
|
ObjectRoot: models.ObjectRoot{AggregateID: "proj-1"},
|
|
AppName: "test-application",
|
|
Metadata: genMetaForValidRequest,
|
|
MetadataURL: gu.Ptr(""),
|
|
LoginVersion: gu.Ptr(domain.LoginVersionUnspecified),
|
|
LoginBaseURI: gu.Ptr(""),
|
|
State: 0,
|
|
},
|
|
},
|
|
{
|
|
testName: "nil request",
|
|
appName: "test-application",
|
|
projectID: "proj-1",
|
|
req: nil,
|
|
|
|
expectedResponse: &domain.SAMLApp{
|
|
AppName: "test-application",
|
|
ObjectRoot: models.ObjectRoot{AggregateID: "proj-1"},
|
|
MetadataURL: gu.Ptr(""),
|
|
LoginVersion: gu.Ptr(domain.LoginVersionUnspecified),
|
|
LoginBaseURI: gu.Ptr(""),
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
t.Run(tc.testName, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// When
|
|
res, err := CreateSAMLAppRequestToDomain(tc.appName, tc.projectID, tc.req)
|
|
|
|
// Then
|
|
assert.Equal(t, tc.expectedError, err)
|
|
assert.Equal(t, tc.expectedResponse, res)
|
|
})
|
|
}
|
|
}
|
|
func TestUpdateSAMLAppConfigRequestToDomain(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
genMetaForValidRequest := samlMetadataGen(integration.URL())
|
|
|
|
tt := []struct {
|
|
testName string
|
|
appID string
|
|
projectID string
|
|
req *application.UpdateSAMLApplicationConfigurationRequest
|
|
|
|
expectedResponse *domain.SAMLApp
|
|
expectedError error
|
|
}{
|
|
{
|
|
testName: "login version error",
|
|
appID: "application-1",
|
|
projectID: "proj-1",
|
|
req: &application.UpdateSAMLApplicationConfigurationRequest{
|
|
Metadata: &application.UpdateSAMLApplicationConfigurationRequest_MetadataXml{
|
|
MetadataXml: samlMetadataGen(integration.URL()),
|
|
},
|
|
LoginVersion: &application.LoginVersion{
|
|
Version: &application.LoginVersion_LoginV2{
|
|
LoginV2: &application.LoginV2{BaseUri: gu.Ptr("%+o")},
|
|
},
|
|
},
|
|
},
|
|
expectedError: &url.Error{
|
|
URL: "%+o",
|
|
Op: "parse",
|
|
Err: url.EscapeError("%+o"),
|
|
},
|
|
},
|
|
{
|
|
testName: "valid request",
|
|
appID: "application-1",
|
|
projectID: "proj-1",
|
|
req: &application.UpdateSAMLApplicationConfigurationRequest{
|
|
Metadata: &application.UpdateSAMLApplicationConfigurationRequest_MetadataXml{
|
|
MetadataXml: genMetaForValidRequest,
|
|
},
|
|
LoginVersion: nil,
|
|
},
|
|
expectedResponse: &domain.SAMLApp{
|
|
ObjectRoot: models.ObjectRoot{AggregateID: "proj-1"},
|
|
AppID: "application-1",
|
|
Metadata: genMetaForValidRequest,
|
|
LoginVersion: gu.Ptr(domain.LoginVersionUnspecified),
|
|
LoginBaseURI: gu.Ptr(""),
|
|
},
|
|
},
|
|
{
|
|
testName: "nil request",
|
|
appID: "application-1",
|
|
projectID: "proj-1",
|
|
req: nil,
|
|
expectedResponse: &domain.SAMLApp{
|
|
ObjectRoot: models.ObjectRoot{AggregateID: "proj-1"},
|
|
AppID: "application-1",
|
|
LoginVersion: gu.Ptr(domain.LoginVersionUnspecified),
|
|
LoginBaseURI: gu.Ptr(""),
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
t.Run(tc.testName, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// When
|
|
res, err := UpdateSAMLAppConfigRequestToDomain(tc.appID, tc.projectID, tc.req)
|
|
|
|
// Then
|
|
assert.Equal(t, tc.expectedError, err)
|
|
assert.Equal(t, tc.expectedResponse, res)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppSAMLConfigToPb(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
metadata := samlMetadataGen(integration.URL())
|
|
|
|
tt := []struct {
|
|
name string
|
|
inputSAMLApp *query.SAMLApp
|
|
|
|
expectedPbApp application.IsApplicationConfiguration
|
|
}{
|
|
{
|
|
name: "valid conversion",
|
|
inputSAMLApp: &query.SAMLApp{
|
|
Metadata: metadata,
|
|
LoginVersion: domain.LoginVersion2,
|
|
LoginBaseURI: gu.Ptr("https://example.com"),
|
|
},
|
|
expectedPbApp: &application.Application_SamlConfiguration{
|
|
SamlConfiguration: &application.SAMLConfiguration{
|
|
MetadataXml: metadata,
|
|
LoginVersion: &application.LoginVersion{
|
|
Version: &application.LoginVersion_LoginV2{
|
|
LoginV2: &application.LoginV2{BaseUri: gu.Ptr("https://example.com")},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "nil saml application",
|
|
inputSAMLApp: nil,
|
|
expectedPbApp: &application.Application_SamlConfiguration{
|
|
SamlConfiguration: &application.SAMLConfiguration{
|
|
LoginVersion: &application.LoginVersion{},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// When
|
|
got := appSAMLConfigToPb(tc.inputSAMLApp)
|
|
|
|
// Then
|
|
assert.Equal(t, tc.expectedPbApp, got)
|
|
})
|
|
}
|
|
}
|