mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-11-13 12:23:34 +01:00
Expire abandoned OIDC mobile login sessions
This commit is contained in:
1 parent
d22c468215
commit
273693e8ad
2 files changed
+28
-1
No files matched your search
@@ -1,3 +1,4 @@
|
||||
const { LRUCache } = require('lru-cache')
|
||||
const { Request, Response } = require('express')
|
||||
const passport = require('passport')
|
||||
const OpenIDClient = require('openid-client')
|
||||
@@ -15,7 +16,10 @@ class OidcAuthStrategy {
|
||||
this.strategy = null
|
||||
this.client = null
|
||||
// Map of openId sessions indexed by oauth2 state-variable
|
||||
this.openIdAuthSession = new Map()
|
||||
this.openIdAuthSession = new LRUCache({
|
||||
ttl: 10 * 60 * 1000,
|
||||
ttlAutopurge: true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,3 +75,26 @@ describe('OidcAuthStrategy - isValidWebCallbackUrl', () => {
|
||||
expect(strategy.isValidWebCallbackUrl('http://books.example.com/login', req)).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('OidcAuthStrategy - openIdAuthSession', () => {
|
||||
/** @type {OidcAuthStrategy} */
|
||||
let strategy
|
||||
|
||||
beforeEach(() => {
|
||||
global.RouterBasePath = ''
|
||||
strategy = new OidcAuthStrategy()
|
||||
})
|
||||
|
||||
it('configures a 10 minute TTL with autopurge so abandoned mobile logins are cleaned up', () => {
|
||||
expect(strategy.openIdAuthSession.ttl).to.equal(10 * 60 * 1000)
|
||||
expect(strategy.openIdAuthSession.ttlAutopurge).to.equal(true)
|
||||
})
|
||||
|
||||
it('still supports the same set/has/get/delete usage as a plain Map', () => {
|
||||
strategy.openIdAuthSession.set('some-state', { mobile_redirect_uri: 'myapp://callback' })
|
||||
expect(strategy.openIdAuthSession.has('some-state')).to.equal(true)
|
||||
expect(strategy.openIdAuthSession.get('some-state')).to.deep.equal({ mobile_redirect_uri: 'myapp://callback' })
|
||||
strategy.openIdAuthSession.delete('some-state')
|
||||
expect(strategy.openIdAuthSession.has('some-state')).to.equal(false)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user