mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
f3e6f3b23b
* feat(command): remove org * refactor: imports, unused code, error handling * reduce org removed in action * add org deletion to projections * add org removal to projections * add org removal to projections * org removed projection * lint import * projections * fix: table names in tests * fix: table names in tests * logging * add org state * fix(domain): add Owner removed to object details * feat(ListQuery): add with owner removed * fix(org-delete): add bool to functions to select with owner removed * fix(org-delete): add bools to user grants with events to determine if dependencies lost owner * fix(org-delete): add unit tests for owner removed and org removed events * fix(org-delete): add handling of org remove for grants and members * fix(org-delete): correction of unit tests for owner removed * fix(org-delete): update projections, unit tests and get functions * fix(org-delete): add change date to authnkeys and owner removed to org metadata * fix(org-delete): include owner removed for login names * fix(org-delete): some column fixes in projections and build for queries with owner removed * indexes * fix(org-delete): include review changes * fix(org-delete): change user projection name after merge * fix(org-delete): include review changes for project grant where no project owner is necessary * fix(org-delete): include auth and adminapi tables with owner removed information * fix(org-delete): cleanup username and orgdomain uniqueconstraints when org is removed * fix(org-delete): add permissions for org.remove * remove unnecessary unique constraints * fix column order in primary keys * fix(org-delete): include review changes * fix(org-delete): add owner removed indexes and chang setup step to create tables * fix(org-delete): move PK order of instance_id and change added user_grant from review * fix(org-delete): no params for prepareUserQuery * change to step 6 * merge main * fix(org-delete): OldUserName rename to private * fix linting * cleanup * fix: remove org test * create prerelease * chore: delete org-delete as prerelease Co-authored-by: Stefan Benz <stefan@caos.ch> Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
937 lines
27 KiB
Go
937 lines
27 KiB
Go
package projection
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
|
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
|
)
|
|
|
|
func TestIDPProjection_reduces(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 reduceIDPAdded",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPConfigAddedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"name": "custom-zitadel-instance",
|
|
"idpType": 0,
|
|
"stylingType": 0,
|
|
"autoRegister": true
|
|
}`),
|
|
), instance.IDPConfigAddedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPAdded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "INSERT INTO projections.idps3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, styling_type, auto_register, owner_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
|
expectedArgs: []interface{}{
|
|
"idp-config-id",
|
|
anyArg{},
|
|
anyArg{},
|
|
uint64(15),
|
|
"ro-id",
|
|
"instance-id",
|
|
domain.IDPConfigStateActive,
|
|
"custom-zitadel-instance",
|
|
domain.IDPConfigStylingTypeUnspecified,
|
|
true,
|
|
domain.IdentityProviderTypeSystem,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceIDPChanged",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPConfigChangedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"name": "custom-zitadel-instance",
|
|
"stylingType": 1,
|
|
"autoRegister": true
|
|
}`),
|
|
), instance.IDPConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (name, styling_type, auto_register, change_date, sequence) = ($1, $2, $3, $4, $5) WHERE (id = $6) AND (instance_id = $7)",
|
|
expectedArgs: []interface{}{
|
|
"custom-zitadel-instance",
|
|
domain.IDPConfigStylingTypeGoogle,
|
|
true,
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceIDPDeactivated",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPConfigDeactivatedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id"
|
|
}`),
|
|
), instance.IDPConfigDeactivatedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPDeactivated,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
|
expectedArgs: []interface{}{
|
|
domain.IDPConfigStateInactive,
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceIDPReactivated",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPConfigReactivatedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id"
|
|
}`),
|
|
), instance.IDPConfigReactivatedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPReactivated,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
|
expectedArgs: []interface{}{
|
|
domain.IDPConfigStateActive,
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceIDPRemoved",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPConfigRemovedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id"
|
|
}`),
|
|
), instance.IDPConfigRemovedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPRemoved,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "DELETE FROM projections.idps3 WHERE (id = $1) AND (instance_id = $2)",
|
|
expectedArgs: []interface{}{
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceInstanceRemoved",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.InstanceRemovedEventType),
|
|
instance.AggregateType,
|
|
nil,
|
|
), instance.InstanceRemovedEventMapper),
|
|
},
|
|
reduce: reduceInstanceRemovedHelper(IDPInstanceIDCol),
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "DELETE FROM projections.idps3 WHERE (instance_id = $1)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceOIDCConfigAdded",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPOIDCConfigAddedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"clientId": "client-id",
|
|
"clientSecret": {
|
|
"cryptoType": 0,
|
|
"algorithm": "RSA-265",
|
|
"keyId": "key-id"
|
|
},
|
|
"issuer": "issuer",
|
|
"authorizationEndpoint": "https://api.zitadel.ch/authorize",
|
|
"tokenEndpoint": "https://api.zitadel.ch/token",
|
|
"scopes": ["profile"],
|
|
"idpDisplayNameMapping": 0,
|
|
"usernameMapping": 1
|
|
}`),
|
|
), instance.IDPOIDCConfigAddedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceOIDCConfigAdded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
domain.IDPConfigTypeOIDC,
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
{
|
|
expectedStmt: "INSERT INTO projections.idps3_oidc_config (idp_id, instance_id, client_id, client_secret, issuer, scopes, display_name_mapping, username_mapping, authorization_endpoint, token_endpoint) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
|
expectedArgs: []interface{}{
|
|
"idp-config-id",
|
|
"instance-id",
|
|
"client-id",
|
|
anyArg{},
|
|
"issuer",
|
|
database.StringArray{"profile"},
|
|
domain.OIDCMappingFieldUnspecified,
|
|
domain.OIDCMappingFieldPreferredLoginName,
|
|
"https://api.zitadel.ch/authorize",
|
|
"https://api.zitadel.ch/token",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceOIDCConfigChanged",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPOIDCConfigChangedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"clientId": "client-id",
|
|
"clientSecret": {
|
|
"cryptoType": 0,
|
|
"algorithm": "RSA-265",
|
|
"keyId": "key-id"
|
|
},
|
|
"issuer": "issuer",
|
|
"authorizationEndpoint": "https://api.zitadel.ch/authorize",
|
|
"tokenEndpoint": "https://api.zitadel.ch/token",
|
|
"scopes": ["profile"],
|
|
"idpDisplayNameMapping": 0,
|
|
"usernameMapping": 1
|
|
}`),
|
|
), instance.IDPOIDCConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceOIDCConfigChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3_oidc_config SET (client_id, client_secret, issuer, authorization_endpoint, token_endpoint, scopes, display_name_mapping, username_mapping) = ($1, $2, $3, $4, $5, $6, $7, $8) WHERE (idp_id = $9) AND (instance_id = $10)",
|
|
expectedArgs: []interface{}{
|
|
"client-id",
|
|
anyArg{},
|
|
"issuer",
|
|
"https://api.zitadel.ch/authorize",
|
|
"https://api.zitadel.ch/token",
|
|
database.StringArray{"profile"},
|
|
domain.OIDCMappingFieldUnspecified,
|
|
domain.OIDCMappingFieldPreferredLoginName,
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceOIDCConfigChanged: no op",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPOIDCConfigChangedEventType),
|
|
instance.AggregateType,
|
|
[]byte("{}"),
|
|
), instance.IDPOIDCConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceOIDCConfigChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceJWTConfigAdded",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPJWTConfigAddedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"jwtEndpoint": "https://api.zitadel.ch/jwt",
|
|
"issuer": "issuer",
|
|
"keysEndpoint": "https://api.zitadel.ch/keys",
|
|
"headerName": "hodor"
|
|
}`),
|
|
), instance.IDPJWTConfigAddedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceJWTConfigAdded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
domain.IDPConfigTypeJWT,
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
{
|
|
expectedStmt: "INSERT INTO projections.idps3_jwt_config (idp_id, instance_id, endpoint, issuer, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5, $6)",
|
|
expectedArgs: []interface{}{
|
|
"idp-config-id",
|
|
"instance-id",
|
|
"https://api.zitadel.ch/jwt",
|
|
"issuer",
|
|
"https://api.zitadel.ch/keys",
|
|
"hodor",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceJWTConfigChanged",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPJWTConfigChangedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"jwtEndpoint": "https://api.zitadel.ch/jwt",
|
|
"issuer": "issuer",
|
|
"keysEndpoint": "https://api.zitadel.ch/keys",
|
|
"headerName": "hodor"
|
|
}`),
|
|
), instance.IDPJWTConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceJWTConfigChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3_jwt_config SET (endpoint, issuer, keys_endpoint, header_name) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)",
|
|
expectedArgs: []interface{}{
|
|
"https://api.zitadel.ch/jwt",
|
|
"issuer",
|
|
"https://api.zitadel.ch/keys",
|
|
"hodor",
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceJWTConfigChanged: no op",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(instance.IDPJWTConfigChangedEventType),
|
|
instance.AggregateType,
|
|
[]byte(`{}`),
|
|
), instance.IDPJWTConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceJWTConfigChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceIDPAdded",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPConfigAddedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"name": "custom-zitadel-instance",
|
|
"idpType": 0,
|
|
"stylingType": 0,
|
|
"autoRegister": true
|
|
}`),
|
|
), org.IDPConfigAddedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPAdded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "INSERT INTO projections.idps3 (id, creation_date, change_date, sequence, resource_owner, instance_id, state, name, styling_type, auto_register, owner_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
|
expectedArgs: []interface{}{
|
|
"idp-config-id",
|
|
anyArg{},
|
|
anyArg{},
|
|
uint64(15),
|
|
"ro-id",
|
|
"instance-id",
|
|
domain.IDPConfigStateActive,
|
|
"custom-zitadel-instance",
|
|
domain.IDPConfigStylingTypeUnspecified,
|
|
true,
|
|
domain.IdentityProviderTypeOrg,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceIDPChanged",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPConfigChangedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"name": "custom-zitadel-instance",
|
|
"stylingType": 1,
|
|
"autoRegister": true
|
|
}`),
|
|
), org.IDPConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (name, styling_type, auto_register, change_date, sequence) = ($1, $2, $3, $4, $5) WHERE (id = $6) AND (instance_id = $7)",
|
|
expectedArgs: []interface{}{
|
|
"custom-zitadel-instance",
|
|
domain.IDPConfigStylingTypeGoogle,
|
|
true,
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceIDPDeactivated",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPConfigDeactivatedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id"
|
|
}`),
|
|
), org.IDPConfigDeactivatedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPDeactivated,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
|
expectedArgs: []interface{}{
|
|
domain.IDPConfigStateInactive,
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceIDPReactivated",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPConfigReactivatedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id"
|
|
}`),
|
|
), org.IDPConfigReactivatedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPReactivated,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (state, change_date, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
|
expectedArgs: []interface{}{
|
|
domain.IDPConfigStateActive,
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceIDPRemoved",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPConfigRemovedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id"
|
|
}`),
|
|
), org.IDPConfigRemovedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceIDPRemoved,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "DELETE FROM projections.idps3 WHERE (id = $1) AND (instance_id = $2)",
|
|
expectedArgs: []interface{}{
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceOIDCConfigAdded",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPOIDCConfigAddedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"clientId": "client-id",
|
|
"clientSecret": {
|
|
"cryptoType": 0,
|
|
"algorithm": "RSA-265",
|
|
"keyId": "key-id"
|
|
},
|
|
"issuer": "issuer",
|
|
"authorizationEndpoint": "https://api.zitadel.ch/authorize",
|
|
"tokenEndpoint": "https://api.zitadel.ch/token",
|
|
"scopes": ["profile"],
|
|
"idpDisplayNameMapping": 0,
|
|
"usernameMapping": 1
|
|
}`),
|
|
), org.IDPOIDCConfigAddedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceOIDCConfigAdded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
domain.IDPConfigTypeOIDC,
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
{
|
|
expectedStmt: "INSERT INTO projections.idps3_oidc_config (idp_id, instance_id, client_id, client_secret, issuer, scopes, display_name_mapping, username_mapping, authorization_endpoint, token_endpoint) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
|
expectedArgs: []interface{}{
|
|
"idp-config-id",
|
|
"instance-id",
|
|
"client-id",
|
|
anyArg{},
|
|
"issuer",
|
|
database.StringArray{"profile"},
|
|
domain.OIDCMappingFieldUnspecified,
|
|
domain.OIDCMappingFieldPreferredLoginName,
|
|
"https://api.zitadel.ch/authorize",
|
|
"https://api.zitadel.ch/token",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceOIDCConfigChanged",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPOIDCConfigChangedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"clientId": "client-id",
|
|
"clientSecret": {
|
|
"cryptoType": 0,
|
|
"algorithm": "RSA-265",
|
|
"keyId": "key-id"
|
|
},
|
|
"issuer": "issuer",
|
|
"authorizationEndpoint": "https://api.zitadel.ch/authorize",
|
|
"tokenEndpoint": "https://api.zitadel.ch/token",
|
|
"scopes": ["profile"],
|
|
"idpDisplayNameMapping": 0,
|
|
"usernameMapping": 1
|
|
}`),
|
|
), org.IDPOIDCConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceOIDCConfigChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3_oidc_config SET (client_id, client_secret, issuer, authorization_endpoint, token_endpoint, scopes, display_name_mapping, username_mapping) = ($1, $2, $3, $4, $5, $6, $7, $8) WHERE (idp_id = $9) AND (instance_id = $10)",
|
|
expectedArgs: []interface{}{
|
|
"client-id",
|
|
anyArg{},
|
|
"issuer",
|
|
"https://api.zitadel.ch/authorize",
|
|
"https://api.zitadel.ch/token",
|
|
database.StringArray{"profile"},
|
|
domain.OIDCMappingFieldUnspecified,
|
|
domain.OIDCMappingFieldPreferredLoginName,
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceOIDCConfigChanged: no op",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPOIDCConfigChangedEventType),
|
|
org.AggregateType,
|
|
[]byte("{}"),
|
|
), org.IDPOIDCConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceOIDCConfigChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceJWTConfigAdded",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPJWTConfigAddedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"jwtEndpoint": "https://api.zitadel.ch/jwt",
|
|
"issuer": "issuer",
|
|
"keysEndpoint": "https://api.zitadel.ch/keys",
|
|
"headerName": "hodor"
|
|
}`),
|
|
), org.IDPJWTConfigAddedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceJWTConfigAdded,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence, type) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
domain.IDPConfigTypeJWT,
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
{
|
|
expectedStmt: "INSERT INTO projections.idps3_jwt_config (idp_id, instance_id, endpoint, issuer, keys_endpoint, header_name) VALUES ($1, $2, $3, $4, $5, $6)",
|
|
expectedArgs: []interface{}{
|
|
"idp-config-id",
|
|
"instance-id",
|
|
"https://api.zitadel.ch/jwt",
|
|
"issuer",
|
|
"https://api.zitadel.ch/keys",
|
|
"hodor",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceJWTConfigChanged",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPJWTConfigChangedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{
|
|
"idpConfigId": "idp-config-id",
|
|
"jwtEndpoint": "https://api.zitadel.ch/jwt",
|
|
"issuer": "issuer",
|
|
"keysEndpoint": "https://api.zitadel.ch/keys",
|
|
"headerName": "hodor"
|
|
}`),
|
|
), org.IDPJWTConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceJWTConfigChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3_jwt_config SET (endpoint, issuer, keys_endpoint, header_name) = ($1, $2, $3, $4) WHERE (idp_id = $5) AND (instance_id = $6)",
|
|
expectedArgs: []interface{}{
|
|
"https://api.zitadel.ch/jwt",
|
|
"issuer",
|
|
"https://api.zitadel.ch/keys",
|
|
"hodor",
|
|
"idp-config-id",
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org reduceJWTConfigChanged: no op",
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.IDPJWTConfigChangedEventType),
|
|
org.AggregateType,
|
|
[]byte(`{}`),
|
|
), org.IDPJWTConfigChangedEventMapper),
|
|
},
|
|
reduce: (&idpProjection{}).reduceJWTConfigChanged,
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "org.reduceOwnerRemoved",
|
|
reduce: (&idpProjection{}).reduceOwnerRemoved,
|
|
args: args{
|
|
event: getEvent(testEvent(
|
|
repository.EventType(org.OrgRemovedEventType),
|
|
org.AggregateType,
|
|
nil,
|
|
), org.OrgRemovedEventMapper),
|
|
},
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
sequence: 15,
|
|
previousSequence: 10,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.idps3 SET (change_date, sequence, owner_removed) = ($1, $2, $3) WHERE (instance_id = $4) AND (resource_owner = $5)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
true,
|
|
"instance-id",
|
|
"agg-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
event := baseEvent(t)
|
|
got, err := tt.reduce(event)
|
|
if _, ok := err.(errors.InvalidArgument); !ok {
|
|
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, IDPTable, tt.want)
|
|
})
|
|
}
|
|
}
|