mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
db1d8f4efe
* feat: oidc config * fix: oidc configurations * feat: oidc idp config * feat: add oidc config test * fix: tests * fix: tests * feat: translate new events * feat: idp eventstore * feat: idp eventstore * fix: tests * feat: command side idp * feat: query side idp * feat: idp config on org * fix: tests * feat: authz idp on org * feat: org idps * feat: login policy * feat: login policy * feat: login policy * feat: add idp func on login policy * feat: add validation to loginpolicy and idp provider * feat: add default login policy * feat: login policy on org * feat: login policy on org * fix: id config handlers * fix: id config handlers * fix: create idp on org * fix: create idp on org * fix: not existing idp config * fix: default login policy * fix: add login policy on org * fix: idp provider search on org * fix: test * fix: remove idp on org * fix: test * fix: test * fix: remove admin idp * fix: logo src as byte * fix: migration * fix: tests * Update internal/iam/repository/eventsourcing/iam.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/iam_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/iam_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/org/repository/eventsourcing/org_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: pr comments * fix: tests * Update types.go * fix: merge request changes * fix: reduce optimization Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com>
133 lines
6.0 KiB
Go
133 lines
6.0 KiB
Go
package eventsourcing
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
"github.com/caos/zitadel/internal/id"
|
|
|
|
mock_cache "github.com/caos/zitadel/internal/cache/mock"
|
|
"github.com/caos/zitadel/internal/eventstore/mock"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
"github.com/golang/mock/gomock"
|
|
)
|
|
|
|
func GetMockedEventstore(ctrl *gomock.Controller, mockEs *mock.MockEventstore) *IAMEventstore {
|
|
return &IAMEventstore{
|
|
Eventstore: mockEs,
|
|
iamCache: GetMockCache(ctrl),
|
|
idGenerator: GetSonyFlacke(),
|
|
}
|
|
}
|
|
|
|
func GetMockedEventstoreWithCrypto(ctrl *gomock.Controller, mockEs *mock.MockEventstore) *IAMEventstore {
|
|
return &IAMEventstore{
|
|
Eventstore: mockEs,
|
|
iamCache: GetMockCache(ctrl),
|
|
idGenerator: GetSonyFlacke(),
|
|
secretCrypto: crypto.NewBCrypt(10),
|
|
}
|
|
}
|
|
func GetMockCache(ctrl *gomock.Controller) *IAMCache {
|
|
mockCache := mock_cache.NewMockCache(ctrl)
|
|
mockCache.EXPECT().Get(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
|
mockCache.EXPECT().Set(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
|
return &IAMCache{iamCache: mockCache}
|
|
}
|
|
|
|
func GetSonyFlacke() id.Generator {
|
|
return id.SonyFlakeGenerator
|
|
}
|
|
|
|
func GetMockIamByIDOK(ctrl *gomock.Controller) *IAMEventstore {
|
|
data, _ := json.Marshal(model.IAM{GlobalOrgID: "GlobalOrgID"})
|
|
events := []*es_models.Event{
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.IAMSetupStarted},
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.GlobalOrgSet, Data: data},
|
|
}
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
}
|
|
|
|
func GetMockIamByIDNoEvents(ctrl *gomock.Controller) *IAMEventstore {
|
|
events := []*es_models.Event{}
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
}
|
|
|
|
func GetMockManipulateIam(ctrl *gomock.Controller) *IAMEventstore {
|
|
events := []*es_models.Event{
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.IAMSetupStarted},
|
|
}
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
}
|
|
|
|
func GetMockManipulateIamWithCrypto(ctrl *gomock.Controller) *IAMEventstore {
|
|
events := []*es_models.Event{
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.IAMSetupStarted},
|
|
}
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
|
return GetMockedEventstoreWithCrypto(ctrl, mockEs)
|
|
}
|
|
|
|
func GetMockManipulateIamWithMember(ctrl *gomock.Controller) *IAMEventstore {
|
|
memberData, _ := json.Marshal(model.IAMMember{UserID: "UserID", Roles: []string{"Role"}})
|
|
events := []*es_models.Event{
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.IAMSetupStarted},
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.IAMMemberAdded, Data: memberData},
|
|
}
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
}
|
|
|
|
func GetMockManipulateIamWithOIDCIdp(ctrl *gomock.Controller) *IAMEventstore {
|
|
idpData, _ := json.Marshal(model.IDPConfig{IDPConfigID: "IDPConfigID", Name: "Name"})
|
|
oidcData, _ := json.Marshal(model.OIDCIDPConfig{IDPConfigID: "IDPConfigID", ClientID: "ClientID"})
|
|
events := []*es_models.Event{
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.IAMSetupStarted},
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.IDPConfigAdded, Data: idpData},
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.OIDCIDPConfigAdded, Data: oidcData},
|
|
}
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
}
|
|
|
|
func GetMockManipulateIamWithLoginPolicy(ctrl *gomock.Controller) *IAMEventstore {
|
|
policyData, _ := json.Marshal(model.LoginPolicy{AllowRegister: true, AllowUsernamePassword: true, AllowExternalIdp: true})
|
|
idpProviderData, _ := json.Marshal(model.IDPProvider{IDPConfigID: "IDPConfigID", Type: 1})
|
|
events := []*es_models.Event{
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.IAMSetupStarted},
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.LoginPolicyAdded, Data: policyData},
|
|
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: model.LoginPolicyIDPProviderAdded, Data: idpProviderData},
|
|
}
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
}
|
|
|
|
func GetMockManipulateIamNotExisting(ctrl *gomock.Controller) *IAMEventstore {
|
|
events := []*es_models.Event{}
|
|
mockEs := mock.NewMockEventstore(ctrl)
|
|
mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil)
|
|
mockEs.EXPECT().AggregateCreator().Return(es_models.NewAggregateCreator("TEST"))
|
|
mockEs.EXPECT().PushAggregates(gomock.Any(), gomock.Any()).Return(nil)
|
|
return GetMockedEventstore(ctrl, mockEs)
|
|
}
|