2023-02-15 09:14:59 +01:00
package query
import (
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"regexp"
"testing"
2023-03-24 16:18:56 +01:00
"time"
2023-02-15 09:14:59 +01:00
2023-02-21 18:18:28 +01:00
"github.com/zitadel/zitadel/internal/database"
2023-02-15 09:14:59 +01:00
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/repository/idp"
2023-12-08 16:30:55 +02:00
"github.com/zitadel/zitadel/internal/zerrors"
2023-02-15 09:14:59 +01:00
)
var (
2023-04-17 10:20:49 +02:00
idpTemplateQuery = ` SELECT projections.idp_templates5.id, ` +
` projections.idp_templates5.resource_owner, ` +
` projections.idp_templates5.creation_date, ` +
` projections.idp_templates5.change_date, ` +
` projections.idp_templates5.sequence, ` +
` projections.idp_templates5.state, ` +
` projections.idp_templates5.name, ` +
` projections.idp_templates5.type, ` +
` projections.idp_templates5.owner_type, ` +
` projections.idp_templates5.is_creation_allowed, ` +
` projections.idp_templates5.is_linking_allowed, ` +
` projections.idp_templates5.is_auto_creation, ` +
` projections.idp_templates5.is_auto_update, ` +
2023-02-24 15:16:06 +01:00
// oauth
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_oauth2.idp_id, ` +
` projections.idp_templates5_oauth2.client_id, ` +
` projections.idp_templates5_oauth2.client_secret, ` +
` projections.idp_templates5_oauth2.authorization_endpoint, ` +
` projections.idp_templates5_oauth2.token_endpoint, ` +
` projections.idp_templates5_oauth2.user_endpoint, ` +
` projections.idp_templates5_oauth2.scopes, ` +
` projections.idp_templates5_oauth2.id_attribute, ` +
2023-02-27 16:32:18 +01:00
// oidc
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_oidc.idp_id, ` +
` projections.idp_templates5_oidc.issuer, ` +
` projections.idp_templates5_oidc.client_id, ` +
` projections.idp_templates5_oidc.client_secret, ` +
` projections.idp_templates5_oidc.scopes, ` +
` projections.idp_templates5_oidc.id_token_mapping, ` +
2023-02-27 16:32:18 +01:00
// jwt
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_jwt.idp_id, ` +
` projections.idp_templates5_jwt.issuer, ` +
` projections.idp_templates5_jwt.jwt_endpoint, ` +
` projections.idp_templates5_jwt.keys_endpoint, ` +
` projections.idp_templates5_jwt.header_name, ` +
2023-03-15 07:48:37 +01:00
// azure
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_azure.idp_id, ` +
` projections.idp_templates5_azure.client_id, ` +
` projections.idp_templates5_azure.client_secret, ` +
` projections.idp_templates5_azure.scopes, ` +
` projections.idp_templates5_azure.tenant, ` +
` projections.idp_templates5_azure.is_email_verified, ` +
2023-03-08 11:17:28 +01:00
// github
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_github.idp_id, ` +
` projections.idp_templates5_github.client_id, ` +
` projections.idp_templates5_github.client_secret, ` +
` projections.idp_templates5_github.scopes, ` +
2023-03-08 11:17:28 +01:00
// github enterprise
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_github_enterprise.idp_id, ` +
` projections.idp_templates5_github_enterprise.client_id, ` +
` projections.idp_templates5_github_enterprise.client_secret, ` +
` projections.idp_templates5_github_enterprise.authorization_endpoint, ` +
` projections.idp_templates5_github_enterprise.token_endpoint, ` +
` projections.idp_templates5_github_enterprise.user_endpoint, ` +
` projections.idp_templates5_github_enterprise.scopes, ` +
2023-03-13 17:34:29 +01:00
// gitlab
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_gitlab.idp_id, ` +
` projections.idp_templates5_gitlab.client_id, ` +
` projections.idp_templates5_gitlab.client_secret, ` +
` projections.idp_templates5_gitlab.scopes, ` +
2023-03-13 17:34:29 +01:00
// gitlab self hosted
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_gitlab_self_hosted.idp_id, ` +
` projections.idp_templates5_gitlab_self_hosted.issuer, ` +
` projections.idp_templates5_gitlab_self_hosted.client_id, ` +
` projections.idp_templates5_gitlab_self_hosted.client_secret, ` +
` projections.idp_templates5_gitlab_self_hosted.scopes, ` +
2023-02-24 15:16:06 +01:00
// google
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_google.idp_id, ` +
` projections.idp_templates5_google.client_id, ` +
` projections.idp_templates5_google.client_secret, ` +
` projections.idp_templates5_google.scopes, ` +
2023-09-29 11:26:14 +02:00
// saml
` projections.idp_templates5_saml.idp_id, ` +
` projections.idp_templates5_saml.metadata, ` +
` projections.idp_templates5_saml.key, ` +
` projections.idp_templates5_saml.certificate, ` +
` projections.idp_templates5_saml.binding, ` +
` projections.idp_templates5_saml.with_signed_request, ` +
2023-02-24 15:16:06 +01:00
// ldap
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_ldap2.idp_id, ` +
` projections.idp_templates5_ldap2.servers, ` +
` projections.idp_templates5_ldap2.start_tls, ` +
` projections.idp_templates5_ldap2.base_dn, ` +
` projections.idp_templates5_ldap2.bind_dn, ` +
` projections.idp_templates5_ldap2.bind_password, ` +
` projections.idp_templates5_ldap2.user_base, ` +
` projections.idp_templates5_ldap2.user_object_classes, ` +
` projections.idp_templates5_ldap2.user_filters, ` +
` projections.idp_templates5_ldap2.timeout, ` +
` projections.idp_templates5_ldap2.id_attribute, ` +
` projections.idp_templates5_ldap2.first_name_attribute, ` +
` projections.idp_templates5_ldap2.last_name_attribute, ` +
` projections.idp_templates5_ldap2.display_name_attribute, ` +
` projections.idp_templates5_ldap2.nick_name_attribute, ` +
` projections.idp_templates5_ldap2.preferred_username_attribute, ` +
` projections.idp_templates5_ldap2.email_attribute, ` +
` projections.idp_templates5_ldap2.email_verified, ` +
` projections.idp_templates5_ldap2.phone_attribute, ` +
` projections.idp_templates5_ldap2.phone_verified_attribute, ` +
` projections.idp_templates5_ldap2.preferred_language_attribute, ` +
` projections.idp_templates5_ldap2.avatar_url_attribute, ` +
2023-08-31 08:39:16 +02:00
` projections.idp_templates5_ldap2.profile_attribute, ` +
// apple
` projections.idp_templates5_apple.idp_id, ` +
` projections.idp_templates5_apple.client_id, ` +
` projections.idp_templates5_apple.team_id, ` +
` projections.idp_templates5_apple.key_id, ` +
` projections.idp_templates5_apple.private_key, ` +
` projections.idp_templates5_apple.scopes ` +
2023-04-17 10:20:49 +02:00
` FROM projections.idp_templates5 ` +
` LEFT JOIN projections.idp_templates5_oauth2 ON projections.idp_templates5.id = projections.idp_templates5_oauth2.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_oauth2.instance_id ` +
` LEFT JOIN projections.idp_templates5_oidc ON projections.idp_templates5.id = projections.idp_templates5_oidc.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_oidc.instance_id ` +
` LEFT JOIN projections.idp_templates5_jwt ON projections.idp_templates5.id = projections.idp_templates5_jwt.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_jwt.instance_id ` +
` LEFT JOIN projections.idp_templates5_azure ON projections.idp_templates5.id = projections.idp_templates5_azure.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_azure.instance_id ` +
` LEFT JOIN projections.idp_templates5_github ON projections.idp_templates5.id = projections.idp_templates5_github.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_github.instance_id ` +
` LEFT JOIN projections.idp_templates5_github_enterprise ON projections.idp_templates5.id = projections.idp_templates5_github_enterprise.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_github_enterprise.instance_id ` +
` LEFT JOIN projections.idp_templates5_gitlab ON projections.idp_templates5.id = projections.idp_templates5_gitlab.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_gitlab.instance_id ` +
` LEFT JOIN projections.idp_templates5_gitlab_self_hosted ON projections.idp_templates5.id = projections.idp_templates5_gitlab_self_hosted.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_gitlab_self_hosted.instance_id ` +
` LEFT JOIN projections.idp_templates5_google ON projections.idp_templates5.id = projections.idp_templates5_google.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_google.instance_id ` +
2023-09-29 11:26:14 +02:00
` LEFT JOIN projections.idp_templates5_saml ON projections.idp_templates5.id = projections.idp_templates5_saml.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_saml.instance_id ` +
2023-04-17 10:20:49 +02:00
` LEFT JOIN projections.idp_templates5_ldap2 ON projections.idp_templates5.id = projections.idp_templates5_ldap2.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_ldap2.instance_id ` +
2023-08-31 08:39:16 +02:00
` LEFT JOIN projections.idp_templates5_apple ON projections.idp_templates5.id = projections.idp_templates5_apple.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_apple.instance_id ` +
2023-02-27 22:36:43 +01:00
` AS OF SYSTEM TIME '-1 ms' `
2023-02-15 09:14:59 +01:00
idpTemplateCols = [ ] string {
"id" ,
"resource_owner" ,
"creation_date" ,
"change_date" ,
"sequence" ,
"state" ,
"name" ,
"type" ,
"owner_type" ,
"is_creation_allowed" ,
"is_linking_allowed" ,
"is_auto_creation" ,
"is_auto_update" ,
2023-02-24 15:16:06 +01:00
// oauth config
"idp_id" ,
"client_id" ,
"client_secret" ,
"authorization_endpoint" ,
"token_endpoint" ,
"user_endpoint" ,
"scopes" ,
2023-03-03 11:38:49 +01:00
"id_attribute" ,
2023-02-27 16:32:18 +01:00
// oidc config
"id_id" ,
"issuer" ,
"client_id" ,
"client_secret" ,
"scopes" ,
2023-03-16 16:47:22 +01:00
"id_token_mapping" ,
2023-02-27 16:32:18 +01:00
// jwt
"idp_id" ,
"issuer" ,
"jwt_endpoint" ,
"keys_endpoint" ,
"header_name" ,
2023-03-15 07:48:37 +01:00
// azure
"idp_id" ,
"client_id" ,
"client_secret" ,
"scopes" ,
"tenant" ,
"is_email_verified" ,
2023-03-08 11:17:28 +01:00
// github config
"idp_id" ,
"client_id" ,
"client_secret" ,
"scopes" ,
// github enterprise config
"idp_id" ,
"client_id" ,
"client_secret" ,
"authorization_endpoint" ,
"token_endpoint" ,
"user_endpoint" ,
"scopes" ,
2023-03-13 17:34:29 +01:00
// gitlab config
"idp_id" ,
"client_id" ,
"client_secret" ,
"scopes" ,
// gitlab self hosted config
"idp_id" ,
"issuer" ,
"client_id" ,
"client_secret" ,
"scopes" ,
2023-02-21 18:18:28 +01:00
// google config
"idp_id" ,
"client_id" ,
"client_secret" ,
"scopes" ,
2023-09-29 11:26:14 +02:00
// saml config
"idp_id" ,
"metadata" ,
"key" ,
"certificate" ,
"binding" ,
"with_signed_request" ,
2023-02-15 09:14:59 +01:00
// ldap config
"idp_id" ,
2023-03-24 16:18:56 +01:00
"servers" ,
"start_tls" ,
2023-02-15 09:14:59 +01:00
"base_dn" ,
2023-03-24 16:18:56 +01:00
"bind_dn" ,
"bind_password" ,
"user_base" ,
"user_object_classes" ,
"user_filters" ,
"timeout" ,
2023-02-15 09:14:59 +01:00
"id_attribute" ,
"first_name_attribute" ,
"last_name_attribute" ,
"display_name_attribute" ,
"nick_name_attribute" ,
"preferred_username_attribute" ,
"email_attribute" ,
"email_verified" ,
"phone_attribute" ,
"phone_verified_attribute" ,
"preferred_language_attribute" ,
"avatar_url_attribute" ,
"profile_attribute" ,
2023-08-31 08:39:16 +02:00
// apple config
"idp_id" ,
"client_id" ,
"team_id" ,
"key_id" ,
"private_key" ,
"scopes" ,
2023-02-15 09:14:59 +01:00
}
2023-04-17 10:20:49 +02:00
idpTemplatesQuery = ` SELECT projections.idp_templates5.id, ` +
` projections.idp_templates5.resource_owner, ` +
` projections.idp_templates5.creation_date, ` +
` projections.idp_templates5.change_date, ` +
` projections.idp_templates5.sequence, ` +
` projections.idp_templates5.state, ` +
` projections.idp_templates5.name, ` +
` projections.idp_templates5.type, ` +
` projections.idp_templates5.owner_type, ` +
` projections.idp_templates5.is_creation_allowed, ` +
` projections.idp_templates5.is_linking_allowed, ` +
` projections.idp_templates5.is_auto_creation, ` +
` projections.idp_templates5.is_auto_update, ` +
2023-02-24 15:16:06 +01:00
// oauth
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_oauth2.idp_id, ` +
` projections.idp_templates5_oauth2.client_id, ` +
` projections.idp_templates5_oauth2.client_secret, ` +
` projections.idp_templates5_oauth2.authorization_endpoint, ` +
` projections.idp_templates5_oauth2.token_endpoint, ` +
` projections.idp_templates5_oauth2.user_endpoint, ` +
` projections.idp_templates5_oauth2.scopes, ` +
` projections.idp_templates5_oauth2.id_attribute, ` +
2023-02-27 16:32:18 +01:00
// oidc
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_oidc.idp_id, ` +
` projections.idp_templates5_oidc.issuer, ` +
` projections.idp_templates5_oidc.client_id, ` +
` projections.idp_templates5_oidc.client_secret, ` +
` projections.idp_templates5_oidc.scopes, ` +
` projections.idp_templates5_oidc.id_token_mapping, ` +
2023-02-27 16:32:18 +01:00
// jwt
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_jwt.idp_id, ` +
` projections.idp_templates5_jwt.issuer, ` +
` projections.idp_templates5_jwt.jwt_endpoint, ` +
` projections.idp_templates5_jwt.keys_endpoint, ` +
` projections.idp_templates5_jwt.header_name, ` +
2023-03-15 07:48:37 +01:00
// azure
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_azure.idp_id, ` +
` projections.idp_templates5_azure.client_id, ` +
` projections.idp_templates5_azure.client_secret, ` +
` projections.idp_templates5_azure.scopes, ` +
` projections.idp_templates5_azure.tenant, ` +
` projections.idp_templates5_azure.is_email_verified, ` +
2023-03-08 11:17:28 +01:00
// github
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_github.idp_id, ` +
` projections.idp_templates5_github.client_id, ` +
` projections.idp_templates5_github.client_secret, ` +
` projections.idp_templates5_github.scopes, ` +
2023-03-08 11:17:28 +01:00
// github enterprise
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_github_enterprise.idp_id, ` +
` projections.idp_templates5_github_enterprise.client_id, ` +
` projections.idp_templates5_github_enterprise.client_secret, ` +
` projections.idp_templates5_github_enterprise.authorization_endpoint, ` +
` projections.idp_templates5_github_enterprise.token_endpoint, ` +
` projections.idp_templates5_github_enterprise.user_endpoint, ` +
` projections.idp_templates5_github_enterprise.scopes, ` +
2023-03-13 17:34:29 +01:00
// gitlab
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_gitlab.idp_id, ` +
` projections.idp_templates5_gitlab.client_id, ` +
` projections.idp_templates5_gitlab.client_secret, ` +
` projections.idp_templates5_gitlab.scopes, ` +
2023-03-13 17:34:29 +01:00
// gitlab self hosted
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_gitlab_self_hosted.idp_id, ` +
` projections.idp_templates5_gitlab_self_hosted.issuer, ` +
` projections.idp_templates5_gitlab_self_hosted.client_id, ` +
` projections.idp_templates5_gitlab_self_hosted.client_secret, ` +
` projections.idp_templates5_gitlab_self_hosted.scopes, ` +
2023-02-24 15:16:06 +01:00
// google
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_google.idp_id, ` +
` projections.idp_templates5_google.client_id, ` +
` projections.idp_templates5_google.client_secret, ` +
` projections.idp_templates5_google.scopes, ` +
2023-09-29 11:26:14 +02:00
// saml
` projections.idp_templates5_saml.idp_id, ` +
` projections.idp_templates5_saml.metadata, ` +
` projections.idp_templates5_saml.key, ` +
` projections.idp_templates5_saml.certificate, ` +
` projections.idp_templates5_saml.binding, ` +
` projections.idp_templates5_saml.with_signed_request, ` +
2023-02-24 15:16:06 +01:00
// ldap
2023-04-17 10:20:49 +02:00
` projections.idp_templates5_ldap2.idp_id, ` +
` projections.idp_templates5_ldap2.servers, ` +
` projections.idp_templates5_ldap2.start_tls, ` +
` projections.idp_templates5_ldap2.base_dn, ` +
` projections.idp_templates5_ldap2.bind_dn, ` +
` projections.idp_templates5_ldap2.bind_password, ` +
` projections.idp_templates5_ldap2.user_base, ` +
` projections.idp_templates5_ldap2.user_object_classes, ` +
` projections.idp_templates5_ldap2.user_filters, ` +
` projections.idp_templates5_ldap2.timeout, ` +
` projections.idp_templates5_ldap2.id_attribute, ` +
` projections.idp_templates5_ldap2.first_name_attribute, ` +
` projections.idp_templates5_ldap2.last_name_attribute, ` +
` projections.idp_templates5_ldap2.display_name_attribute, ` +
` projections.idp_templates5_ldap2.nick_name_attribute, ` +
` projections.idp_templates5_ldap2.preferred_username_attribute, ` +
` projections.idp_templates5_ldap2.email_attribute, ` +
` projections.idp_templates5_ldap2.email_verified, ` +
` projections.idp_templates5_ldap2.phone_attribute, ` +
` projections.idp_templates5_ldap2.phone_verified_attribute, ` +
` projections.idp_templates5_ldap2.preferred_language_attribute, ` +
` projections.idp_templates5_ldap2.avatar_url_attribute, ` +
` projections.idp_templates5_ldap2.profile_attribute, ` +
2023-08-31 08:39:16 +02:00
// apple
` projections.idp_templates5_apple.idp_id, ` +
` projections.idp_templates5_apple.client_id, ` +
` projections.idp_templates5_apple.team_id, ` +
` projections.idp_templates5_apple.key_id, ` +
` projections.idp_templates5_apple.private_key, ` +
` projections.idp_templates5_apple.scopes, ` +
2023-02-15 09:14:59 +01:00
` COUNT(*) OVER () ` +
2023-04-17 10:20:49 +02:00
` FROM projections.idp_templates5 ` +
` LEFT JOIN projections.idp_templates5_oauth2 ON projections.idp_templates5.id = projections.idp_templates5_oauth2.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_oauth2.instance_id ` +
` LEFT JOIN projections.idp_templates5_oidc ON projections.idp_templates5.id = projections.idp_templates5_oidc.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_oidc.instance_id ` +
` LEFT JOIN projections.idp_templates5_jwt ON projections.idp_templates5.id = projections.idp_templates5_jwt.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_jwt.instance_id ` +
` LEFT JOIN projections.idp_templates5_azure ON projections.idp_templates5.id = projections.idp_templates5_azure.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_azure.instance_id ` +
` LEFT JOIN projections.idp_templates5_github ON projections.idp_templates5.id = projections.idp_templates5_github.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_github.instance_id ` +
` LEFT JOIN projections.idp_templates5_github_enterprise ON projections.idp_templates5.id = projections.idp_templates5_github_enterprise.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_github_enterprise.instance_id ` +
` LEFT JOIN projections.idp_templates5_gitlab ON projections.idp_templates5.id = projections.idp_templates5_gitlab.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_gitlab.instance_id ` +
` LEFT JOIN projections.idp_templates5_gitlab_self_hosted ON projections.idp_templates5.id = projections.idp_templates5_gitlab_self_hosted.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_gitlab_self_hosted.instance_id ` +
` LEFT JOIN projections.idp_templates5_google ON projections.idp_templates5.id = projections.idp_templates5_google.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_google.instance_id ` +
2023-09-29 11:26:14 +02:00
` LEFT JOIN projections.idp_templates5_saml ON projections.idp_templates5.id = projections.idp_templates5_saml.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_saml.instance_id ` +
2023-04-17 10:20:49 +02:00
` LEFT JOIN projections.idp_templates5_ldap2 ON projections.idp_templates5.id = projections.idp_templates5_ldap2.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_ldap2.instance_id ` +
2023-08-31 08:39:16 +02:00
` LEFT JOIN projections.idp_templates5_apple ON projections.idp_templates5.id = projections.idp_templates5_apple.idp_id AND projections.idp_templates5.instance_id = projections.idp_templates5_apple.instance_id ` +
2023-02-27 22:36:43 +01:00
` AS OF SYSTEM TIME '-1 ms' `
2023-02-15 09:14:59 +01:00
idpTemplatesCols = [ ] string {
"id" ,
"resource_owner" ,
"creation_date" ,
"change_date" ,
"sequence" ,
"state" ,
"name" ,
"type" ,
"owner_type" ,
"is_creation_allowed" ,
"is_linking_allowed" ,
"is_auto_creation" ,
"is_auto_update" ,
2023-02-24 15:16:06 +01:00
// oauth config
"idp_id" ,
"client_id" ,
"client_secret" ,
"authorization_endpoint" ,
"token_endpoint" ,
"user_endpoint" ,
"scopes" ,
2023-03-03 11:38:49 +01:00
"id_attribute" ,
2023-02-27 16:32:18 +01:00
// oidc config
"id_id" ,
"issuer" ,
"client_id" ,
"client_secret" ,
"scopes" ,
2023-03-16 16:47:22 +01:00
"id_token_mapping" ,
2023-02-27 16:32:18 +01:00
// jwt
"idp_id" ,
"issuer" ,
"jwt_endpoint" ,
"keys_endpoint" ,
"header_name" ,
2023-03-15 07:48:37 +01:00
// azure
"idp_id" ,
"client_id" ,
"client_secret" ,
"scopes" ,
"tenant" ,
"is_email_verified" ,
2023-03-08 11:17:28 +01:00
// github config
"idp_id" ,
"client_id" ,
"client_secret" ,
"scopes" ,
// github enterprise config
"idp_id" ,
"client_id" ,
"client_secret" ,
"authorization_endpoint" ,
"token_endpoint" ,
"user_endpoint" ,
"scopes" ,
2023-03-13 17:34:29 +01:00
// gitlab config
"idp_id" ,
"client_id" ,
"client_secret" ,
"scopes" ,
// gitlab self hosted config
"idp_id" ,
"issuer" ,
"client_id" ,
"client_secret" ,
"scopes" ,
2023-02-21 18:18:28 +01:00
// google config
"idp_id" ,
"client_id" ,
"client_secret" ,
"scopes" ,
2023-09-29 11:26:14 +02:00
// saml config
"idp_id" ,
"metadata" ,
"key" ,
"certificate" ,
"binding" ,
"with_signed_request" ,
2023-02-21 18:18:28 +01:00
// ldap config
2023-02-15 09:14:59 +01:00
"idp_id" ,
2023-03-24 16:18:56 +01:00
"servers" ,
"start_tls" ,
2023-02-15 09:14:59 +01:00
"base_dn" ,
2023-03-24 16:18:56 +01:00
"bind_dn" ,
"bind_password" ,
"user_base" ,
"user_object_classes" ,
"user_filters" ,
"timeout" ,
2023-02-15 09:14:59 +01:00
"id_attribute" ,
"first_name_attribute" ,
"last_name_attribute" ,
"display_name_attribute" ,
"nick_name_attribute" ,
"preferred_username_attribute" ,
"email_attribute" ,
"email_verified" ,
"phone_attribute" ,
"phone_verified_attribute" ,
"preferred_language_attribute" ,
"avatar_url_attribute" ,
"profile_attribute" ,
2023-08-31 08:39:16 +02:00
// apple config
"idp_id" ,
"client_id" ,
"team_id" ,
"key_id" ,
"private_key" ,
"scopes" ,
2023-02-15 09:14:59 +01:00
"count" ,
}
)
func Test_IDPTemplateTemplatesPrepares ( t * testing . T ) {
type want struct {
sqlExpectations sqlExpectation
err checkErr
}
tests := [ ] struct {
name string
prepare interface { }
want want
object interface { }
} {
{
name : "prepareIDPTemplateByIDQuery no result" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
2023-08-22 12:49:22 +02:00
sqlExpectations : mockQueryScanErr (
2023-02-15 09:14:59 +01:00
regexp . QuoteMeta ( idpTemplateQuery ) ,
nil ,
nil ,
) ,
err : func ( err error ) ( error , bool ) {
2023-12-08 16:30:55 +02:00
if ! zerrors . IsNotFound ( err ) {
2023-02-15 09:14:59 +01:00
return fmt . Errorf ( "err should be zitadel.NotFoundError got: %w" , err ) , false
}
return nil , true
} ,
} ,
object : ( * IDPTemplate ) ( nil ) ,
} ,
2023-02-24 15:16:06 +01:00
{
name : "prepareIDPTemplateByIDQuery oauth idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeOAuth ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
"idp-id" ,
"client_id" ,
nil ,
"authorization" ,
"token" ,
"user" ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-03-03 11:38:49 +01:00
"id-attribute" ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-24 15:16:06 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-24 15:16:06 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-24 15:16:06 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeOAuth ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
OAuthIDPTemplate : & OAuthIDPTemplate {
IDPID : "idp-id" ,
ClientID : "client_id" ,
ClientSecret : nil ,
AuthorizationEndpoint : "authorization" ,
TokenEndpoint : "token" ,
UserEndpoint : "user" ,
Scopes : [ ] string { "profile" } ,
2023-03-03 11:38:49 +01:00
IDAttribute : "id-attribute" ,
2023-02-24 15:16:06 +01:00
} ,
} ,
} ,
2023-02-27 16:32:18 +01:00
{
name : "prepareIDPTemplateByIDQuery oidc idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeOIDC ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
"idp-id" ,
"issuer" ,
"client_id" ,
nil ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-03-16 16:47:22 +01:00
true ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeOIDC ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
OIDCIDPTemplate : & OIDCIDPTemplate {
2023-03-16 16:47:22 +01:00
IDPID : "idp-id" ,
Issuer : "issuer" ,
ClientID : "client_id" ,
ClientSecret : nil ,
Scopes : [ ] string { "profile" } ,
IsIDTokenMapping : true ,
2023-02-27 16:32:18 +01:00
} ,
} ,
} ,
{
2023-03-08 11:17:28 +01:00
name : "prepareIDPTemplateByIDQuery jwt idp" ,
2023-02-27 16:32:18 +01:00
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeJWT ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
"idp-id" ,
"issuer" ,
"jwt" ,
"keys" ,
"header" ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeJWT ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
JWTIDPTemplate : & JWTIDPTemplate {
IDPID : "idp-id" ,
Issuer : "issuer" ,
Endpoint : "jwt" ,
KeysEndpoint : "keys" ,
HeaderName : "header" ,
} ,
} ,
} ,
2023-03-08 11:17:28 +01:00
{
name : "prepareIDPTemplateByIDQuery github idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeGitHub ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-03-08 11:17:28 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
"idp-id" ,
"client_id" ,
nil ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-03-08 11:17:28 +01:00
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeGitHub ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
GitHubIDPTemplate : & GitHubIDPTemplate {
IDPID : "idp-id" ,
ClientID : "client_id" ,
ClientSecret : nil ,
Scopes : [ ] string { "profile" } ,
} ,
} ,
} ,
2023-03-13 17:34:29 +01:00
{
name : "prepareIDPTemplateByIDQuery gitlab idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeGitLab ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-03-13 17:34:29 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// gitlab
"idp-id" ,
"client_id" ,
nil ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-03-13 17:34:29 +01:00
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeGitLab ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
GitLabIDPTemplate : & GitLabIDPTemplate {
IDPID : "idp-id" ,
ClientID : "client_id" ,
ClientSecret : nil ,
Scopes : [ ] string { "profile" } ,
} ,
} ,
} ,
{
name : "prepareIDPTemplateByIDQuery gitlab self hosted idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeGitLabSelfHosted ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-03-13 17:34:29 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
"idp-id" ,
"issuer" ,
"client_id" ,
nil ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-03-13 17:34:29 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeGitLabSelfHosted ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
GitLabSelfHostedIDPTemplate : & GitLabSelfHostedIDPTemplate {
IDPID : "idp-id" ,
Issuer : "issuer" ,
ClientID : "client_id" ,
ClientSecret : nil ,
Scopes : [ ] string { "profile" } ,
} ,
} ,
} ,
2023-02-21 18:18:28 +01:00
{
name : "prepareIDPTemplateByIDQuery google idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeGoogle ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
2023-02-24 15:16:06 +01:00
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
// google
"idp-id" ,
"client_id" ,
nil ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeGoogle ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
GoogleIDPTemplate : & GoogleIDPTemplate {
IDPID : "idp-id" ,
ClientID : "client_id" ,
ClientSecret : nil ,
Scopes : [ ] string { "profile" } ,
} ,
} ,
} ,
2023-09-29 11:26:14 +02:00
{
name : "prepareIDPTemplateByIDQuery saml idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeSAML ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
// google
nil ,
nil ,
nil ,
nil ,
// saml
"idp-id" ,
[ ] byte ( "metadata" ) ,
nil ,
nil ,
"binding" ,
false ,
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeSAML ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
SAMLIDPTemplate : & SAMLIDPTemplate {
IDPID : "idp-id" ,
Metadata : [ ] byte ( "metadata" ) ,
Key : nil ,
Certificate : nil ,
Binding : "binding" ,
WithSignedRequest : false ,
} ,
} ,
} ,
2023-02-15 09:14:59 +01:00
{
name : "prepareIDPTemplateByIDQuery ldap idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeLDAP ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
2023-02-24 15:16:06 +01:00
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
// ldap config
"idp-id" ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "server" } ,
2023-02-15 09:14:59 +01:00
true ,
"base" ,
2023-03-24 16:18:56 +01:00
"dn" ,
2023-02-15 09:14:59 +01:00
nil ,
2023-03-24 16:18:56 +01:00
"user" ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "object" } ,
database . TextArray [ string ] { "filter" } ,
2023-03-24 16:18:56 +01:00
time . Duration ( 30000000000 ) ,
2023-02-15 09:14:59 +01:00
"id" ,
"first" ,
"last" ,
"display" ,
"nickname" ,
"username" ,
"email" ,
"emailVerified" ,
"phone" ,
"phoneVerified" ,
"lang" ,
"avatar" ,
"profile" ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeLDAP ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
LDAPIDPTemplate : & LDAPIDPTemplate {
2023-03-24 16:18:56 +01:00
IDPID : "idp-id" ,
Servers : [ ] string { "server" } ,
StartTLS : true ,
BaseDN : "base" ,
BindDN : "dn" ,
UserBase : "user" ,
UserObjectClasses : [ ] string { "object" } ,
UserFilters : [ ] string { "filter" } ,
Timeout : time . Duration ( 30000000000 ) ,
2023-02-15 09:14:59 +01:00
LDAPAttributes : idp . LDAPAttributes {
IDAttribute : "id" ,
FirstNameAttribute : "first" ,
LastNameAttribute : "last" ,
DisplayNameAttribute : "display" ,
NickNameAttribute : "nickname" ,
PreferredUsernameAttribute : "username" ,
EmailAttribute : "email" ,
EmailVerifiedAttribute : "emailVerified" ,
PhoneAttribute : "phone" ,
PhoneVerifiedAttribute : "phoneVerified" ,
PreferredLanguageAttribute : "lang" ,
AvatarURLAttribute : "avatar" ,
ProfileAttribute : "profile" ,
} ,
} ,
} ,
} ,
2023-08-31 08:39:16 +02:00
{
name : "prepareIDPTemplateByIDQuery apple idp" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeApple ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-08-31 08:39:16 +02:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// apple
"idp-id" ,
"client_id" ,
"team_id" ,
"key_id" ,
nil ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-08-31 08:39:16 +02:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeApple ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
AppleIDPTemplate : & AppleIDPTemplate {
IDPID : "idp-id" ,
ClientID : "client_id" ,
TeamID : "team_id" ,
KeyID : "key_id" ,
PrivateKey : nil ,
Scopes : [ ] string { "profile" } ,
} ,
} ,
} ,
2023-02-15 09:14:59 +01:00
{
name : "prepareIDPTemplateByIDQuery no config" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQuery (
regexp . QuoteMeta ( idpTemplateQuery ) ,
idpTemplateCols ,
[ ] driver . Value {
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeLDAP ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
2023-02-24 15:16:06 +01:00
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
// google config
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
} ,
) ,
} ,
object : & IDPTemplate {
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeLDAP ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
} ,
} ,
{
name : "prepareIDPTemplateByIDQuery sql err" ,
prepare : prepareIDPTemplateByIDQuery ,
want : want {
sqlExpectations : mockQueryErr (
regexp . QuoteMeta ( idpTemplateQuery ) ,
sql . ErrConnDone ,
) ,
err : func ( err error ) ( error , bool ) {
if ! errors . Is ( err , sql . ErrConnDone ) {
return fmt . Errorf ( "err should be sql.ErrConnDone got: %w" , err ) , false
}
return nil , true
} ,
} ,
2023-08-22 12:49:22 +02:00
object : ( * IDPTemplate ) ( nil ) ,
2023-02-15 09:14:59 +01:00
} ,
{
name : "prepareIDPTemplatesQuery no result" ,
prepare : prepareIDPTemplatesQuery ,
want : want {
sqlExpectations : mockQueries (
regexp . QuoteMeta ( idpTemplatesQuery ) ,
nil ,
nil ,
) ,
err : func ( err error ) ( error , bool ) {
2023-12-08 16:30:55 +02:00
if ! zerrors . IsNotFound ( err ) {
2023-02-15 09:14:59 +01:00
return fmt . Errorf ( "err should be zitadel.NotFoundError got: %w" , err ) , false
}
return nil , true
} ,
} ,
object : & IDPTemplates { Templates : [ ] * IDPTemplate { } } ,
} ,
{
name : "prepareIDPTemplatesQuery ldap idp" ,
prepare : prepareIDPTemplatesQuery ,
want : want {
sqlExpectations : mockQueries (
regexp . QuoteMeta ( idpTemplatesQuery ) ,
idpTemplatesCols ,
[ ] [ ] driver . Value {
{
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeLDAP ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
2023-02-24 15:16:06 +01:00
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
// google config
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
// ldap config
"idp-id" ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "server" } ,
2023-02-15 09:14:59 +01:00
true ,
"base" ,
2023-03-24 16:18:56 +01:00
"dn" ,
2023-02-15 09:14:59 +01:00
nil ,
2023-03-24 16:18:56 +01:00
"user" ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "object" } ,
database . TextArray [ string ] { "filter" } ,
2023-03-24 16:18:56 +01:00
time . Duration ( 30000000000 ) ,
2023-02-15 09:14:59 +01:00
"id" ,
"first" ,
"last" ,
"display" ,
"nickname" ,
"username" ,
"email" ,
"emailVerified" ,
"phone" ,
"phoneVerified" ,
"lang" ,
"avatar" ,
"profile" ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
} ,
} ,
) ,
} ,
object : & IDPTemplates {
SearchResponse : SearchResponse {
Count : 1 ,
} ,
Templates : [ ] * IDPTemplate {
{
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeLDAP ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
LDAPIDPTemplate : & LDAPIDPTemplate {
2023-03-24 16:18:56 +01:00
IDPID : "idp-id" ,
Servers : [ ] string { "server" } ,
StartTLS : true ,
BaseDN : "base" ,
BindDN : "dn" ,
UserBase : "user" ,
UserObjectClasses : [ ] string { "object" } ,
UserFilters : [ ] string { "filter" } ,
Timeout : time . Duration ( 30000000000 ) ,
2023-02-15 09:14:59 +01:00
LDAPAttributes : idp . LDAPAttributes {
IDAttribute : "id" ,
FirstNameAttribute : "first" ,
LastNameAttribute : "last" ,
DisplayNameAttribute : "display" ,
NickNameAttribute : "nickname" ,
PreferredUsernameAttribute : "username" ,
EmailAttribute : "email" ,
EmailVerifiedAttribute : "emailVerified" ,
PhoneAttribute : "phone" ,
PhoneVerifiedAttribute : "phoneVerified" ,
PreferredLanguageAttribute : "lang" ,
AvatarURLAttribute : "avatar" ,
ProfileAttribute : "profile" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "prepareIDPTemplatesQuery no config" ,
prepare : prepareIDPTemplatesQuery ,
want : want {
sqlExpectations : mockQueries (
regexp . QuoteMeta ( idpTemplatesQuery ) ,
idpTemplatesCols ,
[ ] [ ] driver . Value {
{
"idp-id" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeLDAP ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
2023-02-24 15:16:06 +01:00
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
// google config
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
} ,
} ,
) ,
} ,
object : & IDPTemplates {
SearchResponse : SearchResponse {
Count : 1 ,
} ,
Templates : [ ] * IDPTemplate {
{
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeLDAP ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
} ,
} ,
} ,
} ,
{
name : "prepareIDPTemplatesQuery all config types" ,
prepare : prepareIDPTemplatesQuery ,
want : want {
sqlExpectations : mockQueries (
regexp . QuoteMeta ( idpTemplatesQuery ) ,
idpTemplatesCols ,
[ ] [ ] driver . Value {
{
2023-02-21 18:18:28 +01:00
"idp-id-ldap" ,
2023-02-15 09:14:59 +01:00
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeLDAP ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
2023-02-24 15:16:06 +01:00
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
// google config
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
// ldap config
2023-02-21 18:18:28 +01:00
"idp-id-ldap" ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "server" } ,
2023-02-15 09:14:59 +01:00
true ,
"base" ,
2023-03-24 16:18:56 +01:00
"dn" ,
2023-02-15 09:14:59 +01:00
nil ,
2023-03-24 16:18:56 +01:00
"user" ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "object" } ,
database . TextArray [ string ] { "filter" } ,
2023-03-24 16:18:56 +01:00
time . Duration ( 30000000000 ) ,
2023-02-15 09:14:59 +01:00
"id" ,
"first" ,
"last" ,
"display" ,
"nickname" ,
"username" ,
"email" ,
"emailVerified" ,
"phone" ,
"phoneVerified" ,
"lang" ,
"avatar" ,
"profile" ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
} ,
2023-09-29 11:26:14 +02:00
{
"idp-id-saml" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeSAML ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
// google
nil ,
nil ,
nil ,
nil ,
// saml
"idp-id-saml" ,
[ ] byte ( "metadata" ) ,
nil ,
nil ,
"binding" ,
false ,
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
} ,
2023-02-15 09:14:59 +01:00
{
2023-02-21 18:18:28 +01:00
"idp-id-google" ,
2023-02-15 09:14:59 +01:00
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
2023-02-21 18:18:28 +01:00
domain . IDPTypeGoogle ,
2023-02-15 09:14:59 +01:00
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
2023-02-24 15:16:06 +01:00
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-21 18:18:28 +01:00
// google
"idp-id-google" ,
"client_id" ,
nil ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-15 09:14:59 +01:00
} ,
2023-02-24 15:16:06 +01:00
{
"idp-id-oauth" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeOAuth ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
"idp-id-oauth" ,
"client_id" ,
nil ,
"authorization" ,
"token" ,
"user" ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-03-03 11:38:49 +01:00
"id-attribute" ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
} ,
{
"idp-id-oidc" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeOIDC ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
"idp-id-oidc" ,
"issuer" ,
"client_id" ,
nil ,
2023-10-19 12:19:10 +02:00
database . TextArray [ string ] { "profile" } ,
2023-03-16 16:47:22 +01:00
true ,
2023-02-27 16:32:18 +01:00
// jwt
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-27 16:32:18 +01:00
} ,
{
"idp-id-jwt" ,
"ro" ,
testNow ,
testNow ,
uint64 ( 20211109 ) ,
domain . IDPConfigStateActive ,
"idp-name" ,
domain . IDPTypeJWT ,
domain . IdentityProviderTypeOrg ,
true ,
true ,
true ,
true ,
// oauth
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-03 11:38:49 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// oidc
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-16 16:47:22 +01:00
nil ,
2023-02-27 16:32:18 +01:00
// jwt
"idp-id-jwt" ,
"issuer" ,
"jwt" ,
"keys" ,
"header" ,
2023-03-15 07:48:37 +01:00
// azure
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-08 11:17:28 +01:00
// github
nil ,
nil ,
nil ,
nil ,
// github enterprise
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-13 17:34:29 +01:00
// gitlab
nil ,
nil ,
nil ,
nil ,
// gitlab self hosted
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-24 15:16:06 +01:00
// google
nil ,
nil ,
nil ,
nil ,
2023-09-29 11:26:14 +02:00
// saml
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-24 15:16:06 +01:00
// ldap config
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-03-24 16:18:56 +01:00
nil ,
2023-08-31 08:39:16 +02:00
// apple
nil ,
nil ,
nil ,
nil ,
nil ,
nil ,
2023-02-24 15:16:06 +01:00
} ,
2023-02-15 09:14:59 +01:00
} ,
) ,
} ,
object : & IDPTemplates {
SearchResponse : SearchResponse {
2023-09-29 11:26:14 +02:00
Count : 6 ,
2023-02-15 09:14:59 +01:00
} ,
Templates : [ ] * IDPTemplate {
{
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
2023-02-21 18:18:28 +01:00
ID : "idp-id-ldap" ,
2023-02-15 09:14:59 +01:00
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeLDAP ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
LDAPIDPTemplate : & LDAPIDPTemplate {
2023-03-24 16:18:56 +01:00
IDPID : "idp-id-ldap" ,
Servers : [ ] string { "server" } ,
StartTLS : true ,
BaseDN : "base" ,
BindDN : "dn" ,
UserBase : "user" ,
UserObjectClasses : [ ] string { "object" } ,
UserFilters : [ ] string { "filter" } ,
Timeout : time . Duration ( 30000000000 ) ,
2023-02-15 09:14:59 +01:00
LDAPAttributes : idp . LDAPAttributes {
IDAttribute : "id" ,
FirstNameAttribute : "first" ,
LastNameAttribute : "last" ,
DisplayNameAttribute : "display" ,
NickNameAttribute : "nickname" ,
PreferredUsernameAttribute : "username" ,
EmailAttribute : "email" ,
EmailVerifiedAttribute : "emailVerified" ,
PhoneAttribute : "phone" ,
PhoneVerifiedAttribute : "phoneVerified" ,
PreferredLanguageAttribute : "lang" ,
AvatarURLAttribute : "avatar" ,
ProfileAttribute : "profile" ,
} ,
} ,
} ,
2023-09-29 11:26:14 +02:00
{
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id-saml" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeSAML ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
SAMLIDPTemplate : & SAMLIDPTemplate {
IDPID : "idp-id-saml" ,
Metadata : [ ] byte ( "metadata" ) ,
Key : nil ,
Certificate : nil ,
Binding : "binding" ,
WithSignedRequest : false ,
} ,
} ,
2023-02-15 09:14:59 +01:00
{
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
2023-02-21 18:18:28 +01:00
ID : "idp-id-google" ,
2023-02-15 09:14:59 +01:00
State : domain . IDPStateActive ,
Name : "idp-name" ,
2023-02-21 18:18:28 +01:00
Type : domain . IDPTypeGoogle ,
2023-02-15 09:14:59 +01:00
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
2023-02-21 18:18:28 +01:00
GoogleIDPTemplate : & GoogleIDPTemplate {
IDPID : "idp-id-google" ,
ClientID : "client_id" ,
ClientSecret : nil ,
Scopes : [ ] string { "profile" } ,
} ,
2023-02-15 09:14:59 +01:00
} ,
2023-02-24 15:16:06 +01:00
{
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id-oauth" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeOAuth ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
OAuthIDPTemplate : & OAuthIDPTemplate {
IDPID : "idp-id-oauth" ,
ClientID : "client_id" ,
ClientSecret : nil ,
AuthorizationEndpoint : "authorization" ,
TokenEndpoint : "token" ,
UserEndpoint : "user" ,
Scopes : [ ] string { "profile" } ,
2023-03-03 11:38:49 +01:00
IDAttribute : "id-attribute" ,
2023-02-24 15:16:06 +01:00
} ,
} ,
2023-02-27 16:32:18 +01:00
{
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id-oidc" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeOIDC ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
OIDCIDPTemplate : & OIDCIDPTemplate {
2023-03-16 16:47:22 +01:00
IDPID : "idp-id-oidc" ,
Issuer : "issuer" ,
ClientID : "client_id" ,
ClientSecret : nil ,
Scopes : [ ] string { "profile" } ,
IsIDTokenMapping : true ,
2023-02-27 16:32:18 +01:00
} ,
} ,
{
CreationDate : testNow ,
ChangeDate : testNow ,
Sequence : 20211109 ,
ResourceOwner : "ro" ,
ID : "idp-id-jwt" ,
State : domain . IDPStateActive ,
Name : "idp-name" ,
Type : domain . IDPTypeJWT ,
OwnerType : domain . IdentityProviderTypeOrg ,
IsCreationAllowed : true ,
IsLinkingAllowed : true ,
IsAutoCreation : true ,
IsAutoUpdate : true ,
JWTIDPTemplate : & JWTIDPTemplate {
IDPID : "idp-id-jwt" ,
Issuer : "issuer" ,
Endpoint : "jwt" ,
KeysEndpoint : "keys" ,
HeaderName : "header" ,
} ,
} ,
2023-02-15 09:14:59 +01:00
} ,
} ,
} ,
{
name : "prepareIDPTemplatesQuery sql err" ,
prepare : prepareIDPTemplatesQuery ,
want : want {
sqlExpectations : mockQueryErr (
regexp . QuoteMeta ( idpTemplatesQuery ) ,
sql . ErrConnDone ,
) ,
err : func ( err error ) ( error , bool ) {
if ! errors . Is ( err , sql . ErrConnDone ) {
return fmt . Errorf ( "err should be sql.ErrConnDone got: %w" , err ) , false
}
return nil , true
} ,
} ,
2023-08-22 12:49:22 +02:00
object : ( * IDPTemplates ) ( nil ) ,
2023-02-15 09:14:59 +01:00
} ,
}
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
2023-02-27 22:36:43 +01:00
assertPrepare ( t , tt . prepare , tt . object , tt . want . sqlExpectations , tt . want . err , defaultPrepareArgs ... )
2023-02-15 09:14:59 +01:00
} )
}
}