zitadel/internal/command/idp_model_test.go
Stefan Benz 15fd3045e0
feat: add SAML as identity provider (#6454)
* feat: first implementation for saml sp

* fix: add command side instance and org for saml provider

* fix: add query side instance and org for saml provider

* fix: request handling in event and retrieval of finished intent

* fix: add review changes and integration tests

* fix: add integration tests for saml idp

* fix: correct unit tests with review changes

* fix: add saml session unit test

* fix: add saml session unit test

* fix: add saml session unit test

* fix: changes from review

* fix: changes from review

* fix: proto build error

* fix: proto build error

* fix: proto build error

* fix: proto require metadata oneof

* fix: login with saml provider

* fix: integration test for saml assertion

* lint client.go

* fix json tag

* fix: linting

* fix import

* fix: linting

* fix saml idp query

* fix: linting

* lint: try all issues

* revert linting config

* fix: add regenerate endpoints

* fix: translations

* fix mk.yaml

* ignore acs path for user agent cookie

* fix: add AuthFromProvider test for saml

* fix: integration test for saml retrieve information

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
2023-09-29 11:26:14 +02:00

356 lines
7.7 KiB
Go

package command
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
)
func TestCommands_AllIDPWriteModel(t *testing.T) {
type args struct {
resourceOwner string
instanceBool bool
id string
idpType domain.IDPType
}
type res struct {
writeModelType interface{}
samlWriteModelType interface{}
err error
}
tests := []struct {
name string
args args
res res
}{
{
name: "writemodel instance oidc",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeOIDC,
},
res: res{
writeModelType: &InstanceOIDCIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance jwt",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeJWT,
},
res: res{
writeModelType: &InstanceJWTIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance oauth",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeOAuth,
},
res: res{
writeModelType: &InstanceOAuthIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance ldap",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeLDAP,
},
res: res{
writeModelType: &InstanceLDAPIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance azureAD",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeAzureAD,
},
res: res{
writeModelType: &InstanceAzureADIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance github",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeGitHub,
},
res: res{
writeModelType: &InstanceGitHubIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance github enterprise",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeGitHubEnterprise,
},
res: res{
writeModelType: &InstanceGitHubEnterpriseIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance gitlab",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeGitLab,
},
res: res{
writeModelType: &InstanceGitLabIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance gitlab self hosted",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeGitLabSelfHosted,
},
res: res{
writeModelType: &InstanceGitLabSelfHostedIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance google",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeGoogle,
},
res: res{
writeModelType: &InstanceGoogleIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance saml",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeSAML,
},
res: res{
samlWriteModelType: &InstanceSAMLIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel instance unspecified",
args: args{
resourceOwner: "owner",
instanceBool: true,
id: "id",
idpType: domain.IDPTypeUnspecified,
},
res: res{
err: errors.ThrowInternal(nil, "COMMAND-xw921211", "Errors.IDPConfig.NotExisting"),
},
},
{
name: "writemodel org oidc",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeOIDC,
},
res: res{
writeModelType: &OrgOIDCIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org jwt",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeJWT,
},
res: res{
writeModelType: &OrgJWTIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org oauth",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeOAuth,
},
res: res{
writeModelType: &OrgOAuthIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org ldap",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeLDAP,
},
res: res{
writeModelType: &OrgLDAPIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org azureAD",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeAzureAD,
},
res: res{
writeModelType: &OrgAzureADIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org github",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeGitHub,
},
res: res{
writeModelType: &OrgGitHubIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org github enterprise",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeGitHubEnterprise,
},
res: res{
writeModelType: &OrgGitHubEnterpriseIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org gitlab",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeGitLab,
},
res: res{
writeModelType: &OrgGitLabIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org gitlab self hosted",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeGitLabSelfHosted,
},
res: res{
writeModelType: &OrgGitLabSelfHostedIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org google",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeGoogle,
},
res: res{
writeModelType: &OrgGoogleIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org saml",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeSAML,
},
res: res{
samlWriteModelType: &OrgSAMLIDPWriteModel{},
err: nil,
},
},
{
name: "writemodel org unspecified",
args: args{
resourceOwner: "owner",
instanceBool: false,
id: "id",
idpType: domain.IDPTypeUnspecified,
},
res: res{
err: errors.ThrowInternal(nil, "COMMAND-xw921111", "Errors.IDPConfig.NotExisting"),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
wm, err := NewAllIDPWriteModel(tt.args.resourceOwner, tt.args.instanceBool, tt.args.id, tt.args.idpType)
require.ErrorIs(t, err, tt.res.err)
if wm != nil {
if tt.res.writeModelType != nil {
assert.IsType(t, tt.res.writeModelType, wm.model)
}
if tt.res.samlWriteModelType != nil {
assert.IsType(t, tt.res.samlWriteModelType, wm.samlModel)
}
}
})
}
}