Skip to content

Commit

Permalink
unexport event store and add peerUpdateManager
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer committed Nov 22, 2024
1 parent 832e168 commit 72157b5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
4 changes: 2 additions & 2 deletions management/server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type DefaultAccountManager struct {
cacheManager cache.CacheInterface[[]*idp.UserData]
externalCacheManager ExternalCacheManager
ctx context.Context
EventStore activity.Store
eventStore activity.Store
geo geolocation.Geolocation

requestBuffer *AccountRequestBuffer
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func BuildManager(
cacheMux: sync.Mutex{},
cacheLoading: map[string]chan struct{}{},
dnsDomain: dnsDomain,
EventStore: eventStore,
eventStore: eventStore,
peerLoginExpiry: NewDefaultScheduler(),
peerInactivityExpiry: NewDefaultScheduler(),
userDeleteFromIDPEnabled: userDeleteFromIDPEnabled,
Expand Down
4 changes: 2 additions & 2 deletions management/server/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (am *DefaultAccountManager) GetEvents(ctx context.Context, accountID, userI
return nil, status.Errorf(status.PermissionDenied, "only users with admin power can view events")
}

events, err := am.EventStore.Get(ctx, accountID, 0, 10000, true)
events, err := am.eventStore.Get(ctx, accountID, 0, 10000, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -58,7 +58,7 @@ func (am *DefaultAccountManager) GetEvents(ctx context.Context, accountID, userI
func (am *DefaultAccountManager) StoreEvent(ctx context.Context, initiatorID, targetID, accountID string, activityID activity.ActivityDescriber, meta map[string]any) {

go func() {
_, err := am.EventStore.Save(ctx, &activity.Event{
_, err := am.eventStore.Save(ctx, &activity.Event{
Timestamp: time.Now().UTC(),
Activity: activityID,
InitiatorID: initiatorID,
Expand Down
8 changes: 4 additions & 4 deletions management/server/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func generateAndStoreEvents(t *testing.T, manager *DefaultAccountManager, typ ac
accountID string, count int) {
t.Helper()
for i := 0; i < count; i++ {
_, err := manager.EventStore.Save(context.Background(), &activity.Event{
_, err := manager.eventStore.Save(context.Background(), &activity.Event{
Timestamp: time.Now().UTC(),
Activity: typ,
InitiatorID: initiatorID,
Expand All @@ -41,7 +41,7 @@ func TestDefaultAccountManager_GetEvents(t *testing.T) {
return
}
assert.Len(t, events, 0)
_ = manager.EventStore.Close(context.Background()) //nolint
_ = manager.eventStore.Close(context.Background()) //nolint
})

t.Run("get events", func(t *testing.T) {
Expand All @@ -52,7 +52,7 @@ func TestDefaultAccountManager_GetEvents(t *testing.T) {
}

assert.Len(t, events, 10)
_ = manager.EventStore.Close(context.Background()) //nolint
_ = manager.eventStore.Close(context.Background()) //nolint
})

t.Run("get events without duplicates", func(t *testing.T) {
Expand All @@ -62,6 +62,6 @@ func TestDefaultAccountManager_GetEvents(t *testing.T) {
return
}
assert.Len(t, events, 1)
_ = manager.EventStore.Close(context.Background()) //nolint
_ = manager.eventStore.Close(context.Background()) //nolint
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ func Test_SetupKeys_Create_Success(t *testing.T) {
t.Cleanup(cleanup)

metrics, err := telemetry.NewDefaultAppMetrics(context.Background())
am := server.DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},

peersUpdateManager := &server.PeersUpdateManager{}
geoMock := &geolocation.GeolocationMock{}
validatorMock := server.MocIntegratedValidator{}
am, err := server.BuildManager(context.Background(), store, peersUpdateManager, nil, "", "", &activity.InMemoryEventStore{}, geoMock, false, validatorMock, metrics)
if err != nil {
t.Fatalf("Failed to create manager: %v", err)
}
apiHandler, err := APIHandler(context.Background(), &am, &geolocation.GeolocationMock{}, &jwtclaims.JwtValidatorMock{}, metrics, AuthCfg{}, server.MocIntegratedValidator{})

apiHandler, err := APIHandler(context.Background(), am, geoMock, &jwtclaims.JwtValidatorMock{}, metrics, AuthCfg{}, validatorMock)
if err != nil {
t.Fatalf("Failed to create API handler: %v", err)
}
Expand Down
44 changes: 22 additions & 22 deletions management/server/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestUser_CreatePAT_ForSameUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

pat, err := am.CreatePAT(context.Background(), mockAccountID, mockUserID, mockUserID, mockTokenName, mockExpiresIn)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestUser_CreatePAT_ForDifferentUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

_, err = am.CreatePAT(context.Background(), mockAccountID, mockUserID, mockTargetUserId, mockTokenName, mockExpiresIn)
Expand All @@ -119,7 +119,7 @@ func TestUser_CreatePAT_ForServiceUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

pat, err := am.CreatePAT(context.Background(), mockAccountID, mockUserID, mockTargetUserId, mockTokenName, mockExpiresIn)
Expand All @@ -142,7 +142,7 @@ func TestUser_CreatePAT_WithWrongExpiration(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

_, err = am.CreatePAT(context.Background(), mockAccountID, mockUserID, mockUserID, mockTokenName, mockWrongExpiresIn)
Expand All @@ -161,7 +161,7 @@ func TestUser_CreatePAT_WithEmptyName(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

_, err = am.CreatePAT(context.Background(), mockAccountID, mockUserID, mockUserID, mockEmptyTokenName, mockExpiresIn)
Expand All @@ -188,7 +188,7 @@ func TestUser_DeletePAT(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

err = am.DeletePAT(context.Background(), mockAccountID, mockUserID, mockUserID, mockTokenID1)
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestUser_GetPAT(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

pat, err := am.GetPAT(context.Background(), mockAccountID, mockUserID, mockUserID, mockTokenID1)
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestUser_GetAllPATs(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

pats, err := am.GetAllPATs(context.Background(), mockAccountID, mockUserID, mockUserID)
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestUser_CreateServiceUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

user, err := am.createServiceUser(context.Background(), mockAccountID, mockUserID, mockRole, mockServiceUserName, false, []string{"group1", "group2"})
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestUser_CreateUser_ServiceUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

user, err := am.CreateUser(context.Background(), mockAccountID, mockUserID, &UserInfo{
Expand Down Expand Up @@ -435,7 +435,7 @@ func TestUser_CreateUser_RegularUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

_, err = am.CreateUser(context.Background(), mockAccountID, mockUserID, &UserInfo{
Expand All @@ -460,7 +460,7 @@ func TestUser_InviteNewUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
cacheLoading: map[string]chan struct{}{},
}

Expand Down Expand Up @@ -560,7 +560,7 @@ func TestUser_DeleteUser_ServiceUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

err = am.DeleteUser(context.Background(), mockAccountID, mockUserID, mockServiceUserID)
Expand Down Expand Up @@ -592,7 +592,7 @@ func TestUser_DeleteUser_SelfDelete(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

err = am.DeleteUser(context.Background(), mockAccountID, mockUserID, mockUserID)
Expand Down Expand Up @@ -640,7 +640,7 @@ func TestUser_DeleteUser_regularUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
integratedPeerValidator: MocIntegratedValidator{},
}

Expand Down Expand Up @@ -744,7 +744,7 @@ func TestUser_DeleteUser_RegularUsers(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
integratedPeerValidator: MocIntegratedValidator{},
}

Expand Down Expand Up @@ -846,7 +846,7 @@ func TestDefaultAccountManager_GetUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

claims := jwtclaims.AuthorizationClaims{
Expand Down Expand Up @@ -877,7 +877,7 @@ func TestDefaultAccountManager_ListUsers(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

users, err := am.ListUsers(context.Background(), mockAccountID)
Expand Down Expand Up @@ -959,7 +959,7 @@ func TestDefaultAccountManager_ListUsers_DashboardPermissions(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

users, err := am.ListUsers(context.Background(), mockAccountID)
Expand Down Expand Up @@ -998,7 +998,7 @@ func TestDefaultAccountManager_ExternalCache(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
idpManager: &idp.GoogleWorkspaceManager{}, // empty manager
cacheLoading: map[string]chan struct{}{},
cacheManager: cache.New[[]*idp.UserData](
Expand Down Expand Up @@ -1057,7 +1057,7 @@ func TestUser_GetUsersFromAccount_ForAdmin(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

users, err := am.GetUsersFromAccount(context.Background(), mockAccountID, mockUserID)
Expand Down Expand Up @@ -1086,7 +1086,7 @@ func TestUser_GetUsersFromAccount_ForUser(t *testing.T) {

am := DefaultAccountManager{
Store: store,
EventStore: &activity.InMemoryEventStore{},
eventStore: &activity.InMemoryEventStore{},
}

users, err := am.GetUsersFromAccount(context.Background(), mockAccountID, mockServiceUserID)
Expand Down

0 comments on commit 72157b5

Please sign in to comment.