mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:37:34 +00:00
feat: instance remove (#4345)
* feat(instance): add remove instance event with projections cleanup * fix(instance): corrected used id to clean up projections * fix merge * fix: correct unit test projection names * fix: current sequence of lists and query for ensuring keypair based projections Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"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/project"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
)
|
||||
@@ -33,7 +34,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyAdded,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -70,7 +70,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyAdded,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -107,7 +106,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -134,7 +132,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -154,7 +151,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -182,7 +178,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -210,7 +205,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -226,6 +220,32 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"name": "Name"}`),
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(AuthNKeyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.authn_keys WHERE (instance_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceAuthNKeyEnabledChanged oidc no change",
|
||||
args: args{
|
||||
@@ -237,7 +257,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -257,7 +276,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -285,7 +303,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -313,7 +330,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -340,7 +356,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -367,7 +382,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -394,7 +408,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -421,7 +434,6 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
projection: AuthNKeyTable,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
@@ -448,7 +460,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
|
||||
event = tt.args.event(t)
|
||||
got, err = tt.reduce(event)
|
||||
assertReduce(t, got, err, tt.want)
|
||||
assertReduce(t, got, err, AuthNKeyTable, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user