mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:57:32 +00:00
feat(api): add oidc and jwt provider template (#5290)
Adds possibility to manage OIDC and JWT template based providers
This commit is contained in:
@@ -34,6 +34,8 @@ type IDPTemplate struct {
|
||||
IsAutoCreation bool
|
||||
IsAutoUpdate bool
|
||||
*OAuthIDPTemplate
|
||||
*OIDCIDPTemplate
|
||||
*JWTIDPTemplate
|
||||
*GoogleIDPTemplate
|
||||
*LDAPIDPTemplate
|
||||
}
|
||||
@@ -53,6 +55,22 @@ type OAuthIDPTemplate struct {
|
||||
Scopes database.StringArray
|
||||
}
|
||||
|
||||
type OIDCIDPTemplate struct {
|
||||
IDPID string
|
||||
ClientID string
|
||||
ClientSecret *crypto.CryptoValue
|
||||
Issuer string
|
||||
Scopes database.StringArray
|
||||
}
|
||||
|
||||
type JWTIDPTemplate struct {
|
||||
IDPID string
|
||||
Issuer string
|
||||
KeysEndpoint string
|
||||
HeaderName string
|
||||
Endpoint string
|
||||
}
|
||||
|
||||
type GoogleIDPTemplate struct {
|
||||
IDPID string
|
||||
ClientID string
|
||||
@@ -179,6 +197,68 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
oidcIdpTemplateTable = table{
|
||||
name: projection.IDPTemplateOIDCTable,
|
||||
instanceIDCol: projection.OIDCInstanceIDCol,
|
||||
}
|
||||
OIDCIDCol = Column{
|
||||
name: projection.OIDCIDCol,
|
||||
table: oidcIdpTemplateTable,
|
||||
}
|
||||
OIDCInstanceIDCol = Column{
|
||||
name: projection.OIDCInstanceIDCol,
|
||||
table: oidcIdpTemplateTable,
|
||||
}
|
||||
OIDCIssuerCol = Column{
|
||||
name: projection.OIDCIssuerCol,
|
||||
table: oidcIdpTemplateTable,
|
||||
}
|
||||
OIDCClientIDCol = Column{
|
||||
name: projection.OIDCClientIDCol,
|
||||
table: oidcIdpTemplateTable,
|
||||
}
|
||||
OIDCClientSecretCol = Column{
|
||||
name: projection.OIDCClientSecretCol,
|
||||
table: oidcIdpTemplateTable,
|
||||
}
|
||||
OIDCScopesCol = Column{
|
||||
name: projection.OIDCScopesCol,
|
||||
table: oidcIdpTemplateTable,
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
jwtIdpTemplateTable = table{
|
||||
name: projection.IDPTemplateJWTTable,
|
||||
instanceIDCol: projection.JWTInstanceIDCol,
|
||||
}
|
||||
JWTIDCol = Column{
|
||||
name: projection.JWTIDCol,
|
||||
table: jwtIdpTemplateTable,
|
||||
}
|
||||
JWTInstanceIDCol = Column{
|
||||
name: projection.JWTInstanceIDCol,
|
||||
table: jwtIdpTemplateTable,
|
||||
}
|
||||
JWTIssuerCol = Column{
|
||||
name: projection.JWTIssuerCol,
|
||||
table: jwtIdpTemplateTable,
|
||||
}
|
||||
JWTEndpointCol = Column{
|
||||
name: projection.JWTEndpointCol,
|
||||
table: jwtIdpTemplateTable,
|
||||
}
|
||||
JWTKeysEndpointCol = Column{
|
||||
name: projection.JWTKeysEndpointCol,
|
||||
table: jwtIdpTemplateTable,
|
||||
}
|
||||
JWTHeaderNameCol = Column{
|
||||
name: projection.JWTHeaderNameCol,
|
||||
table: jwtIdpTemplateTable,
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
googleIdpTemplateTable = table{
|
||||
name: projection.IDPTemplateGoogleTable,
|
||||
@@ -428,6 +508,18 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
OAuthTokenEndpointCol.identifier(),
|
||||
OAuthUserEndpointCol.identifier(),
|
||||
OAuthScopesCol.identifier(),
|
||||
// oidc
|
||||
OIDCIDCol.identifier(),
|
||||
OIDCIssuerCol.identifier(),
|
||||
OIDCClientIDCol.identifier(),
|
||||
OIDCClientSecretCol.identifier(),
|
||||
OIDCScopesCol.identifier(),
|
||||
// jwt
|
||||
JWTIDCol.identifier(),
|
||||
JWTIssuerCol.identifier(),
|
||||
JWTEndpointCol.identifier(),
|
||||
JWTKeysEndpointCol.identifier(),
|
||||
JWTHeaderNameCol.identifier(),
|
||||
// google
|
||||
GoogleIDCol.identifier(),
|
||||
GoogleClientIDCol.identifier(),
|
||||
@@ -458,6 +550,8 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
LDAPProfileAttributeCol.identifier(),
|
||||
).From(idpTemplateTable.identifier()).
|
||||
LeftJoin(join(OAuthIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(OIDCIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(JWTIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(GoogleIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(LDAPIDCol, IDPTemplateIDCol)).
|
||||
PlaceholderFormat(sq.Dollar),
|
||||
@@ -474,6 +568,18 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
oauthUserEndpoint := sql.NullString{}
|
||||
oauthScopes := database.StringArray{}
|
||||
|
||||
oidcID := sql.NullString{}
|
||||
oidcIssuer := sql.NullString{}
|
||||
oidcClientID := sql.NullString{}
|
||||
oidcClientSecret := new(crypto.CryptoValue)
|
||||
oidcScopes := database.StringArray{}
|
||||
|
||||
jwtID := sql.NullString{}
|
||||
jwtIssuer := sql.NullString{}
|
||||
jwtEndpoint := sql.NullString{}
|
||||
jwtKeysEndpoint := sql.NullString{}
|
||||
jwtHeaderName := sql.NullString{}
|
||||
|
||||
googleID := sql.NullString{}
|
||||
googleClientID := sql.NullString{}
|
||||
googleClientSecret := new(crypto.CryptoValue)
|
||||
@@ -524,6 +630,18 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
&oauthTokenEndpoint,
|
||||
&oauthUserEndpoint,
|
||||
&oauthScopes,
|
||||
// oidc
|
||||
&oidcID,
|
||||
&oidcIssuer,
|
||||
&oidcClientID,
|
||||
&oidcClientSecret,
|
||||
&oidcScopes,
|
||||
// jwt
|
||||
&jwtID,
|
||||
&jwtIssuer,
|
||||
&jwtEndpoint,
|
||||
&jwtKeysEndpoint,
|
||||
&jwtHeaderName,
|
||||
// google
|
||||
&googleID,
|
||||
&googleClientID,
|
||||
@@ -573,6 +691,24 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
Scopes: oauthScopes,
|
||||
}
|
||||
}
|
||||
if oidcID.Valid {
|
||||
idpTemplate.OIDCIDPTemplate = &OIDCIDPTemplate{
|
||||
IDPID: oidcID.String,
|
||||
ClientID: oidcClientID.String,
|
||||
ClientSecret: oidcClientSecret,
|
||||
Issuer: oidcIssuer.String,
|
||||
Scopes: oidcScopes,
|
||||
}
|
||||
}
|
||||
if jwtID.Valid {
|
||||
idpTemplate.JWTIDPTemplate = &JWTIDPTemplate{
|
||||
IDPID: jwtID.String,
|
||||
Issuer: jwtIssuer.String,
|
||||
KeysEndpoint: jwtKeysEndpoint.String,
|
||||
HeaderName: jwtHeaderName.String,
|
||||
Endpoint: jwtEndpoint.String,
|
||||
}
|
||||
}
|
||||
if googleID.Valid {
|
||||
idpTemplate.GoogleIDPTemplate = &GoogleIDPTemplate{
|
||||
IDPID: googleID.String,
|
||||
@@ -637,6 +773,18 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
OAuthTokenEndpointCol.identifier(),
|
||||
OAuthUserEndpointCol.identifier(),
|
||||
OAuthScopesCol.identifier(),
|
||||
// oidc
|
||||
OIDCIDCol.identifier(),
|
||||
OIDCIssuerCol.identifier(),
|
||||
OIDCClientIDCol.identifier(),
|
||||
OIDCClientSecretCol.identifier(),
|
||||
OIDCScopesCol.identifier(),
|
||||
// jwt
|
||||
JWTIDCol.identifier(),
|
||||
JWTIssuerCol.identifier(),
|
||||
JWTEndpointCol.identifier(),
|
||||
JWTKeysEndpointCol.identifier(),
|
||||
JWTHeaderNameCol.identifier(),
|
||||
// google
|
||||
GoogleIDCol.identifier(),
|
||||
GoogleClientIDCol.identifier(),
|
||||
@@ -668,6 +816,8 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
countColumn.identifier(),
|
||||
).From(idpTemplateTable.identifier()).
|
||||
LeftJoin(join(OAuthIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(OIDCIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(JWTIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(GoogleIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(LDAPIDCol, IDPTemplateIDCol)).
|
||||
PlaceholderFormat(sq.Dollar),
|
||||
@@ -687,6 +837,18 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
oauthUserEndpoint := sql.NullString{}
|
||||
oauthScopes := database.StringArray{}
|
||||
|
||||
oidcID := sql.NullString{}
|
||||
oidcIssuer := sql.NullString{}
|
||||
oidcClientID := sql.NullString{}
|
||||
oidcClientSecret := new(crypto.CryptoValue)
|
||||
oidcScopes := database.StringArray{}
|
||||
|
||||
jwtID := sql.NullString{}
|
||||
jwtIssuer := sql.NullString{}
|
||||
jwtEndpoint := sql.NullString{}
|
||||
jwtKeysEndpoint := sql.NullString{}
|
||||
jwtHeaderName := sql.NullString{}
|
||||
|
||||
googleID := sql.NullString{}
|
||||
googleClientID := sql.NullString{}
|
||||
googleClientSecret := new(crypto.CryptoValue)
|
||||
@@ -737,6 +899,18 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
&oauthTokenEndpoint,
|
||||
&oauthUserEndpoint,
|
||||
&oauthScopes,
|
||||
// oidc
|
||||
&oidcID,
|
||||
&oidcIssuer,
|
||||
&oidcClientID,
|
||||
&oidcClientSecret,
|
||||
&oidcScopes,
|
||||
// jwt
|
||||
&jwtID,
|
||||
&jwtIssuer,
|
||||
&jwtEndpoint,
|
||||
&jwtKeysEndpoint,
|
||||
&jwtHeaderName,
|
||||
// google
|
||||
&googleID,
|
||||
&googleClientID,
|
||||
@@ -785,6 +959,24 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
Scopes: oauthScopes,
|
||||
}
|
||||
}
|
||||
if oidcID.Valid {
|
||||
idpTemplate.OIDCIDPTemplate = &OIDCIDPTemplate{
|
||||
IDPID: oidcID.String,
|
||||
ClientID: oidcClientID.String,
|
||||
ClientSecret: oidcClientSecret,
|
||||
Issuer: oidcIssuer.String,
|
||||
Scopes: oidcScopes,
|
||||
}
|
||||
}
|
||||
if jwtID.Valid {
|
||||
idpTemplate.JWTIDPTemplate = &JWTIDPTemplate{
|
||||
IDPID: jwtID.String,
|
||||
Issuer: jwtIssuer.String,
|
||||
KeysEndpoint: jwtKeysEndpoint.String,
|
||||
HeaderName: jwtHeaderName.String,
|
||||
Endpoint: jwtEndpoint.String,
|
||||
}
|
||||
}
|
||||
if googleID.Valid {
|
||||
idpTemplate.GoogleIDPTemplate = &GoogleIDPTemplate{
|
||||
IDPID: googleID.String,
|
||||
|
@@ -15,59 +15,73 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
idpTemplateQuery = `SELECT projections.idp_templates.id,` +
|
||||
` projections.idp_templates.resource_owner,` +
|
||||
` projections.idp_templates.creation_date,` +
|
||||
` projections.idp_templates.change_date,` +
|
||||
` projections.idp_templates.sequence,` +
|
||||
` projections.idp_templates.state,` +
|
||||
` projections.idp_templates.name,` +
|
||||
` projections.idp_templates.type,` +
|
||||
` projections.idp_templates.owner_type,` +
|
||||
` projections.idp_templates.is_creation_allowed,` +
|
||||
` projections.idp_templates.is_linking_allowed,` +
|
||||
` projections.idp_templates.is_auto_creation,` +
|
||||
` projections.idp_templates.is_auto_update,` +
|
||||
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,` +
|
||||
// oauth
|
||||
` projections.idp_templates_oauth.idp_id,` +
|
||||
` projections.idp_templates_oauth.client_id,` +
|
||||
` projections.idp_templates_oauth.client_secret,` +
|
||||
` projections.idp_templates_oauth.authorization_endpoint,` +
|
||||
` projections.idp_templates_oauth.token_endpoint,` +
|
||||
` projections.idp_templates_oauth.user_endpoint,` +
|
||||
` projections.idp_templates_oauth.scopes,` +
|
||||
` projections.idp_templates2_oauth.idp_id,` +
|
||||
` projections.idp_templates2_oauth.client_id,` +
|
||||
` projections.idp_templates2_oauth.client_secret,` +
|
||||
` projections.idp_templates2_oauth.authorization_endpoint,` +
|
||||
` projections.idp_templates2_oauth.token_endpoint,` +
|
||||
` projections.idp_templates2_oauth.user_endpoint,` +
|
||||
` projections.idp_templates2_oauth.scopes,` +
|
||||
// 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,` +
|
||||
// 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,` +
|
||||
// google
|
||||
` projections.idp_templates_google.idp_id,` +
|
||||
` projections.idp_templates_google.client_id,` +
|
||||
` projections.idp_templates_google.client_secret,` +
|
||||
` projections.idp_templates_google.scopes,` +
|
||||
` projections.idp_templates2_google.idp_id,` +
|
||||
` projections.idp_templates2_google.client_id,` +
|
||||
` projections.idp_templates2_google.client_secret,` +
|
||||
` projections.idp_templates2_google.scopes,` +
|
||||
// ldap
|
||||
` projections.idp_templates_ldap.idp_id,` +
|
||||
` projections.idp_templates_ldap.host,` +
|
||||
` projections.idp_templates_ldap.port,` +
|
||||
` projections.idp_templates_ldap.tls,` +
|
||||
` projections.idp_templates_ldap.base_dn,` +
|
||||
` projections.idp_templates_ldap.user_object_class,` +
|
||||
` projections.idp_templates_ldap.user_unique_attribute,` +
|
||||
` projections.idp_templates_ldap.admin,` +
|
||||
` projections.idp_templates_ldap.password,` +
|
||||
` projections.idp_templates_ldap.id_attribute,` +
|
||||
` projections.idp_templates_ldap.first_name_attribute,` +
|
||||
` projections.idp_templates_ldap.last_name_attribute,` +
|
||||
` projections.idp_templates_ldap.display_name_attribute,` +
|
||||
` projections.idp_templates_ldap.nick_name_attribute,` +
|
||||
` projections.idp_templates_ldap.preferred_username_attribute,` +
|
||||
` projections.idp_templates_ldap.email_attribute,` +
|
||||
` projections.idp_templates_ldap.email_verified,` +
|
||||
` projections.idp_templates_ldap.phone_attribute,` +
|
||||
` projections.idp_templates_ldap.phone_verified_attribute,` +
|
||||
` projections.idp_templates_ldap.preferred_language_attribute,` +
|
||||
` projections.idp_templates_ldap.avatar_url_attribute,` +
|
||||
` projections.idp_templates_ldap.profile_attribute` +
|
||||
` FROM projections.idp_templates` +
|
||||
` LEFT JOIN projections.idp_templates_oauth ON projections.idp_templates.id = projections.idp_templates_oauth.idp_id AND projections.idp_templates.instance_id = projections.idp_templates_oauth.instance_id` +
|
||||
` LEFT JOIN projections.idp_templates_google ON projections.idp_templates.id = projections.idp_templates_google.idp_id AND projections.idp_templates.instance_id = projections.idp_templates_google.instance_id` +
|
||||
` LEFT JOIN projections.idp_templates_ldap ON projections.idp_templates.id = projections.idp_templates_ldap.idp_id AND projections.idp_templates.instance_id = projections.idp_templates_ldap.instance_id`
|
||||
` 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_oauth ON projections.idp_templates2.id = projections.idp_templates2_oauth.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_oauth.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`
|
||||
idpTemplateCols = []string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -90,6 +104,18 @@ var (
|
||||
"token_endpoint",
|
||||
"user_endpoint",
|
||||
"scopes",
|
||||
// oidc config
|
||||
"id_id",
|
||||
"issuer",
|
||||
"client_id",
|
||||
"client_secret",
|
||||
"scopes",
|
||||
// jwt
|
||||
"idp_id",
|
||||
"issuer",
|
||||
"jwt_endpoint",
|
||||
"keys_endpoint",
|
||||
"header_name",
|
||||
// google config
|
||||
"idp_id",
|
||||
"client_id",
|
||||
@@ -119,60 +145,74 @@ var (
|
||||
"avatar_url_attribute",
|
||||
"profile_attribute",
|
||||
}
|
||||
idpTemplatesQuery = `SELECT projections.idp_templates.id,` +
|
||||
` projections.idp_templates.resource_owner,` +
|
||||
` projections.idp_templates.creation_date,` +
|
||||
` projections.idp_templates.change_date,` +
|
||||
` projections.idp_templates.sequence,` +
|
||||
` projections.idp_templates.state,` +
|
||||
` projections.idp_templates.name,` +
|
||||
` projections.idp_templates.type,` +
|
||||
` projections.idp_templates.owner_type,` +
|
||||
` projections.idp_templates.is_creation_allowed,` +
|
||||
` projections.idp_templates.is_linking_allowed,` +
|
||||
` projections.idp_templates.is_auto_creation,` +
|
||||
` projections.idp_templates.is_auto_update,` +
|
||||
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,` +
|
||||
// oauth
|
||||
` projections.idp_templates_oauth.idp_id,` +
|
||||
` projections.idp_templates_oauth.client_id,` +
|
||||
` projections.idp_templates_oauth.client_secret,` +
|
||||
` projections.idp_templates_oauth.authorization_endpoint,` +
|
||||
` projections.idp_templates_oauth.token_endpoint,` +
|
||||
` projections.idp_templates_oauth.user_endpoint,` +
|
||||
` projections.idp_templates_oauth.scopes,` +
|
||||
` projections.idp_templates2_oauth.idp_id,` +
|
||||
` projections.idp_templates2_oauth.client_id,` +
|
||||
` projections.idp_templates2_oauth.client_secret,` +
|
||||
` projections.idp_templates2_oauth.authorization_endpoint,` +
|
||||
` projections.idp_templates2_oauth.token_endpoint,` +
|
||||
` projections.idp_templates2_oauth.user_endpoint,` +
|
||||
` projections.idp_templates2_oauth.scopes,` +
|
||||
// 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,` +
|
||||
// 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,` +
|
||||
// google
|
||||
` projections.idp_templates_google.idp_id,` +
|
||||
` projections.idp_templates_google.client_id,` +
|
||||
` projections.idp_templates_google.client_secret,` +
|
||||
` projections.idp_templates_google.scopes,` +
|
||||
` projections.idp_templates2_google.idp_id,` +
|
||||
` projections.idp_templates2_google.client_id,` +
|
||||
` projections.idp_templates2_google.client_secret,` +
|
||||
` projections.idp_templates2_google.scopes,` +
|
||||
// ldap
|
||||
` projections.idp_templates_ldap.idp_id,` +
|
||||
` projections.idp_templates_ldap.host,` +
|
||||
` projections.idp_templates_ldap.port,` +
|
||||
` projections.idp_templates_ldap.tls,` +
|
||||
` projections.idp_templates_ldap.base_dn,` +
|
||||
` projections.idp_templates_ldap.user_object_class,` +
|
||||
` projections.idp_templates_ldap.user_unique_attribute,` +
|
||||
` projections.idp_templates_ldap.admin,` +
|
||||
` projections.idp_templates_ldap.password,` +
|
||||
` projections.idp_templates_ldap.id_attribute,` +
|
||||
` projections.idp_templates_ldap.first_name_attribute,` +
|
||||
` projections.idp_templates_ldap.last_name_attribute,` +
|
||||
` projections.idp_templates_ldap.display_name_attribute,` +
|
||||
` projections.idp_templates_ldap.nick_name_attribute,` +
|
||||
` projections.idp_templates_ldap.preferred_username_attribute,` +
|
||||
` projections.idp_templates_ldap.email_attribute,` +
|
||||
` projections.idp_templates_ldap.email_verified,` +
|
||||
` projections.idp_templates_ldap.phone_attribute,` +
|
||||
` projections.idp_templates_ldap.phone_verified_attribute,` +
|
||||
` projections.idp_templates_ldap.preferred_language_attribute,` +
|
||||
` projections.idp_templates_ldap.avatar_url_attribute,` +
|
||||
` projections.idp_templates_ldap.profile_attribute,` +
|
||||
` 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,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM projections.idp_templates` +
|
||||
` LEFT JOIN projections.idp_templates_oauth ON projections.idp_templates.id = projections.idp_templates_oauth.idp_id AND projections.idp_templates.instance_id = projections.idp_templates_oauth.instance_id` +
|
||||
` LEFT JOIN projections.idp_templates_google ON projections.idp_templates.id = projections.idp_templates_google.idp_id AND projections.idp_templates.instance_id = projections.idp_templates_google.instance_id` +
|
||||
` LEFT JOIN projections.idp_templates_ldap ON projections.idp_templates.id = projections.idp_templates_ldap.idp_id AND projections.idp_templates.instance_id = projections.idp_templates_ldap.instance_id`
|
||||
` FROM projections.idp_templates2` +
|
||||
` LEFT JOIN projections.idp_templates2_oauth ON projections.idp_templates2.id = projections.idp_templates2_oauth.idp_id AND projections.idp_templates2.instance_id = projections.idp_templates2_oauth.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`
|
||||
idpTemplatesCols = []string{
|
||||
"id",
|
||||
"resource_owner",
|
||||
@@ -195,6 +235,18 @@ var (
|
||||
"token_endpoint",
|
||||
"user_endpoint",
|
||||
"scopes",
|
||||
// oidc config
|
||||
"id_id",
|
||||
"issuer",
|
||||
"client_id",
|
||||
"client_secret",
|
||||
"scopes",
|
||||
// jwt
|
||||
"idp_id",
|
||||
"issuer",
|
||||
"jwt_endpoint",
|
||||
"keys_endpoint",
|
||||
"header_name",
|
||||
// google config
|
||||
"idp_id",
|
||||
"client_id",
|
||||
@@ -285,6 +337,18 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
"token",
|
||||
"user",
|
||||
database.StringArray{"profile"},
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google
|
||||
nil,
|
||||
nil,
|
||||
@@ -341,6 +405,196 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
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,
|
||||
// oidc
|
||||
"idp-id",
|
||||
"issuer",
|
||||
"client_id",
|
||||
nil,
|
||||
database.StringArray{"profile"},
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
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.IDPTypeOIDC,
|
||||
OwnerType: domain.IdentityProviderTypeOrg,
|
||||
IsCreationAllowed: true,
|
||||
IsLinkingAllowed: true,
|
||||
IsAutoCreation: true,
|
||||
IsAutoUpdate: true,
|
||||
OIDCIDPTemplate: &OIDCIDPTemplate{
|
||||
IDPID: "idp-id",
|
||||
Issuer: "issuer",
|
||||
ClientID: "client_id",
|
||||
ClientSecret: nil,
|
||||
Scopes: []string{"profile"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
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.IDPTypeJWT,
|
||||
domain.IdentityProviderTypeOrg,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
// oauth
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
"idp-id",
|
||||
"issuer",
|
||||
"jwt",
|
||||
"keys",
|
||||
"header",
|
||||
// google
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
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.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",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "prepareIDPTemplateByIDQuery google idp",
|
||||
prepare: prepareIDPTemplateByIDQuery,
|
||||
@@ -370,6 +624,18 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google
|
||||
"idp-id",
|
||||
"client_id",
|
||||
@@ -452,6 +718,18 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google
|
||||
nil,
|
||||
nil,
|
||||
@@ -553,6 +831,18 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google config
|
||||
nil,
|
||||
nil,
|
||||
@@ -665,6 +955,18 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google config
|
||||
nil,
|
||||
nil,
|
||||
@@ -775,6 +1077,18 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google config
|
||||
nil,
|
||||
nil,
|
||||
@@ -860,6 +1174,18 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google config
|
||||
nil,
|
||||
nil,
|
||||
@@ -911,6 +1237,18 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google
|
||||
"idp-id-google",
|
||||
"client_id",
|
||||
@@ -962,6 +1300,144 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
"token",
|
||||
"user",
|
||||
database.StringArray{"profile"},
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"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,
|
||||
// oidc
|
||||
"idp-id-oidc",
|
||||
"issuer",
|
||||
"client_id",
|
||||
nil,
|
||||
database.StringArray{"profile"},
|
||||
// jwt
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// google
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"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,
|
||||
// oidc
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// jwt
|
||||
"idp-id-jwt",
|
||||
"issuer",
|
||||
"jwt",
|
||||
"keys",
|
||||
"header",
|
||||
// google
|
||||
nil,
|
||||
nil,
|
||||
@@ -996,7 +1472,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
},
|
||||
object: &IDPTemplates{
|
||||
SearchResponse: SearchResponse{
|
||||
Count: 3,
|
||||
Count: 5,
|
||||
},
|
||||
Templates: []*IDPTemplate{
|
||||
{
|
||||
@@ -1085,6 +1561,50 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
Scopes: []string{"profile"},
|
||||
},
|
||||
},
|
||||
{
|
||||
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{
|
||||
IDPID: "idp-id-oidc",
|
||||
Issuer: "issuer",
|
||||
ClientID: "client_id",
|
||||
ClientSecret: nil,
|
||||
Scopes: []string{"profile"},
|
||||
},
|
||||
},
|
||||
{
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@@ -11,17 +11,22 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
"github.com/zitadel/zitadel/internal/repository/idp"
|
||||
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
const (
|
||||
IDPTemplateTable = "projections.idp_templates"
|
||||
IDPTemplateTable = "projections.idp_templates2"
|
||||
IDPTemplateOAuthTable = IDPTemplateTable + "_" + IDPTemplateOAuthSuffix
|
||||
IDPTemplateOIDCTable = IDPTemplateTable + "_" + IDPTemplateOIDCSuffix
|
||||
IDPTemplateJWTTable = IDPTemplateTable + "_" + IDPTemplateJWTSuffix
|
||||
IDPTemplateGoogleTable = IDPTemplateTable + "_" + IDPTemplateGoogleSuffix
|
||||
IDPTemplateLDAPTable = IDPTemplateTable + "_" + IDPTemplateLDAPSuffix
|
||||
|
||||
IDPTemplateOAuthSuffix = "oauth"
|
||||
IDPTemplateOIDCSuffix = "oidc"
|
||||
IDPTemplateJWTSuffix = "jwt"
|
||||
IDPTemplateGoogleSuffix = "google"
|
||||
IDPTemplateLDAPSuffix = "ldap"
|
||||
|
||||
@@ -50,6 +55,20 @@ const (
|
||||
OAuthUserEndpointCol = "user_endpoint"
|
||||
OAuthScopesCol = "scopes"
|
||||
|
||||
OIDCIDCol = "idp_id"
|
||||
OIDCInstanceIDCol = "instance_id"
|
||||
OIDCIssuerCol = "issuer"
|
||||
OIDCClientIDCol = "client_id"
|
||||
OIDCClientSecretCol = "client_secret"
|
||||
OIDCScopesCol = "scopes"
|
||||
|
||||
JWTIDCol = "idp_id"
|
||||
JWTInstanceIDCol = "instance_id"
|
||||
JWTIssuerCol = "issuer"
|
||||
JWTEndpointCol = "jwt_endpoint"
|
||||
JWTKeysEndpointCol = "keys_endpoint"
|
||||
JWTHeaderNameCol = "header_name"
|
||||
|
||||
GoogleIDCol = "idp_id"
|
||||
GoogleInstanceIDCol = "instance_id"
|
||||
GoogleClientIDCol = "client_id"
|
||||
@@ -125,6 +144,30 @@ func newIDPTemplateProjection(ctx context.Context, config crdb.StatementHandlerC
|
||||
IDPTemplateOAuthSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(OIDCIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCIssuerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCClientIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCClientSecretCol, crdb.ColumnTypeJSONB),
|
||||
crdb.NewColumn(OIDCScopesCol, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(OIDCInstanceIDCol, OIDCIDCol),
|
||||
IDPTemplateOIDCSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(JWTIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(JWTInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(JWTIssuerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(JWTEndpointCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(JWTKeysEndpointCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(JWTHeaderNameCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(JWTInstanceIDCol, JWTIDCol),
|
||||
IDPTemplateJWTSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(GoogleIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(GoogleInstanceIDCol, crdb.ColumnTypeText),
|
||||
@@ -183,6 +226,46 @@ func (p *idpTemplateProjection) reducers() []handler.AggregateReducer {
|
||||
Event: instance.OAuthIDPChangedEventType,
|
||||
Reduce: p.reduceOAuthIDPChanged,
|
||||
},
|
||||
{
|
||||
Event: instance.OIDCIDPAddedEventType,
|
||||
Reduce: p.reduceOIDCIDPAdded,
|
||||
},
|
||||
{
|
||||
Event: instance.OIDCIDPChangedEventType,
|
||||
Reduce: p.reduceOIDCIDPChanged,
|
||||
},
|
||||
{
|
||||
Event: instance.JWTIDPAddedEventType,
|
||||
Reduce: p.reduceJWTIDPAdded,
|
||||
},
|
||||
{
|
||||
Event: instance.JWTIDPAddedEventType,
|
||||
Reduce: p.reduceJWTIDPChanged,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPConfigAddedEventType,
|
||||
Reduce: p.reduceOldConfigAdded,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPConfigChangedEventType,
|
||||
Reduce: p.reduceOldConfigChanged,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPOIDCConfigAddedEventType,
|
||||
Reduce: p.reduceOldOIDCConfigAdded,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPOIDCConfigChangedEventType,
|
||||
Reduce: p.reduceOldOIDCConfigChanged,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPJWTConfigAddedEventType,
|
||||
Reduce: p.reduceOldJWTConfigAdded,
|
||||
},
|
||||
{
|
||||
Event: instance.IDPJWTConfigChangedEventType,
|
||||
Reduce: p.reduceOldJWTConfigChanged,
|
||||
},
|
||||
{
|
||||
Event: instance.GoogleIDPAddedEventType,
|
||||
Reduce: p.reduceGoogleIDPAdded,
|
||||
@@ -220,6 +303,47 @@ func (p *idpTemplateProjection) reducers() []handler.AggregateReducer {
|
||||
Event: org.OAuthIDPChangedEventType,
|
||||
Reduce: p.reduceOAuthIDPChanged,
|
||||
},
|
||||
{
|
||||
Event: org.OIDCIDPAddedEventType,
|
||||
Reduce: p.reduceOIDCIDPAdded,
|
||||
},
|
||||
{
|
||||
Event: org.OIDCIDPChangedEventType,
|
||||
Reduce: p.reduceOIDCIDPChanged,
|
||||
},
|
||||
|
||||
{
|
||||
Event: org.JWTIDPAddedEventType,
|
||||
Reduce: p.reduceJWTIDPAdded,
|
||||
},
|
||||
{
|
||||
Event: org.JWTIDPAddedEventType,
|
||||
Reduce: p.reduceJWTIDPChanged,
|
||||
},
|
||||
{
|
||||
Event: org.IDPConfigAddedEventType,
|
||||
Reduce: p.reduceOldConfigAdded,
|
||||
},
|
||||
{
|
||||
Event: org.IDPConfigChangedEventType,
|
||||
Reduce: p.reduceOldConfigChanged,
|
||||
},
|
||||
{
|
||||
Event: org.IDPOIDCConfigAddedEventType,
|
||||
Reduce: p.reduceOldOIDCConfigAdded,
|
||||
},
|
||||
{
|
||||
Event: org.IDPOIDCConfigChangedEventType,
|
||||
Reduce: p.reduceOldOIDCConfigChanged,
|
||||
},
|
||||
{
|
||||
Event: org.IDPJWTConfigAddedEventType,
|
||||
Reduce: p.reduceOldJWTConfigAdded,
|
||||
},
|
||||
{
|
||||
Event: org.IDPJWTConfigChangedEventType,
|
||||
Reduce: p.reduceOldJWTConfigChanged,
|
||||
},
|
||||
{
|
||||
Event: org.GoogleIDPAddedEventType,
|
||||
Reduce: p.reduceGoogleIDPAdded,
|
||||
@@ -340,6 +464,438 @@ func (p *idpTemplateProjection) reduceOAuthIDPChanged(event eventstore.Event) (*
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceOIDCIDPAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idp.OIDCIDPAddedEvent
|
||||
var idpOwnerType domain.IdentityProviderType
|
||||
switch e := event.(type) {
|
||||
case *org.OIDCIDPAddedEvent:
|
||||
idpEvent = e.OIDCIDPAddedEvent
|
||||
idpOwnerType = domain.IdentityProviderTypeOrg
|
||||
case *instance.OIDCIDPAddedEvent:
|
||||
idpEvent = e.OIDCIDPAddedEvent
|
||||
idpOwnerType = domain.IdentityProviderTypeSystem
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-9s02m1", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPAddedEventType, instance.OIDCIDPAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
&idpEvent,
|
||||
crdb.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
|
||||
handler.NewCol(IDPTemplateCreationDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
|
||||
handler.NewCol(IDPTemplateResourceOwnerCol, idpEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(IDPTemplateStateCol, domain.IDPStateActive),
|
||||
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
|
||||
handler.NewCol(IDPTemplateOwnerTypeCol, idpOwnerType),
|
||||
handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeOIDC),
|
||||
handler.NewCol(IDPTemplateIsCreationAllowedCol, idpEvent.IsCreationAllowed),
|
||||
handler.NewCol(IDPTemplateIsLinkingAllowedCol, idpEvent.IsLinkingAllowed),
|
||||
handler.NewCol(IDPTemplateIsAutoCreationCol, idpEvent.IsAutoCreation),
|
||||
handler.NewCol(IDPTemplateIsAutoUpdateCol, idpEvent.IsAutoUpdate),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(OIDCIDCol, idpEvent.ID),
|
||||
handler.NewCol(OIDCInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(OIDCIssuerCol, idpEvent.Issuer),
|
||||
handler.NewCol(OIDCClientIDCol, idpEvent.ClientID),
|
||||
handler.NewCol(OIDCClientSecretCol, idpEvent.ClientSecret),
|
||||
handler.NewCol(OIDCScopesCol, database.StringArray(idpEvent.Scopes)),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPTemplateOIDCSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceOIDCIDPChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idp.OIDCIDPChangedEvent
|
||||
switch e := event.(type) {
|
||||
case *org.OIDCIDPChangedEvent:
|
||||
idpEvent = e.OIDCIDPChangedEvent
|
||||
case *instance.OIDCIDPChangedEvent:
|
||||
idpEvent = e.OIDCIDPChangedEvent
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPChangedEventType, instance.OIDCIDPChangedEventType})
|
||||
}
|
||||
|
||||
ops := make([]func(eventstore.Event) crdb.Exec, 0, 2)
|
||||
ops = append(ops,
|
||||
crdb.AddUpdateStatement(
|
||||
reduceIDPChangedTemplateColumns(idpEvent.Name, idpEvent.CreationDate(), idpEvent.Sequence(), idpEvent.OptionChanges),
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
|
||||
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
)
|
||||
oidcCols := reduceOIDCIDPChangedColumns(idpEvent)
|
||||
if len(oidcCols) > 0 {
|
||||
ops = append(ops,
|
||||
crdb.AddUpdateStatement(
|
||||
oidcCols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OIDCIDCol, idpEvent.ID),
|
||||
handler.NewCond(OIDCInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPTemplateOIDCSuffix),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
&idpEvent,
|
||||
ops...,
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceJWTIDPAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idp.JWTIDPAddedEvent
|
||||
var idpOwnerType domain.IdentityProviderType
|
||||
switch e := event.(type) {
|
||||
case *org.JWTIDPAddedEvent:
|
||||
idpEvent = e.JWTIDPAddedEvent
|
||||
idpOwnerType = domain.IdentityProviderTypeOrg
|
||||
case *instance.JWTIDPAddedEvent:
|
||||
idpEvent = e.JWTIDPAddedEvent
|
||||
idpOwnerType = domain.IdentityProviderTypeSystem
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-xopi2s", "reduce.wrong.event.type %v", []eventstore.EventType{org.JWTIDPAddedEventType, instance.JWTIDPAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
&idpEvent,
|
||||
crdb.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPTemplateIDCol, idpEvent.ID),
|
||||
handler.NewCol(IDPTemplateCreationDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
|
||||
handler.NewCol(IDPTemplateResourceOwnerCol, idpEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(IDPTemplateStateCol, domain.IDPStateActive),
|
||||
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
|
||||
handler.NewCol(IDPTemplateOwnerTypeCol, idpOwnerType),
|
||||
handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeJWT),
|
||||
handler.NewCol(IDPTemplateIsCreationAllowedCol, idpEvent.IsCreationAllowed),
|
||||
handler.NewCol(IDPTemplateIsLinkingAllowedCol, idpEvent.IsLinkingAllowed),
|
||||
handler.NewCol(IDPTemplateIsAutoCreationCol, idpEvent.IsAutoCreation),
|
||||
handler.NewCol(IDPTemplateIsAutoUpdateCol, idpEvent.IsAutoUpdate),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(JWTIDCol, idpEvent.ID),
|
||||
handler.NewCol(JWTInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(JWTIssuerCol, idpEvent.Issuer),
|
||||
handler.NewCol(JWTEndpointCol, idpEvent.JWTEndpoint),
|
||||
handler.NewCol(JWTKeysEndpointCol, idpEvent.KeysEndpoint),
|
||||
handler.NewCol(JWTHeaderNameCol, idpEvent.HeaderName),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPTemplateJWTSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceJWTIDPChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idp.JWTIDPChangedEvent
|
||||
switch e := event.(type) {
|
||||
case *org.JWTIDPChangedEvent:
|
||||
idpEvent = e.JWTIDPChangedEvent
|
||||
case *instance.JWTIDPChangedEvent:
|
||||
idpEvent = e.JWTIDPChangedEvent
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.JWTIDPChangedEventType, instance.JWTIDPChangedEventType})
|
||||
}
|
||||
|
||||
ops := make([]func(eventstore.Event) crdb.Exec, 0, 2)
|
||||
ops = append(ops,
|
||||
crdb.AddUpdateStatement(
|
||||
reduceIDPChangedTemplateColumns(idpEvent.Name, idpEvent.CreationDate(), idpEvent.Sequence(), idpEvent.OptionChanges),
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
|
||||
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
)
|
||||
jwtCols := reduceJWTIDPChangedColumns(idpEvent)
|
||||
if len(jwtCols) > 0 {
|
||||
ops = append(ops,
|
||||
crdb.AddUpdateStatement(
|
||||
jwtCols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(JWTIDCol, idpEvent.ID),
|
||||
handler.NewCond(JWTInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPTemplateJWTSuffix),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
&idpEvent,
|
||||
ops...,
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceOldConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idpconfig.IDPConfigAddedEvent
|
||||
var idpOwnerType domain.IdentityProviderType
|
||||
switch e := event.(type) {
|
||||
case *org.IDPConfigAddedEvent:
|
||||
idpEvent = e.IDPConfigAddedEvent
|
||||
idpOwnerType = domain.IdentityProviderTypeOrg
|
||||
case *instance.IDPConfigAddedEvent:
|
||||
idpEvent = e.IDPConfigAddedEvent
|
||||
idpOwnerType = domain.IdentityProviderTypeSystem
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ADfeg", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigAddedEventType, instance.IDPConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPTemplateIDCol, idpEvent.ConfigID),
|
||||
handler.NewCol(IDPTemplateCreationDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
|
||||
handler.NewCol(IDPTemplateResourceOwnerCol, idpEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(IDPTemplateStateCol, domain.IDPStateActive),
|
||||
handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
|
||||
handler.NewCol(IDPTemplateOwnerTypeCol, idpOwnerType),
|
||||
handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeOIDC),
|
||||
handler.NewCol(IDPTemplateIsCreationAllowedCol, true),
|
||||
handler.NewCol(IDPTemplateIsLinkingAllowedCol, true),
|
||||
handler.NewCol(IDPTemplateIsAutoCreationCol, idpEvent.AutoRegister),
|
||||
handler.NewCol(IDPTemplateIsAutoUpdateCol, false),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceOldConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idpconfig.IDPConfigChangedEvent
|
||||
switch e := event.(type) {
|
||||
case *org.IDPConfigChangedEvent:
|
||||
idpEvent = e.IDPConfigChangedEvent
|
||||
case *instance.IDPConfigChangedEvent:
|
||||
idpEvent = e.IDPConfigChangedEvent
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SAfg2", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigChangedEventType, instance.IDPConfigChangedEventType})
|
||||
}
|
||||
|
||||
cols := make([]handler.Column, 0, 4)
|
||||
if idpEvent.Name != nil {
|
||||
cols = append(cols, handler.NewCol(IDPTemplateNameCol, *idpEvent.Name))
|
||||
}
|
||||
if idpEvent.AutoRegister != nil {
|
||||
cols = append(cols, handler.NewCol(IDPTemplateIsAutoCreationCol, *idpEvent.AutoRegister))
|
||||
}
|
||||
cols = append(cols,
|
||||
handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
|
||||
)
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
event,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OIDCIDCol, idpEvent.ConfigID),
|
||||
handler.NewCond(OIDCInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceOldOIDCConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idpconfig.OIDCConfigAddedEvent
|
||||
switch e := event.(type) {
|
||||
case *org.IDPOIDCConfigAddedEvent:
|
||||
idpEvent = e.OIDCConfigAddedEvent
|
||||
case *instance.IDPOIDCConfigAddedEvent:
|
||||
idpEvent = e.OIDCConfigAddedEvent
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ASFdq2", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, instance.IDPOIDCConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
&idpEvent,
|
||||
crdb.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPTemplateIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(OIDCIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCol(OIDCInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(OIDCIssuerCol, idpEvent.Issuer),
|
||||
handler.NewCol(OIDCClientIDCol, idpEvent.ClientID),
|
||||
handler.NewCol(OIDCClientSecretCol, idpEvent.ClientSecret),
|
||||
handler.NewCol(OIDCScopesCol, database.StringArray(idpEvent.Scopes)),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPTemplateOIDCSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceOldOIDCConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idpconfig.OIDCConfigChangedEvent
|
||||
switch e := event.(type) {
|
||||
case *org.IDPOIDCConfigChangedEvent:
|
||||
idpEvent = e.OIDCConfigChangedEvent
|
||||
case *instance.IDPOIDCConfigChangedEvent:
|
||||
idpEvent = e.OIDCConfigChangedEvent
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.OIDCIDPChangedEventType, instance.OIDCIDPChangedEventType})
|
||||
}
|
||||
|
||||
ops := make([]func(eventstore.Event) crdb.Exec, 0, 2)
|
||||
ops = append(ops,
|
||||
crdb.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPTemplateIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
)
|
||||
oidcCols := make([]handler.Column, 0, 4)
|
||||
if idpEvent.ClientID != nil {
|
||||
oidcCols = append(oidcCols, handler.NewCol(OIDCClientIDCol, *idpEvent.ClientID))
|
||||
}
|
||||
if idpEvent.ClientSecret != nil {
|
||||
oidcCols = append(oidcCols, handler.NewCol(OIDCClientSecretCol, *idpEvent.ClientSecret))
|
||||
}
|
||||
if idpEvent.Issuer != nil {
|
||||
oidcCols = append(oidcCols, handler.NewCol(OIDCIssuerCol, *idpEvent.Issuer))
|
||||
}
|
||||
if idpEvent.Scopes != nil {
|
||||
oidcCols = append(oidcCols, handler.NewCol(OIDCScopesCol, database.StringArray(idpEvent.Scopes)))
|
||||
}
|
||||
if len(oidcCols) > 0 {
|
||||
ops = append(ops,
|
||||
crdb.AddUpdateStatement(
|
||||
oidcCols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OIDCIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(OIDCInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPTemplateOIDCSuffix),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
&idpEvent,
|
||||
ops...,
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceOldJWTConfigAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idpconfig.JWTConfigAddedEvent
|
||||
switch e := event.(type) {
|
||||
case *org.IDPJWTConfigAddedEvent:
|
||||
idpEvent = e.JWTConfigAddedEvent
|
||||
case *instance.IDPJWTConfigAddedEvent:
|
||||
idpEvent = e.JWTConfigAddedEvent
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ASFdq2", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPJWTConfigAddedEventType, instance.IDPJWTConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
&idpEvent,
|
||||
crdb.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPTemplateIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(JWTIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCol(JWTInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(JWTIssuerCol, idpEvent.Issuer),
|
||||
handler.NewCol(JWTEndpointCol, idpEvent.JWTEndpoint),
|
||||
handler.NewCol(JWTKeysEndpointCol, idpEvent.KeysEndpoint),
|
||||
handler.NewCol(JWTHeaderNameCol, idpEvent.HeaderName),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPTemplateJWTSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceOldJWTConfigChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idpconfig.JWTConfigChangedEvent
|
||||
switch e := event.(type) {
|
||||
case *org.IDPJWTConfigChangedEvent:
|
||||
idpEvent = e.JWTConfigChangedEvent
|
||||
case *instance.IDPJWTConfigChangedEvent:
|
||||
idpEvent = e.JWTConfigChangedEvent
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.JWTIDPChangedEventType, instance.JWTIDPChangedEventType})
|
||||
}
|
||||
|
||||
ops := make([]func(eventstore.Event) crdb.Exec, 0, 2)
|
||||
ops = append(ops,
|
||||
crdb.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPTemplateChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPTemplateSequenceCol, idpEvent.Sequence()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPTemplateIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
)
|
||||
jwtCols := make([]handler.Column, 0, 4)
|
||||
if idpEvent.JWTEndpoint != nil {
|
||||
jwtCols = append(jwtCols, handler.NewCol(JWTEndpointCol, *idpEvent.JWTEndpoint))
|
||||
}
|
||||
if idpEvent.KeysEndpoint != nil {
|
||||
jwtCols = append(jwtCols, handler.NewCol(JWTKeysEndpointCol, *idpEvent.KeysEndpoint))
|
||||
}
|
||||
if idpEvent.HeaderName != nil {
|
||||
jwtCols = append(jwtCols, handler.NewCol(JWTHeaderNameCol, *idpEvent.HeaderName))
|
||||
}
|
||||
if idpEvent.Issuer != nil {
|
||||
jwtCols = append(jwtCols, handler.NewCol(JWTIssuerCol, *idpEvent.Issuer))
|
||||
}
|
||||
if len(jwtCols) > 0 {
|
||||
ops = append(ops,
|
||||
crdb.AddUpdateStatement(
|
||||
jwtCols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(JWTIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(JWTInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPTemplateJWTSuffix),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
&idpEvent,
|
||||
ops...,
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *idpTemplateProjection) reduceGoogleIDPAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
var idpEvent idp.GoogleIDPAddedEvent
|
||||
var idpOwnerType domain.IdentityProviderType
|
||||
@@ -621,6 +1177,40 @@ func reduceOAuthIDPChangedColumns(idpEvent idp.OAuthIDPChangedEvent) []handler.C
|
||||
return oauthCols
|
||||
}
|
||||
|
||||
func reduceOIDCIDPChangedColumns(idpEvent idp.OIDCIDPChangedEvent) []handler.Column {
|
||||
oidcCols := make([]handler.Column, 0, 4)
|
||||
if idpEvent.ClientID != nil {
|
||||
oidcCols = append(oidcCols, handler.NewCol(OIDCClientIDCol, *idpEvent.ClientID))
|
||||
}
|
||||
if idpEvent.ClientSecret != nil {
|
||||
oidcCols = append(oidcCols, handler.NewCol(OIDCClientSecretCol, *idpEvent.ClientSecret))
|
||||
}
|
||||
if idpEvent.Issuer != nil {
|
||||
oidcCols = append(oidcCols, handler.NewCol(OIDCIssuerCol, *idpEvent.Issuer))
|
||||
}
|
||||
if idpEvent.Scopes != nil {
|
||||
oidcCols = append(oidcCols, handler.NewCol(OIDCScopesCol, database.StringArray(idpEvent.Scopes)))
|
||||
}
|
||||
return oidcCols
|
||||
}
|
||||
|
||||
func reduceJWTIDPChangedColumns(idpEvent idp.JWTIDPChangedEvent) []handler.Column {
|
||||
jwtCols := make([]handler.Column, 0, 4)
|
||||
if idpEvent.JWTEndpoint != nil {
|
||||
jwtCols = append(jwtCols, handler.NewCol(JWTEndpointCol, *idpEvent.JWTEndpoint))
|
||||
}
|
||||
if idpEvent.KeysEndpoint != nil {
|
||||
jwtCols = append(jwtCols, handler.NewCol(JWTKeysEndpointCol, *idpEvent.KeysEndpoint))
|
||||
}
|
||||
if idpEvent.HeaderName != nil {
|
||||
jwtCols = append(jwtCols, handler.NewCol(JWTHeaderNameCol, *idpEvent.HeaderName))
|
||||
}
|
||||
if idpEvent.Issuer != nil {
|
||||
jwtCols = append(jwtCols, handler.NewCol(JWTIssuerCol, *idpEvent.Issuer))
|
||||
}
|
||||
return jwtCols
|
||||
}
|
||||
|
||||
func reduceGoogleIDPChangedColumns(idpEvent idp.GoogleIDPChangedEvent) []handler.Column {
|
||||
googleCols := make([]handler.Column, 0, 3)
|
||||
if idpEvent.ClientID != nil {
|
||||
|
@@ -41,7 +41,7 @@ func TestIDPTemplateProjection_reducesRemove(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.idp_templates WHERE (instance_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.idp_templates2 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_templates SET (change_date, sequence, owner_removed) = ($1, $2, $3) WHERE (instance_id = $4) AND (resource_owner = $5)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2 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_templates WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.idp_templates2 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -144,8 +144,8 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"name": "custom-zitadel-instance",
|
||||
"client_id": "client_id",
|
||||
"client_secret": {
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
"keyId": "key-id"
|
||||
@@ -169,7 +169,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates (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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
@@ -188,7 +188,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates_oauth (idp_id, instance_id, client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedStmt: "INSERT INTO projections.idp_templates2_oauth (idp_id, instance_id, client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -213,8 +213,8 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"name": "custom-zitadel-instance",
|
||||
"client_id": "client_id",
|
||||
"client_secret": {
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
"keyId": "key-id"
|
||||
@@ -238,7 +238,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates (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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
@@ -257,7 +257,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates_oauth (idp_id, instance_id, client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedStmt: "INSERT INTO projections.idp_templates2_oauth (idp_id, instance_id, client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -282,7 +282,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"isCreationAllowed": true,
|
||||
"client_id": "id"
|
||||
"clientId": "id"
|
||||
}`),
|
||||
), instance.OAuthIDPChangedEventMapper),
|
||||
},
|
||||
@@ -294,7 +294,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
anyArg{},
|
||||
@@ -304,7 +304,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates_oauth SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2_oauth SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"id",
|
||||
"idp-id",
|
||||
@@ -324,8 +324,8 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"name": "custom-zitadel-instance",
|
||||
"client_id": "client_id",
|
||||
"client_secret": {
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
"keyId": "key-id"
|
||||
@@ -349,7 +349,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates 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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"custom-zitadel-instance",
|
||||
true,
|
||||
@@ -363,7 +363,7 @@ func TestIDPTemplateProjection_reducesOAuth(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates_oauth SET (client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes) = ($1, $2, $3, $4, $5, $6) WHERE (idp_id = $7) AND (instance_id = $8)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2_oauth SET (client_id, client_secret, authorization_endpoint, token_endpoint, user_endpoint, scopes) = ($1, $2, $3, $4, $5, $6) WHERE (idp_id = $7) AND (instance_id = $8)",
|
||||
expectedArgs: []interface{}{
|
||||
"client_id",
|
||||
anyArg{},
|
||||
@@ -413,7 +413,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"clientID": "client_id",
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
@@ -435,7 +435,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates (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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
@@ -454,7 +454,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates_google (idp_id, instance_id, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedStmt: "INSERT INTO projections.idp_templates2_google (idp_id, instance_id, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -475,7 +475,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"clientID": "client_id",
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
@@ -497,7 +497,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates (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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
@@ -516,7 +516,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates_google (idp_id, instance_id, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedStmt: "INSERT INTO projections.idp_templates2_google (idp_id, instance_id, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -538,7 +538,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"isCreationAllowed": true,
|
||||
"clientID": "id"
|
||||
"clientId": "id"
|
||||
}`),
|
||||
), instance.GoogleIDPChangedEventMapper),
|
||||
},
|
||||
@@ -550,7 +550,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2 SET (is_creation_allowed, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
anyArg{},
|
||||
@@ -560,7 +560,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates_google SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2_google SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"id",
|
||||
"idp-id",
|
||||
@@ -579,7 +579,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"clientID": "client_id",
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
@@ -601,7 +601,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates 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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
true,
|
||||
@@ -614,7 +614,7 @@ func TestIDPTemplateProjection_reducesGoogle(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates_google SET (client_id, client_secret, scopes) = ($1, $2, $3) WHERE (idp_id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2_google SET (client_id, client_secret, scopes) = ($1, $2, $3) WHERE (idp_id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"client_id",
|
||||
anyArg{},
|
||||
@@ -702,7 +702,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates (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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
@@ -721,7 +721,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates_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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -801,7 +801,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates (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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
@@ -820,7 +820,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates_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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -872,7 +872,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates SET (name, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2 SET (name, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
"custom-zitadel-instance",
|
||||
anyArg{},
|
||||
@@ -882,7 +882,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates_ldap SET host = $1 WHERE (idp_id = $2) AND (instance_id = $3)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2_ldap SET host = $1 WHERE (idp_id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"host",
|
||||
"idp-id",
|
||||
@@ -942,7 +942,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates 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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"custom-zitadel-instance",
|
||||
true,
|
||||
@@ -956,7 +956,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates_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_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)",
|
||||
expectedArgs: []interface{}{
|
||||
"host",
|
||||
"port",
|
||||
@@ -1004,7 +1004,7 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates SET (change_date, sequence, owner_removed) = ($1, $2, $3) WHERE (instance_id = $4) AND (resource_owner = $5)",
|
||||
expectedStmt: "UPDATE projections.idp_templates2 SET (change_date, sequence, owner_removed) = ($1, $2, $3) WHERE (instance_id = $4) AND (resource_owner = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -1032,3 +1032,499 @@ func TestIDPTemplateProjection_reducesLDAP(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIDPTemplateProjection_reducesOIDC(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 reduceOIDCIDPAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.OIDCIDPAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"issuer": "issuer",
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
"keyId": "key-id"
|
||||
},
|
||||
"scopes": ["profile"],
|
||||
"isCreationAllowed": true,
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true
|
||||
}`),
|
||||
), instance.OIDCIDPAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpTemplateProjection{}).reduceOIDCIDPAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.IDPStateActive,
|
||||
"",
|
||||
domain.IdentityProviderTypeSystem,
|
||||
domain.IDPTypeOIDC,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates2_oidc (idp_id, instance_id, issuer, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
"issuer",
|
||||
"client_id",
|
||||
anyArg{},
|
||||
database.StringArray{"profile"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "org reduceOIDCIDPAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OIDCIDPAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"issuer": "issuer",
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
"keyId": "key-id"
|
||||
},
|
||||
"scopes": ["profile"],
|
||||
"isCreationAllowed": true,
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true
|
||||
}`),
|
||||
), org.OIDCIDPAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpTemplateProjection{}).reduceOIDCIDPAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.IDPStateActive,
|
||||
"",
|
||||
domain.IdentityProviderTypeOrg,
|
||||
domain.IDPTypeOIDC,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates2_oidc (idp_id, instance_id, issuer, client_id, client_secret, scopes) VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
"issuer",
|
||||
"client_id",
|
||||
anyArg{},
|
||||
database.StringArray{"profile"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "instance reduceOIDCIDPChanged minimal",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.OIDCIDPChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"isCreationAllowed": true,
|
||||
"clientId": "id"
|
||||
}`),
|
||||
), instance.OIDCIDPChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpTemplateProjection{}).reduceOIDCIDPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates2_oidc SET client_id = $1 WHERE (idp_id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"id",
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "instance reduceOIDCIDPChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.OIDCIDPChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"issuer": "issuer",
|
||||
"clientId": "client_id",
|
||||
"clientSecret": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
"keyId": "key-id"
|
||||
},
|
||||
"scopes": ["profile"],
|
||||
"isCreationAllowed": true,
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true
|
||||
}`),
|
||||
), instance.OIDCIDPChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpTemplateProjection{}).reduceOIDCIDPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
"client_id",
|
||||
anyArg{},
|
||||
"issuer",
|
||||
database.StringArray{"profile"},
|
||||
"idp-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
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
reduce func(event eventstore.Event) (*handler.Statement, error)
|
||||
want wantReduce
|
||||
}{
|
||||
{
|
||||
name: "instance reduceJWTIDPAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.JWTIDPAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"issuer": "issuer",
|
||||
"jwtEndpoint": "jwt",
|
||||
"keysEndpoint": "keys",
|
||||
"headerName": "header",
|
||||
"isCreationAllowed": true,
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true
|
||||
}`),
|
||||
), instance.JWTIDPAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpTemplateProjection{}).reduceJWTIDPAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.IDPStateActive,
|
||||
"",
|
||||
domain.IdentityProviderTypeSystem,
|
||||
domain.IDPTypeJWT,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
},
|
||||
},
|
||||
{
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
"issuer",
|
||||
"jwt",
|
||||
"keys",
|
||||
"header",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "org reduceJWTIDPAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.JWTIDPAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"issuer": "issuer",
|
||||
"jwtEndpoint": "jwt",
|
||||
"keysEndpoint": "keys",
|
||||
"headerName": "header",
|
||||
"isCreationAllowed": true,
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true
|
||||
}`),
|
||||
), org.JWTIDPAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpTemplateProjection{}).reduceJWTIDPAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
domain.IDPStateActive,
|
||||
"",
|
||||
domain.IdentityProviderTypeOrg,
|
||||
domain.IDPTypeJWT,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
},
|
||||
},
|
||||
{
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
"issuer",
|
||||
"jwt",
|
||||
"keys",
|
||||
"header",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "instance reduceJWTIDPChanged minimal",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.JWTIDPChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"isCreationAllowed": true,
|
||||
"jwtEndpoint": "jwt"
|
||||
}`),
|
||||
), instance.JWTIDPChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpTemplateProjection{}).reduceJWTIDPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates2_jwt SET jwt_endpoint = $1 WHERE (idp_id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"jwt",
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "instance reduceJWTIDPChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.JWTIDPChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "idp-id",
|
||||
"issuer": "issuer",
|
||||
"jwtEndpoint": "jwt",
|
||||
"keysEndpoint": "keys",
|
||||
"headerName": "header",
|
||||
"isCreationAllowed": true,
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true
|
||||
}`),
|
||||
), instance.JWTIDPChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpTemplateProjection{}).reduceJWTIDPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
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)",
|
||||
expectedArgs: []interface{}{
|
||||
"jwt",
|
||||
"keys",
|
||||
"header",
|
||||
"issuer",
|
||||
"idp-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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user