mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
fix: handle project deactivate and remove correctly on tokens (#6947)
This commit is contained in:
parent
492b7d8676
commit
ad3563d58b
@ -219,7 +219,7 @@ func (t *Token) Reduce(event eventstore.Event) (_ *handler.Statement, err error)
|
||||
}
|
||||
applicationIDs := make([]string, 0, len(project.Applications))
|
||||
for _, app := range project.Applications {
|
||||
if app.OIDCConfig != nil {
|
||||
if app.OIDCConfig != nil && app.OIDCConfig.ClientID != "" {
|
||||
applicationIDs = append(applicationIDs, app.OIDCConfig.ClientID)
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func (p *Project) appendRemovedEvent() error {
|
||||
|
||||
func (p *Project) appendOIDCConfig(event eventstore.Event) error {
|
||||
appEvent := new(oidcApp)
|
||||
if err := event.Unmarshal(p); err != nil {
|
||||
if err := event.Unmarshal(appEvent); err != nil {
|
||||
return err
|
||||
}
|
||||
p.OIDCApplications = append(p.OIDCApplications, appEvent)
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/project/model"
|
||||
@ -40,6 +42,27 @@ func TestProjectFromEvents(t *testing.T) {
|
||||
},
|
||||
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateActive)},
|
||||
},
|
||||
{
|
||||
name: "project from events with OIDC Application, ok",
|
||||
args: args{
|
||||
event: []eventstore.Event{
|
||||
&es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ProjectAddedType, Data: []byte(`{"name": "ProjectName"}`)},
|
||||
&es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.OIDCConfigAddedType, Data: []byte(`{"appId":"appId", "clientId": "clientID"}`)},
|
||||
},
|
||||
project: nil,
|
||||
},
|
||||
result: &Project{
|
||||
ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"},
|
||||
State: int32(model.ProjectStateActive),
|
||||
Name: "ProjectName",
|
||||
OIDCApplications: []*oidcApp{
|
||||
{
|
||||
AppID: "appID",
|
||||
ClientID: "clientID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@ -95,6 +118,30 @@ func TestAppendEvent(t *testing.T) {
|
||||
},
|
||||
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateActive)},
|
||||
},
|
||||
{
|
||||
name: "append oidc config added event",
|
||||
args: args{
|
||||
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.OIDCConfigAddedType, Data: []byte(`{"appId":"appID", "clientId": "clientID"}`)},
|
||||
},
|
||||
result: &Project{
|
||||
ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"},
|
||||
State: int32(model.ProjectStateActive),
|
||||
OIDCApplications: []*oidcApp{{
|
||||
AppID: "appID",
|
||||
ClientID: "clientID",
|
||||
}}},
|
||||
},
|
||||
{
|
||||
name: "append application removed event",
|
||||
args: args{
|
||||
project: &Project{Name: "ProjectName", OIDCApplications: []*oidcApp{{
|
||||
AppID: "appID",
|
||||
ClientID: "clientID",
|
||||
}}},
|
||||
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationRemovedType, Data: []byte(`{"appId": "appID"}`)},
|
||||
},
|
||||
result: &Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID"}, State: int32(model.ProjectStateActive)},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@ -113,6 +160,7 @@ func TestAppendEvent(t *testing.T) {
|
||||
if result.ObjectRoot.AggregateID != tt.result.ObjectRoot.AggregateID {
|
||||
t.Errorf("got wrong result id: expected: %v, actual: %v ", tt.result.ObjectRoot.AggregateID, result.ObjectRoot.AggregateID)
|
||||
}
|
||||
assert.Equal(t, tt.result.OIDCApplications, result.OIDCApplications)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user