diff --git a/internal/query/idp_login_policy_link_test.go b/internal/query/idp_login_policy_link_test.go index f886b9f68a..2a1802da64 100644 --- a/internal/query/idp_login_policy_link_test.go +++ b/internal/query/idp_login_policy_link_test.go @@ -13,12 +13,12 @@ import ( var ( loginPolicyIDPLinksQuery = regexp.QuoteMeta(`SELECT projections.idp_login_policy_links4.idp_id,` + - ` projections.idp_templates2.name,` + - ` projections.idp_templates2.type,` + - ` projections.idp_templates2.owner_type,` + + ` projections.idp_templates3.name,` + + ` projections.idp_templates3.type,` + + ` projections.idp_templates3.owner_type,` + ` COUNT(*) OVER ()` + ` FROM projections.idp_login_policy_links4` + - ` LEFT JOIN projections.idp_templates2 ON projections.idp_login_policy_links4.idp_id = projections.idp_templates2.id AND projections.idp_login_policy_links4.instance_id = projections.idp_templates2.instance_id` + + ` LEFT JOIN projections.idp_templates3 ON projections.idp_login_policy_links4.idp_id = projections.idp_templates3.id AND projections.idp_login_policy_links4.instance_id = projections.idp_templates3.instance_id` + ` AS OF SYSTEM TIME '-1 ms'`) loginPolicyIDPLinksCols = []string{ "idp_id", diff --git a/internal/query/idp_template_test.go b/internal/query/idp_template_test.go index 3fff2c0088..d0470eb0da 100644 --- a/internal/query/idp_template_test.go +++ b/internal/query/idp_template_test.go @@ -15,74 +15,74 @@ import ( ) var ( - idpTemplateQuery = `SELECT projections.idp_templates2.id,` + - ` projections.idp_templates2.resource_owner,` + - ` projections.idp_templates2.creation_date,` + - ` projections.idp_templates2.change_date,` + - ` projections.idp_templates2.sequence,` + - ` projections.idp_templates2.state,` + - ` projections.idp_templates2.name,` + - ` projections.idp_templates2.type,` + - ` projections.idp_templates2.owner_type,` + - ` projections.idp_templates2.is_creation_allowed,` + - ` projections.idp_templates2.is_linking_allowed,` + - ` projections.idp_templates2.is_auto_creation,` + - ` projections.idp_templates2.is_auto_update,` + + idpTemplateQuery = `SELECT projections.idp_templates3.id,` + + ` projections.idp_templates3.resource_owner,` + + ` projections.idp_templates3.creation_date,` + + ` projections.idp_templates3.change_date,` + + ` projections.idp_templates3.sequence,` + + ` projections.idp_templates3.state,` + + ` projections.idp_templates3.name,` + + ` projections.idp_templates3.type,` + + ` projections.idp_templates3.owner_type,` + + ` projections.idp_templates3.is_creation_allowed,` + + ` projections.idp_templates3.is_linking_allowed,` + + ` projections.idp_templates3.is_auto_creation,` + + ` projections.idp_templates3.is_auto_update,` + // oauth - ` projections.idp_templates2_oauth2.idp_id,` + - ` projections.idp_templates2_oauth2.client_id,` + - ` projections.idp_templates2_oauth2.client_secret,` + - ` projections.idp_templates2_oauth2.authorization_endpoint,` + - ` projections.idp_templates2_oauth2.token_endpoint,` + - ` projections.idp_templates2_oauth2.user_endpoint,` + - ` projections.idp_templates2_oauth2.scopes,` + - ` projections.idp_templates2_oauth2.id_attribute,` + + ` projections.idp_templates3_oauth2.idp_id,` + + ` projections.idp_templates3_oauth2.client_id,` + + ` projections.idp_templates3_oauth2.client_secret,` + + ` projections.idp_templates3_oauth2.authorization_endpoint,` + + ` projections.idp_templates3_oauth2.token_endpoint,` + + ` projections.idp_templates3_oauth2.user_endpoint,` + + ` projections.idp_templates3_oauth2.scopes,` + + ` projections.idp_templates3_oauth2.id_attribute,` + // oidc - ` projections.idp_templates2_oidc.idp_id,` + - ` projections.idp_templates2_oidc.issuer,` + - ` projections.idp_templates2_oidc.client_id,` + - ` projections.idp_templates2_oidc.client_secret,` + - ` projections.idp_templates2_oidc.scopes,` + + ` projections.idp_templates3_oidc.idp_id,` + + ` projections.idp_templates3_oidc.issuer,` + + ` projections.idp_templates3_oidc.client_id,` + + ` projections.idp_templates3_oidc.client_secret,` + + ` projections.idp_templates3_oidc.scopes,` + // jwt - ` projections.idp_templates2_jwt.idp_id,` + - ` projections.idp_templates2_jwt.issuer,` + - ` projections.idp_templates2_jwt.jwt_endpoint,` + - ` projections.idp_templates2_jwt.keys_endpoint,` + - ` projections.idp_templates2_jwt.header_name,` + + ` projections.idp_templates3_jwt.idp_id,` + + ` projections.idp_templates3_jwt.issuer,` + + ` projections.idp_templates3_jwt.jwt_endpoint,` + + ` projections.idp_templates3_jwt.keys_endpoint,` + + ` projections.idp_templates3_jwt.header_name,` + // google - ` projections.idp_templates2_google.idp_id,` + - ` projections.idp_templates2_google.client_id,` + - ` projections.idp_templates2_google.client_secret,` + - ` projections.idp_templates2_google.scopes,` + + ` projections.idp_templates3_google.idp_id,` + + ` projections.idp_templates3_google.client_id,` + + ` projections.idp_templates3_google.client_secret,` + + ` projections.idp_templates3_google.scopes,` + // ldap - ` projections.idp_templates2_ldap.idp_id,` + - ` projections.idp_templates2_ldap.host,` + - ` projections.idp_templates2_ldap.port,` + - ` projections.idp_templates2_ldap.tls,` + - ` projections.idp_templates2_ldap.base_dn,` + - ` projections.idp_templates2_ldap.user_object_class,` + - ` projections.idp_templates2_ldap.user_unique_attribute,` + - ` projections.idp_templates2_ldap.admin,` + - ` projections.idp_templates2_ldap.password,` + - ` projections.idp_templates2_ldap.id_attribute,` + - ` projections.idp_templates2_ldap.first_name_attribute,` + - ` projections.idp_templates2_ldap.last_name_attribute,` + - ` projections.idp_templates2_ldap.display_name_attribute,` + - ` projections.idp_templates2_ldap.nick_name_attribute,` + - ` projections.idp_templates2_ldap.preferred_username_attribute,` + - ` projections.idp_templates2_ldap.email_attribute,` + - ` projections.idp_templates2_ldap.email_verified,` + - ` projections.idp_templates2_ldap.phone_attribute,` + - ` projections.idp_templates2_ldap.phone_verified_attribute,` + - ` projections.idp_templates2_ldap.preferred_language_attribute,` + - ` projections.idp_templates2_ldap.avatar_url_attribute,` + - ` projections.idp_templates2_ldap.profile_attribute` + - ` FROM projections.idp_templates2` + - ` LEFT JOIN projections.idp_templates2_oauth2 ON projections.idp_templates2.id = projections.idp_templates2_oauth2.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_oauth2.instance_id` + - ` LEFT JOIN projections.idp_templates2_oidc ON projections.idp_templates2.id = projections.idp_templates2_oidc.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_oidc.instance_id` + - ` LEFT JOIN projections.idp_templates2_jwt ON projections.idp_templates2.id = projections.idp_templates2_jwt.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_jwt.instance_id` + - ` LEFT JOIN projections.idp_templates2_google ON projections.idp_templates2.id = projections.idp_templates2_google.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_google.instance_id` + - ` LEFT JOIN projections.idp_templates2_ldap ON projections.idp_templates2.id = projections.idp_templates2_ldap.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_ldap.instance_id` + + ` projections.idp_templates3_ldap.idp_id,` + + ` projections.idp_templates3_ldap.host,` + + ` projections.idp_templates3_ldap.port,` + + ` projections.idp_templates3_ldap.tls,` + + ` projections.idp_templates3_ldap.base_dn,` + + ` projections.idp_templates3_ldap.user_object_class,` + + ` projections.idp_templates3_ldap.user_unique_attribute,` + + ` projections.idp_templates3_ldap.admin,` + + ` projections.idp_templates3_ldap.password,` + + ` projections.idp_templates3_ldap.id_attribute,` + + ` projections.idp_templates3_ldap.first_name_attribute,` + + ` projections.idp_templates3_ldap.last_name_attribute,` + + ` projections.idp_templates3_ldap.display_name_attribute,` + + ` projections.idp_templates3_ldap.nick_name_attribute,` + + ` projections.idp_templates3_ldap.preferred_username_attribute,` + + ` projections.idp_templates3_ldap.email_attribute,` + + ` projections.idp_templates3_ldap.email_verified,` + + ` projections.idp_templates3_ldap.phone_attribute,` + + ` projections.idp_templates3_ldap.phone_verified_attribute,` + + ` projections.idp_templates3_ldap.preferred_language_attribute,` + + ` projections.idp_templates3_ldap.avatar_url_attribute,` + + ` projections.idp_templates3_ldap.profile_attribute` + + ` FROM projections.idp_templates3` + + ` LEFT JOIN projections.idp_templates3_oauth2 ON projections.idp_templates3.id = projections.idp_templates3_oauth2.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_oauth2.instance_id` + + ` LEFT JOIN projections.idp_templates3_oidc ON projections.idp_templates3.id = projections.idp_templates3_oidc.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_oidc.instance_id` + + ` LEFT JOIN projections.idp_templates3_jwt ON projections.idp_templates3.id = projections.idp_templates3_jwt.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_jwt.instance_id` + + ` LEFT JOIN projections.idp_templates3_google ON projections.idp_templates3.id = projections.idp_templates3_google.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_google.instance_id` + + ` LEFT JOIN projections.idp_templates3_ldap ON projections.idp_templates3.id = projections.idp_templates3_ldap.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_ldap.instance_id` + ` AS OF SYSTEM TIME '-1 ms'` idpTemplateCols = []string{ "id", @@ -148,75 +148,75 @@ var ( "avatar_url_attribute", "profile_attribute", } - idpTemplatesQuery = `SELECT projections.idp_templates2.id,` + - ` projections.idp_templates2.resource_owner,` + - ` projections.idp_templates2.creation_date,` + - ` projections.idp_templates2.change_date,` + - ` projections.idp_templates2.sequence,` + - ` projections.idp_templates2.state,` + - ` projections.idp_templates2.name,` + - ` projections.idp_templates2.type,` + - ` projections.idp_templates2.owner_type,` + - ` projections.idp_templates2.is_creation_allowed,` + - ` projections.idp_templates2.is_linking_allowed,` + - ` projections.idp_templates2.is_auto_creation,` + - ` projections.idp_templates2.is_auto_update,` + + idpTemplatesQuery = `SELECT projections.idp_templates3.id,` + + ` projections.idp_templates3.resource_owner,` + + ` projections.idp_templates3.creation_date,` + + ` projections.idp_templates3.change_date,` + + ` projections.idp_templates3.sequence,` + + ` projections.idp_templates3.state,` + + ` projections.idp_templates3.name,` + + ` projections.idp_templates3.type,` + + ` projections.idp_templates3.owner_type,` + + ` projections.idp_templates3.is_creation_allowed,` + + ` projections.idp_templates3.is_linking_allowed,` + + ` projections.idp_templates3.is_auto_creation,` + + ` projections.idp_templates3.is_auto_update,` + // oauth - ` projections.idp_templates2_oauth2.idp_id,` + - ` projections.idp_templates2_oauth2.client_id,` + - ` projections.idp_templates2_oauth2.client_secret,` + - ` projections.idp_templates2_oauth2.authorization_endpoint,` + - ` projections.idp_templates2_oauth2.token_endpoint,` + - ` projections.idp_templates2_oauth2.user_endpoint,` + - ` projections.idp_templates2_oauth2.scopes,` + - ` projections.idp_templates2_oauth2.id_attribute,` + + ` projections.idp_templates3_oauth2.idp_id,` + + ` projections.idp_templates3_oauth2.client_id,` + + ` projections.idp_templates3_oauth2.client_secret,` + + ` projections.idp_templates3_oauth2.authorization_endpoint,` + + ` projections.idp_templates3_oauth2.token_endpoint,` + + ` projections.idp_templates3_oauth2.user_endpoint,` + + ` projections.idp_templates3_oauth2.scopes,` + + ` projections.idp_templates3_oauth2.id_attribute,` + // oidc - ` projections.idp_templates2_oidc.idp_id,` + - ` projections.idp_templates2_oidc.issuer,` + - ` projections.idp_templates2_oidc.client_id,` + - ` projections.idp_templates2_oidc.client_secret,` + - ` projections.idp_templates2_oidc.scopes,` + + ` projections.idp_templates3_oidc.idp_id,` + + ` projections.idp_templates3_oidc.issuer,` + + ` projections.idp_templates3_oidc.client_id,` + + ` projections.idp_templates3_oidc.client_secret,` + + ` projections.idp_templates3_oidc.scopes,` + // jwt - ` projections.idp_templates2_jwt.idp_id,` + - ` projections.idp_templates2_jwt.issuer,` + - ` projections.idp_templates2_jwt.jwt_endpoint,` + - ` projections.idp_templates2_jwt.keys_endpoint,` + - ` projections.idp_templates2_jwt.header_name,` + + ` projections.idp_templates3_jwt.idp_id,` + + ` projections.idp_templates3_jwt.issuer,` + + ` projections.idp_templates3_jwt.jwt_endpoint,` + + ` projections.idp_templates3_jwt.keys_endpoint,` + + ` projections.idp_templates3_jwt.header_name,` + // google - ` projections.idp_templates2_google.idp_id,` + - ` projections.idp_templates2_google.client_id,` + - ` projections.idp_templates2_google.client_secret,` + - ` projections.idp_templates2_google.scopes,` + + ` projections.idp_templates3_google.idp_id,` + + ` projections.idp_templates3_google.client_id,` + + ` projections.idp_templates3_google.client_secret,` + + ` projections.idp_templates3_google.scopes,` + // ldap - ` projections.idp_templates2_ldap.idp_id,` + - ` projections.idp_templates2_ldap.host,` + - ` projections.idp_templates2_ldap.port,` + - ` projections.idp_templates2_ldap.tls,` + - ` projections.idp_templates2_ldap.base_dn,` + - ` projections.idp_templates2_ldap.user_object_class,` + - ` projections.idp_templates2_ldap.user_unique_attribute,` + - ` projections.idp_templates2_ldap.admin,` + - ` projections.idp_templates2_ldap.password,` + - ` projections.idp_templates2_ldap.id_attribute,` + - ` projections.idp_templates2_ldap.first_name_attribute,` + - ` projections.idp_templates2_ldap.last_name_attribute,` + - ` projections.idp_templates2_ldap.display_name_attribute,` + - ` projections.idp_templates2_ldap.nick_name_attribute,` + - ` projections.idp_templates2_ldap.preferred_username_attribute,` + - ` projections.idp_templates2_ldap.email_attribute,` + - ` projections.idp_templates2_ldap.email_verified,` + - ` projections.idp_templates2_ldap.phone_attribute,` + - ` projections.idp_templates2_ldap.phone_verified_attribute,` + - ` projections.idp_templates2_ldap.preferred_language_attribute,` + - ` projections.idp_templates2_ldap.avatar_url_attribute,` + - ` projections.idp_templates2_ldap.profile_attribute,` + + ` projections.idp_templates3_ldap.idp_id,` + + ` projections.idp_templates3_ldap.host,` + + ` projections.idp_templates3_ldap.port,` + + ` projections.idp_templates3_ldap.tls,` + + ` projections.idp_templates3_ldap.base_dn,` + + ` projections.idp_templates3_ldap.user_object_class,` + + ` projections.idp_templates3_ldap.user_unique_attribute,` + + ` projections.idp_templates3_ldap.admin,` + + ` projections.idp_templates3_ldap.password,` + + ` projections.idp_templates3_ldap.id_attribute,` + + ` projections.idp_templates3_ldap.first_name_attribute,` + + ` projections.idp_templates3_ldap.last_name_attribute,` + + ` projections.idp_templates3_ldap.display_name_attribute,` + + ` projections.idp_templates3_ldap.nick_name_attribute,` + + ` projections.idp_templates3_ldap.preferred_username_attribute,` + + ` projections.idp_templates3_ldap.email_attribute,` + + ` projections.idp_templates3_ldap.email_verified,` + + ` projections.idp_templates3_ldap.phone_attribute,` + + ` projections.idp_templates3_ldap.phone_verified_attribute,` + + ` projections.idp_templates3_ldap.preferred_language_attribute,` + + ` projections.idp_templates3_ldap.avatar_url_attribute,` + + ` projections.idp_templates3_ldap.profile_attribute,` + ` COUNT(*) OVER ()` + - ` FROM projections.idp_templates2` + - ` LEFT JOIN projections.idp_templates2_oauth2 ON projections.idp_templates2.id = projections.idp_templates2_oauth2.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_oauth2.instance_id` + - ` LEFT JOIN projections.idp_templates2_oidc ON projections.idp_templates2.id = projections.idp_templates2_oidc.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_oidc.instance_id` + - ` LEFT JOIN projections.idp_templates2_jwt ON projections.idp_templates2.id = projections.idp_templates2_jwt.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_jwt.instance_id` + - ` LEFT JOIN projections.idp_templates2_google ON projections.idp_templates2.id = projections.idp_templates2_google.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_google.instance_id` + - ` LEFT JOIN projections.idp_templates2_ldap ON projections.idp_templates2.id = projections.idp_templates2_ldap.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_ldap.instance_id` + + ` FROM projections.idp_templates3` + + ` LEFT JOIN projections.idp_templates3_oauth2 ON projections.idp_templates3.id = projections.idp_templates3_oauth2.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_oauth2.instance_id` + + ` LEFT JOIN projections.idp_templates3_oidc ON projections.idp_templates3.id = projections.idp_templates3_oidc.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_oidc.instance_id` + + ` LEFT JOIN projections.idp_templates3_jwt ON projections.idp_templates3.id = projections.idp_templates3_jwt.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_jwt.instance_id` + + ` LEFT JOIN projections.idp_templates3_google ON projections.idp_templates3.id = projections.idp_templates3_google.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_google.instance_id` + + ` LEFT JOIN projections.idp_templates3_ldap ON projections.idp_templates3.id = projections.idp_templates3_ldap.idp_id AND projections.idp_templates3.instance_id = projections.idp_templates3_ldap.instance_id` + ` AS OF SYSTEM TIME '-1 ms'` idpTemplatesCols = []string{ "id", diff --git a/internal/query/idp_user_link_test.go b/internal/query/idp_user_link_test.go index 0343af9261..f42736a792 100644 --- a/internal/query/idp_user_link_test.go +++ b/internal/query/idp_user_link_test.go @@ -14,14 +14,14 @@ import ( var ( idpUserLinksQuery = regexp.QuoteMeta(`SELECT projections.idp_user_links3.idp_id,` + ` projections.idp_user_links3.user_id,` + - ` projections.idp_templates2.name,` + + ` projections.idp_templates3.name,` + ` projections.idp_user_links3.external_user_id,` + ` projections.idp_user_links3.display_name,` + - ` projections.idp_templates2.type,` + + ` projections.idp_templates3.type,` + ` projections.idp_user_links3.resource_owner,` + ` COUNT(*) OVER ()` + ` FROM projections.idp_user_links3` + - ` LEFT JOIN projections.idp_templates2 ON projections.idp_user_links3.idp_id = projections.idp_templates2.id AND projections.idp_user_links3.instance_id = projections.idp_templates2.instance_id` + + ` LEFT JOIN projections.idp_templates3 ON projections.idp_user_links3.idp_id = projections.idp_templates3.id AND projections.idp_user_links3.instance_id = projections.idp_templates3.instance_id` + ` AS OF SYSTEM TIME '-1 ms'`) idpUserLinksCols = []string{ "idp_id", diff --git a/internal/query/projection/idp_template.go b/internal/query/projection/idp_template.go index 6f392bfa15..7a7cd13af7 100644 --- a/internal/query/projection/idp_template.go +++ b/internal/query/projection/idp_template.go @@ -17,7 +17,7 @@ import ( ) const ( - IDPTemplateTable = "projections.idp_templates2" + IDPTemplateTable = "projections.idp_templates3" IDPTemplateOAuthTable = IDPTemplateTable + "_" + IDPTemplateOAuthSuffix IDPTemplateOIDCTable = IDPTemplateTable + "_" + IDPTemplateOIDCSuffix IDPTemplateJWTTable = IDPTemplateTable + "_" + IDPTemplateJWTSuffix @@ -707,8 +707,8 @@ func (p *idpTemplateProjection) reduceOldConfigChanged(event eventstore.Event) ( event, cols, []handler.Condition{ - handler.NewCond(OIDCIDCol, idpEvent.ConfigID), - handler.NewCond(OIDCInstanceIDCol, idpEvent.Aggregate().InstanceID), + handler.NewCond(IDPTemplateIDCol, idpEvent.ConfigID), + handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID), }, ), nil } diff --git a/internal/query/projection/idp_template_test.go b/internal/query/projection/idp_template_test.go index 3c9ed82f8f..9950922e8a 100644 --- a/internal/query/projection/idp_template_test.go +++ b/internal/query/projection/idp_template_test.go @@ -41,7 +41,7 @@ func TestIDPTemplateProjection_reducesRemove(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_templates2 WHERE (instance_id = $1)", + expectedStmt: "DELETE FROM projections.idp_templates3 WHERE (instance_id = $1)", expectedArgs: []interface{}{ "agg-id", }, @@ -67,7 +67,7 @@ func TestIDPTemplateProjection_reducesRemove(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (change_date, sequence, owner_removed) = ($1, $2, $3) WHERE (instance_id = $4) AND (resource_owner = $5)", + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence, owner_removed) = ($1, $2, $3) WHERE (instance_id = $4) AND (resource_owner = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -99,7 +99,7 @@ func TestIDPTemplateProjection_reducesRemove(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_templates2 WHERE (id = $1) AND (instance_id = $2)", + expectedStmt: "DELETE FROM projections.idp_templates3 WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -170,7 +170,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -189,7 +189,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_oauth2 (idp_id, instance_id, client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes, id_attribute) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.idp_templates3_oauth2 (idp_id, instance_id, client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes, id_attribute) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -241,7 +241,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -260,7 +260,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_oauth2 (idp_id, instance_id, client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes, id_attribute) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", + expectedStmt: "INSERT INTO projections.idp_templates3_oauth2 (idp_id, instance_id, client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes, id_attribute) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -298,7 +298,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.idp_templates3 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ true, anyArg{}, @@ -308,7 +308,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_oauth2 SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.idp_templates3_oauth2 SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "id", "idp-id", @@ -354,7 +354,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (name, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (instance_id = $9)", + expectedStmt: "UPDATE projections.idp_templates3 SET (name, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (instance_id = $9)", expectedArgs: []interface{}{ "custom-zitadel-instance", true, @@ -368,7 +368,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_oauth2 SET (client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes, id_attribute) = ($1, $2, $3, $4, $5, $6, $7) WHERE (idp_id = $8) AND (instance_id = $9)", + expectedStmt: "UPDATE projections.idp_templates3_oauth2 SET (client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes, id_attribute) = ($1, $2, $3, $4, $5, $6, $7) WHERE (idp_id = $8) AND (instance_id = $9)", expectedArgs: []interface{}{ "client_id", anyArg{}, @@ -441,7 +441,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -460,7 +460,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_google (idp_id, instance_id, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5)", + expectedStmt: "INSERT INTO projections.idp_templates3_google (idp_id, instance_id, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -503,7 +503,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -522,7 +522,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_google (idp_id, instance_id, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5)", + expectedStmt: "INSERT INTO projections.idp_templates3_google (idp_id, instance_id, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -556,7 +556,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.idp_templates3 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ true, anyArg{}, @@ -566,7 +566,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_google SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.idp_templates3_google SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "id", "idp-id", @@ -607,7 +607,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)", + expectedStmt: "UPDATE projections.idp_templates3 SET (is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)", expectedArgs: []interface{}{ true, true, @@ -620,7 +620,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_google SET (client_id, client_secret, scopes) = ($1, $2, $3) WHERE (idp_id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.idp_templates3_google SET (client_id, client_secret, scopes) = ($1, $2, $3) WHERE (idp_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ "client_id", anyArg{}, @@ -708,7 +708,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -727,7 +727,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_ldap (idp_id, instance_id, host, port, tls, base_dn, user_object_class, user_unique_attribute, admin, password, 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) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)", + expectedStmt: "INSERT INTO projections.idp_templates3_ldap (idp_id, instance_id, host, port, tls, base_dn, user_object_class, user_unique_attribute, admin, password, 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) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -807,7 +807,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -826,7 +826,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_ldap (idp_id, instance_id, host, port, tls, base_dn, user_object_class, user_unique_attribute, admin, password, 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) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)", + expectedStmt: "INSERT INTO projections.idp_templates3_ldap (idp_id, instance_id, host, port, tls, base_dn, user_object_class, user_unique_attribute, admin, password, 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) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -878,7 +878,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (name, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.idp_templates3 SET (name, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ "custom-zitadel-instance", anyArg{}, @@ -888,7 +888,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_ldap SET host = $1 WHERE (idp_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.idp_templates3_ldap SET host = $1 WHERE (idp_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "host", "idp-id", @@ -948,7 +948,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (name, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (instance_id = $9)", + expectedStmt: "UPDATE projections.idp_templates3 SET (name, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (instance_id = $9)", expectedArgs: []interface{}{ "custom-zitadel-instance", true, @@ -962,7 +962,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_ldap SET (host, port, tls, base_dn, user_object_class, user_unique_attribute, admin, password, 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) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21) WHERE (idp_id = $22) AND (instance_id = $23)", + expectedStmt: "UPDATE projections.idp_templates3_ldap SET (host, port, tls, base_dn, user_object_class, user_unique_attribute, admin, password, 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) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21) WHERE (idp_id = $22) AND (instance_id = $23)", expectedArgs: []interface{}{ "host", "port", @@ -1010,7 +1010,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (change_date, sequence, owner_removed) = ($1, $2, $3) WHERE (instance_id = $4) AND (resource_owner = $5)", + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence, owner_removed) = ($1, $2, $3) WHERE (instance_id = $4) AND (resource_owner = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -1080,7 +1080,7 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -1099,7 +1099,7 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_oidc (idp_id, instance_id, issuer, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5, $6)", + expectedStmt: "INSERT INTO projections.idp_templates3_oidc (idp_id, instance_id, issuer, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5, $6)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -1144,7 +1144,7 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -1163,7 +1163,7 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_oidc (idp_id, instance_id, issuer, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5, $6)", + expectedStmt: "INSERT INTO projections.idp_templates3_oidc (idp_id, instance_id, issuer, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5, $6)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -1198,7 +1198,7 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.idp_templates3 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ true, anyArg{}, @@ -1208,7 +1208,7 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_oidc SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.idp_templates3_oidc SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "id", "idp-id", @@ -1250,7 +1250,7 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)", + expectedStmt: "UPDATE projections.idp_templates3 SET (is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)", expectedArgs: []interface{}{ true, true, @@ -1263,7 +1263,7 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_oidc SET (client_id, client_secret, issuer, scopes) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)", + expectedStmt: "UPDATE projections.idp_templates3_oidc SET (client_id, client_secret, issuer, scopes) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ "client_id", anyArg{}, @@ -1293,6 +1293,591 @@ func TestIDPTemplateProjection_reducesOIDC(t *testing.T) { } } +func TestIDPTemplateProjection_reducesOldConfig(t *testing.T) { + type args struct { + event func(t *testing.T) eventstore.Event + } + tests := []struct { + name string + args args + reduce func(event eventstore.Event) (*handler.Statement, error) + want wantReduce + }{ + { + name: "instance reduceOldConfigAdded", + args: args{ + event: getEvent(testEvent( + repository.EventType(instance.IDPConfigAddedEventType), + instance.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "name": "custom-zitadel-instance", + "idpType": 0, + "stylingType": 0, + "autoRegister": true +}`), + ), instance.IDPConfigAddedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldConfigAdded, + want: wantReduce{ + aggregateType: eventstore.AggregateType("instance"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedArgs: []interface{}{ + "idp-config-id", + anyArg{}, + anyArg{}, + uint64(15), + "ro-id", + "instance-id", + domain.IDPStateActive, + "custom-zitadel-instance", + domain.IdentityProviderTypeSystem, + domain.IDPTypeUnspecified, + true, + true, + true, + false, + }, + }, + }, + }, + }, + }, + { + name: "org reduceOldConfigAdded", + args: args{ + event: getEvent(testEvent( + repository.EventType(org.IDPConfigAddedEventType), + org.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "name": "custom-zitadel-instance", + "idpType": 0, + "stylingType": 0, + "autoRegister": true +}`), + ), org.IDPConfigAddedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldConfigAdded, + want: wantReduce{ + aggregateType: eventstore.AggregateType("org"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedArgs: []interface{}{ + "idp-config-id", + anyArg{}, + anyArg{}, + uint64(15), + "ro-id", + "instance-id", + domain.IDPStateActive, + "custom-zitadel-instance", + domain.IdentityProviderTypeOrg, + domain.IDPTypeUnspecified, + true, + true, + true, + false, + }, + }, + }, + }, + }, + }, + { + name: "instance reduceOldConfigChanged", + args: args{ + event: getEvent(testEvent( + repository.EventType(instance.IDPConfigChangedEventType), + instance.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "name": "custom-zitadel-instance", + "stylingType": 1, + "autoRegister": true + }`), + ), instance.IDPConfigChangedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldConfigChanged, + want: wantReduce{ + aggregateType: eventstore.AggregateType("instance"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (name, is_auto_creation, change_date, sequence) = ($1, $2, $3, $4) WHERE (id = $5) AND (instance_id = $6)", + expectedArgs: []interface{}{ + "custom-zitadel-instance", + true, + anyArg{}, + uint64(15), + "idp-config-id", + "instance-id", + }, + }, + }, + }, + }, + }, + { + name: "org reduceOldConfigChanged", + args: args{ + event: getEvent(testEvent( + repository.EventType(org.IDPConfigChangedEventType), + org.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "name": "custom-zitadel-instance", + "stylingType": 1, + "autoRegister": true + }`), + ), org.IDPConfigChangedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldConfigChanged, + want: wantReduce{ + aggregateType: eventstore.AggregateType("org"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (name, is_auto_creation, change_date, sequence) = ($1, $2, $3, $4) WHERE (id = $5) AND (instance_id = $6)", + expectedArgs: []interface{}{ + "custom-zitadel-instance", + true, + anyArg{}, + uint64(15), + "idp-config-id", + "instance-id", + }, + }, + }, + }, + }, + }, + { + name: "instance reduceOldOIDCConfigAdded", + args: args{ + event: getEvent(testEvent( + repository.EventType(instance.IDPOIDCConfigAddedEventType), + instance.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "clientId": "client-id", + "clientSecret": { + "cryptoType": 0, + "algorithm": "RSA-265", + "keyId": "key-id" + }, + "issuer": "issuer", + "scopes": ["profile"], + "idpDisplayNameMapping": 0, + "usernameMapping": 1 + }`), + ), instance.IDPOIDCConfigAddedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldOIDCConfigAdded, + want: wantReduce{ + aggregateType: eventstore.AggregateType("instance"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedArgs: []interface{}{ + anyArg{}, + uint64(15), + domain.IDPTypeOIDC, + "idp-config-id", + "instance-id", + }, + }, + { + expectedStmt: "INSERT INTO projections.idp_templates3_oidc (idp_id, instance_id, issuer, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5, $6)", + expectedArgs: []interface{}{ + "idp-config-id", + "instance-id", + "issuer", + "client-id", + anyArg{}, + database.StringArray{"profile"}, + }, + }, + }, + }, + }, + }, + { + name: "org reduceOldOIDCConfigAdded", + args: args{ + event: getEvent(testEvent( + repository.EventType(org.IDPOIDCConfigAddedEventType), + org.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "clientId": "client-id", + "clientSecret": { + "cryptoType": 0, + "algorithm": "RSA-265", + "keyId": "key-id" + }, + "issuer": "issuer", + "scopes": ["profile"], + "idpDisplayNameMapping": 0, + "usernameMapping": 1 + }`), + ), org.IDPOIDCConfigAddedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldOIDCConfigAdded, + want: wantReduce{ + aggregateType: eventstore.AggregateType("org"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedArgs: []interface{}{ + anyArg{}, + uint64(15), + domain.IDPTypeOIDC, + "idp-config-id", + "instance-id", + }, + }, + { + expectedStmt: "INSERT INTO projections.idp_templates3_oidc (idp_id, instance_id, issuer, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5, $6)", + expectedArgs: []interface{}{ + "idp-config-id", + "instance-id", + "issuer", + "client-id", + anyArg{}, + database.StringArray{"profile"}, + }, + }, + }, + }, + }, + }, + { + name: "instance reduceOldOIDCConfigChanged", + args: args{ + event: getEvent(testEvent( + repository.EventType(instance.IDPOIDCConfigChangedEventType), + instance.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "clientId": "client-id", + "clientSecret": { + "cryptoType": 0, + "algorithm": "RSA-265", + "keyId": "key-id" + }, + "issuer": "issuer", + "scopes": ["profile"], + "idpDisplayNameMapping": 0, + "usernameMapping": 1 + }`), + ), instance.IDPOIDCConfigChangedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldOIDCConfigChanged, + want: wantReduce{ + aggregateType: eventstore.AggregateType("instance"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedArgs: []interface{}{ + anyArg{}, + uint64(15), + "idp-config-id", + "instance-id", + }, + }, + { + expectedStmt: "UPDATE projections.idp_templates3_oidc SET (client_id, client_secret, issuer, scopes) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)", + expectedArgs: []interface{}{ + "client-id", + anyArg{}, + "issuer", + database.StringArray{"profile"}, + "idp-config-id", + "instance-id", + }, + }, + }, + }, + }, + }, + { + name: "org reduceOldOIDCConfigChanged", + args: args{ + event: getEvent(testEvent( + repository.EventType(org.IDPOIDCConfigChangedEventType), + org.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "clientId": "client-id", + "clientSecret": { + "cryptoType": 0, + "algorithm": "RSA-265", + "keyId": "key-id" + }, + "issuer": "issuer", + "scopes": ["profile"], + "idpDisplayNameMapping": 0, + "usernameMapping": 1 + }`), + ), org.IDPOIDCConfigChangedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldOIDCConfigChanged, + want: wantReduce{ + aggregateType: eventstore.AggregateType("org"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedArgs: []interface{}{ + anyArg{}, + uint64(15), + "idp-config-id", + "instance-id", + }, + }, + { + expectedStmt: "UPDATE projections.idp_templates3_oidc SET (client_id, client_secret, issuer, scopes) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)", + expectedArgs: []interface{}{ + "client-id", + anyArg{}, + "issuer", + database.StringArray{"profile"}, + "idp-config-id", + "instance-id", + }, + }, + }, + }, + }, + }, + { + name: "instance reduceOldJWTConfigAdded", + args: args{ + event: getEvent(testEvent( + repository.EventType(instance.IDPJWTConfigAddedEventType), + instance.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "jwtEndpoint": "https://api.zitadel.ch/jwt", + "issuer": "issuer", + "keysEndpoint": "https://api.zitadel.ch/keys", + "headerName": "hodor" + }`), + ), instance.IDPJWTConfigAddedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldJWTConfigAdded, + want: wantReduce{ + aggregateType: eventstore.AggregateType("instance"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedArgs: []interface{}{ + anyArg{}, + uint64(15), + domain.IDPTypeJWT, + "idp-config-id", + "instance-id", + }, + }, + { + expectedStmt: "INSERT INTO projections.idp_templates3_jwt (idp_id, instance_id, issuer, jwt_endpoint, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5, $6)", + expectedArgs: []interface{}{ + "idp-config-id", + "instance-id", + "issuer", + "https://api.zitadel.ch/jwt", + "https://api.zitadel.ch/keys", + "hodor", + }, + }, + }, + }, + }, + }, + + { + name: "org reduceOldJWTConfigAdded", + args: args{ + event: getEvent(testEvent( + repository.EventType(org.IDPJWTConfigAddedEventType), + org.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "jwtEndpoint": "https://api.zitadel.ch/jwt", + "issuer": "issuer", + "keysEndpoint": "https://api.zitadel.ch/keys", + "headerName": "hodor" + }`), + ), org.IDPJWTConfigAddedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldJWTConfigAdded, + want: wantReduce{ + aggregateType: eventstore.AggregateType("org"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedArgs: []interface{}{ + anyArg{}, + uint64(15), + domain.IDPTypeJWT, + "idp-config-id", + "instance-id", + }, + }, + { + expectedStmt: "INSERT INTO projections.idp_templates3_jwt (idp_id, instance_id, issuer, jwt_endpoint, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5, $6)", + expectedArgs: []interface{}{ + "idp-config-id", + "instance-id", + "issuer", + "https://api.zitadel.ch/jwt", + "https://api.zitadel.ch/keys", + "hodor", + }, + }, + }, + }, + }, + }, + { + name: "instance reduceOldJWTConfigChanged", + args: args{ + event: getEvent(testEvent( + repository.EventType(instance.IDPJWTConfigChangedEventType), + instance.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "jwtEndpoint": "https://api.zitadel.ch/jwt", + "issuer": "issuer", + "keysEndpoint": "https://api.zitadel.ch/keys", + "headerName": "hodor" + }`), + ), instance.IDPJWTConfigChangedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldJWTConfigChanged, + want: wantReduce{ + aggregateType: eventstore.AggregateType("instance"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedArgs: []interface{}{ + anyArg{}, + uint64(15), + "idp-config-id", + "instance-id", + }, + }, + { + expectedStmt: "UPDATE projections.idp_templates3_jwt SET (jwt_endpoint, keys_endpoint, header_name, issuer) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)", + expectedArgs: []interface{}{ + "https://api.zitadel.ch/jwt", + "https://api.zitadel.ch/keys", + "hodor", + "issuer", + "idp-config-id", + "instance-id", + }, + }, + }, + }, + }, + }, + { + name: "org reduceOldJWTConfigChanged", + args: args{ + event: getEvent(testEvent( + repository.EventType(org.IDPJWTConfigChangedEventType), + org.AggregateType, + []byte(`{ + "idpConfigId": "idp-config-id", + "jwtEndpoint": "https://api.zitadel.ch/jwt", + "issuer": "issuer", + "keysEndpoint": "https://api.zitadel.ch/keys", + "headerName": "hodor" + }`), + ), org.IDPJWTConfigChangedEventMapper), + }, + reduce: (&idpTemplateProjection{}).reduceOldJWTConfigChanged, + want: wantReduce{ + aggregateType: eventstore.AggregateType("org"), + sequence: 15, + previousSequence: 10, + executer: &testExecuter{ + executions: []execution{ + { + expectedStmt: "UPDATE projections.idp_templates3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)", + expectedArgs: []interface{}{ + anyArg{}, + uint64(15), + "idp-config-id", + "instance-id", + }, + }, + { + expectedStmt: "UPDATE projections.idp_templates3_jwt SET (jwt_endpoint, keys_endpoint, header_name, issuer) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)", + expectedArgs: []interface{}{ + "https://api.zitadel.ch/jwt", + "https://api.zitadel.ch/keys", + "hodor", + "issuer", + "idp-config-id", + "instance-id", + }, + }, + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + event := baseEvent(t) + got, err := tt.reduce(event) + if !errors.IsErrorInvalidArgument(err) { + t.Errorf("no wrong event mapping: %v, got: %v", err, got) + } + + event = tt.args.event(t) + got, err = tt.reduce(event) + assertReduce(t, got, err, IDPTemplateTable, tt.want) + }) + } +} + func TestIDPTemplateProjection_reducesJWT(t *testing.T) { type args struct { event func(t *testing.T) eventstore.Event @@ -1330,7 +1915,7 @@ func TestIDPTemplateProjection_reducesJWT(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -1349,7 +1934,7 @@ func TestIDPTemplateProjection_reducesJWT(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_jwt (idp_id, instance_id, issuer, jwt_endpoint, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5, $6)", + expectedStmt: "INSERT INTO projections.idp_templates3_jwt (idp_id, instance_id, issuer, jwt_endpoint, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5, $6)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -1390,7 +1975,7 @@ func TestIDPTemplateProjection_reducesJWT(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.idp_templates2 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", + expectedStmt: "INSERT INTO projections.idp_templates3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, owner_type, type, is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", expectedArgs: []interface{}{ "idp-id", anyArg{}, @@ -1409,7 +1994,7 @@ func TestIDPTemplateProjection_reducesJWT(t *testing.T) { }, }, { - expectedStmt: "INSERT INTO projections.idp_templates2_jwt (idp_id, instance_id, issuer, jwt_endpoint, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5, $6)", + expectedStmt: "INSERT INTO projections.idp_templates3_jwt (idp_id, instance_id, issuer, jwt_endpoint, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5, $6)", expectedArgs: []interface{}{ "idp-id", "instance-id", @@ -1444,7 +2029,7 @@ func TestIDPTemplateProjection_reducesJWT(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", + expectedStmt: "UPDATE projections.idp_templates3 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ true, anyArg{}, @@ -1454,7 +2039,7 @@ func TestIDPTemplateProjection_reducesJWT(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_jwt SET jwt_endpoint = $1 WHERE (idp_id = $2) AND (instance_id = $3)", + expectedStmt: "UPDATE projections.idp_templates3_jwt SET jwt_endpoint = $1 WHERE (idp_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "jwt", "idp-id", @@ -1492,7 +2077,7 @@ func TestIDPTemplateProjection_reducesJWT(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)", + expectedStmt: "UPDATE projections.idp_templates3 SET (is_creation_allowed, is_linking_allowed, is_auto_creation, is_auto_update, change_date, sequence) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)", expectedArgs: []interface{}{ true, true, @@ -1505,7 +2090,7 @@ func TestIDPTemplateProjection_reducesJWT(t *testing.T) { }, }, { - expectedStmt: "UPDATE projections.idp_templates2_jwt SET (jwt_endpoint, keys_endpoint, header_name, issuer) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)", + expectedStmt: "UPDATE projections.idp_templates3_jwt SET (jwt_endpoint, keys_endpoint, header_name, issuer) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ "jwt", "keys",