session: remove the filter fn in ListSessions

And replace with ListAllSessions since no callers of ListSessions
currently make use of the filter function.
This commit is contained in:
Elle Mouton 2025-02-09 12:29:40 +02:00
parent 6c36b01fd8
commit 01410f7950
No known key found for this signature in database
GPG key ID: D7D916376026F177
4 changed files with 20 additions and 18 deletions

View file

@ -161,8 +161,8 @@ type Store interface {
// GetSession fetches the session with the given key.
GetSession(key *btcec.PublicKey) (*Session, error)
// ListSessions returns all sessions currently known to the store.
ListSessions(filterFn func(s *Session) bool) ([]*Session, error)
// ListAllSessions returns all sessions currently known to the store.
ListAllSessions() ([]*Session, error)
// ListSessionsByType returns all sessions of the given type.
ListSessionsByType(t Type) ([]*Session, error)

View file

@ -364,11 +364,13 @@ func (db *BoltStore) GetSession(key *btcec.PublicKey) (*Session, error) {
return session, nil
}
// ListSessions returns all sessions currently known to the store.
// ListAllSessions returns all sessions currently known to the store.
//
// NOTE: this is part of the Store interface.
func (db *BoltStore) ListSessions(filterFn func(s *Session) bool) ([]*Session, error) {
return db.listSessions(filterFn)
func (db *BoltStore) ListAllSessions() ([]*Session, error) {
return db.listSessions(func(s *Session) bool {
return true
})
}
// ListSessionsByType returns all sessions currently known to the store that

View file

@ -56,16 +56,8 @@ func TestBasicSessionStore(t *testing.T) {
require.NoError(t, db.CreateSession(s2))
require.NoError(t, db.CreateSession(s3))
// Check that all sessions are returned in ListSessions.
sessions, err := db.ListSessions(nil)
require.NoError(t, err)
require.Equal(t, 3, len(sessions))
assertEqualSessions(t, s1, sessions[0])
assertEqualSessions(t, s2, sessions[1])
assertEqualSessions(t, s3, sessions[2])
// Test the ListSessionsByType method.
sessions, err = db.ListSessionsByType(TypeMacaroonAdmin)
sessions, err := db.ListSessionsByType(TypeMacaroonAdmin)
require.NoError(t, err)
require.Equal(t, 2, len(sessions))
assertEqualSessions(t, s1, sessions[0])
@ -115,9 +107,17 @@ func TestBasicSessionStore(t *testing.T) {
// Now revoke the session and assert that the state is revoked.
require.NoError(t, db.RevokeSession(s1.LocalPublicKey))
session1, err = db.GetSession(s1.LocalPublicKey)
s1, err = db.GetSession(s1.LocalPublicKey)
require.NoError(t, err)
require.Equal(t, session1.State, StateRevoked)
require.Equal(t, s1.State, StateRevoked)
// Test that ListAllSessions works.
sessions, err = db.ListAllSessions()
require.NoError(t, err)
require.Equal(t, 3, len(sessions))
assertEqualSessions(t, s1, sessions[0])
assertEqualSessions(t, s2, sessions[1])
assertEqualSessions(t, s3, sessions[2])
}
// TestLinkingSessions tests that session linking works as expected.

View file

@ -101,7 +101,7 @@ func newSessionRPCServer(cfg *sessionRpcServerConfig) (*sessionRpcServer,
// requests. This includes resuming all non-revoked sessions.
func (s *sessionRpcServer) start(ctx context.Context) error {
// Start up all previously created sessions.
sessions, err := s.cfg.db.ListSessions(nil)
sessions, err := s.cfg.db.ListAllSessions()
if err != nil {
return fmt.Errorf("error listing sessions: %v", err)
}
@ -536,7 +536,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context,
func (s *sessionRpcServer) ListSessions(_ context.Context,
_ *litrpc.ListSessionsRequest) (*litrpc.ListSessionsResponse, error) {
sessions, err := s.cfg.db.ListSessions(nil)
sessions, err := s.cfg.db.ListAllSessions()
if err != nil {
return nil, fmt.Errorf("error fetching sessions: %v", err)
}