fix: remove idps from org login policy after reset (#4327)

This commit is contained in:
Livio Spring 2022-09-07 14:17:52 +02:00 committed by GitHub
parent f71d158fb0
commit 04ce8b2479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -70,6 +70,10 @@ func (p *idpLoginPolicyLinkProjection) reducers() []handler.AggregateReducer {
Event: org.LoginPolicyIDPProviderRemovedEventType,
Reduce: p.reduceRemoved,
},
{
Event: org.LoginPolicyRemovedEventType,
Reduce: p.reducePolicyRemoved,
},
{
Event: org.OrgRemovedEventType,
Reduce: p.reduceOrgRemoved,
@ -206,3 +210,15 @@ func (p *idpLoginPolicyLinkProjection) reduceOrgRemoved(event eventstore.Event)
},
), nil
}
func (p *idpLoginPolicyLinkProjection) reducePolicyRemoved(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*org.LoginPolicyRemovedEvent)
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SF3dg", "reduce.wrong.event.type %s", org.LoginPolicyRemovedEventType)
}
return crdb.NewDeleteStatement(e,
[]handler.Condition{
handler.NewCond(IDPLoginPolicyLinkAggregateIDCol, e.Aggregate().ID),
},
), nil
}

View File

@ -247,6 +247,33 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
},
},
},
{
name: "reducePolicyRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(org.LoginPolicyRemovedEventType),
org.AggregateType,
nil,
), org.LoginPolicyRemovedEventMapper),
},
reduce: (&idpLoginPolicyLinkProjection{}).reducePolicyRemoved,
want: wantReduce{
aggregateType: org.AggregateType,
sequence: 15,
previousSequence: 10,
projection: IDPLoginPolicyLinkTable,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (aggregate_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
{
name: "org.IDPConfigRemovedEvent",
args: args{