mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
fix: handle project deactivate and remove correctly on tokens (#6947)
(cherry picked from commit ad3563d58b
)
This commit is contained in:
parent
3001d03bca
commit
7786b09444
@ -219,7 +219,7 @@ func (t *Token) Reduce(event eventstore.Event) (_ *handler.Statement, err error)
|
|||||||
}
|
}
|
||||||
applicationIDs := make([]string, 0, len(project.Applications))
|
applicationIDs := make([]string, 0, len(project.Applications))
|
||||||
for _, app := range project.Applications {
|
for _, app := range project.Applications {
|
||||||
if app.OIDCConfig != nil {
|
if app.OIDCConfig != nil && app.OIDCConfig.ClientID != "" {
|
||||||
applicationIDs = append(applicationIDs, 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 {
|
func (p *Project) appendOIDCConfig(event eventstore.Event) error {
|
||||||
appEvent := new(oidcApp)
|
appEvent := new(oidcApp)
|
||||||
if err := event.Unmarshal(p); err != nil {
|
if err := event.Unmarshal(appEvent); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.OIDCApplications = append(p.OIDCApplications, appEvent)
|
p.OIDCApplications = append(p.OIDCApplications, appEvent)
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/eventstore"
|
"github.com/zitadel/zitadel/internal/eventstore"
|
||||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||||
"github.com/zitadel/zitadel/internal/project/model"
|
"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)},
|
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 {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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)},
|
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 {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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 {
|
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)
|
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