Skip to content

Commit

Permalink
cookie-store/ListUser-ListRevoked: don't return expired sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox0815 committed Nov 29, 2023
1 parent 07d09d1 commit 0a1ed9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cookie/backend_bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func (b *BoltBackend) ListUser(username string) (list SessionFullList, err error
if err := json.Unmarshal(value, &session); err != nil {
return err
}
list = append(list, SessionFull{Session: Session{ID: id, SessionBase: session.SessionBase}, Agent: session.Agent})
if !session.SessionBase.IsExpired() {
list = append(list, SessionFull{Session: Session{ID: id, SessionBase: session.SessionBase}, Agent: session.Agent})
}
}
return nil
})
Expand Down Expand Up @@ -232,7 +234,9 @@ func (b *BoltBackend) ListRevoked() (list SessionList, err error) {
if err := json.Unmarshal(value, &session); err != nil {
return err
}
list = append(list, Session{ID: id, SessionBase: session})
if !session.IsExpired() {
list = append(list, Session{ID: id, SessionBase: session})
}
}
return nil
})
Expand Down
8 changes: 6 additions & 2 deletions cookie/backend_in-memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func (b *InMemoryBackend) ListUser(username string) (list SessionFullList, err e
return
}
for id, session := range sessions {
list = append(list, SessionFull{Session: Session{ID: id, SessionBase: session.SessionBase}, Agent: session.Agent})
if !session.SessionBase.IsExpired() {
list = append(list, SessionFull{Session: Session{ID: id, SessionBase: session.SessionBase}, Agent: session.Agent})
}
}
return
}
Expand Down Expand Up @@ -135,7 +137,9 @@ func (b *InMemoryBackend) ListRevoked() (list SessionList, err error) {
defer b.mutex.RUnlock()

for id, session := range b.revoked {
list = append(list, Session{ID: id, SessionBase: session})
if !session.IsExpired() {
list = append(list, Session{ID: id, SessionBase: session})
}
}
return
}
Expand Down

0 comments on commit 0a1ed9a

Please sign in to comment.