Browse Source

Merge pull request #7133 from Budibase/session-wipe-fix

Bulk session wipe fix + logging
pull/7151/head
Rory Powell 4 years ago
committed by GitHub
parent
commit
ccfd001913
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      packages/backend-core/src/security/sessions.ts
  2. 12
      packages/backend-core/src/security/tests/sessions.spec.ts

4
packages/backend-core/src/security/sessions.ts

@ -23,6 +23,10 @@ function makeSessionID(userId: string, sessionId: string) {
}
export async function getSessionsForUser(userId: string) {
if (!userId) {
console.trace("Cannot get sessions for undefined userId")
return []
}
const client = await redis.getSessionClient()
const sessions = await client.scan(userId)
return sessions.map((session: Session) => session.value)

12
packages/backend-core/src/security/tests/sessions.spec.ts

@ -0,0 +1,12 @@
import * as sessions from "../sessions"
describe("sessions", () => {
describe("getSessionsForUser", () => {
it("returns empty when user is undefined", async () => {
// @ts-ignore - allow the undefined to be passed
const results = await sessions.getSessionsForUser(undefined)
expect(results).toStrictEqual([])
})
})
})
Loading…
Cancel
Save