Skip to content

Commit

Permalink
chore: revert use of quick-lru
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Oct 27, 2021
1 parent 3f9b147 commit c9579e7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
3 changes: 1 addition & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { strict: assert } = require('assert');
const querystring = require('querystring');
const url = require('url');

const QuickLRU = require('quick-lru');
const jose = require('jose');
const tokenHash = require('oidc-token-hash');

Expand Down Expand Up @@ -1594,7 +1593,7 @@ function determineEcAlgorithm(privateKey, privateKeyInput) {
throw new TypeError('unsupported DPoP private key curve');
}

const jwkCache = new QuickLRU({ maxSize: 100 });
const jwkCache = new WeakMap();
async function getJwk(privateKey, privateKeyInput) {
if (typeof privateKeyInput === 'object' && typeof privateKeyInput.key === 'object' && privateKeyInput.key.crv) {
return pick(privateKeyInput.key, 'kty', 'crv', 'x', 'y', 'e', 'n');
Expand Down
7 changes: 0 additions & 7 deletions lib/helpers/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ const http = require('http');
const https = require('https');
const { once } = require('events');

const CacheableLookup = require('cacheable-lookup');
const QuickLRU = require('quick-lru');

const pkg = require('../../package.json');
const { RPError } = require('../errors');

Expand All @@ -16,9 +13,6 @@ const { HTTP_OPTIONS } = require('./consts');

let DEFAULT_HTTP_OPTIONS;

const cacheable = new CacheableLookup({
cache: new QuickLRU({ maxSize: 1000 }),
});
const allowed = [
'agent',
'ca',
Expand All @@ -40,7 +34,6 @@ const setDefaults = (props, options) => {
setDefaults([], {
headers: { 'User-Agent': `${pkg.name}/${pkg.version} (${pkg.homepage})` },
timeout: 3500,
lookup: cacheable.lookup,
});

module.exports = async function request(options, { accessToken, mTLS = false, DPoP } = {}) {
Expand Down
6 changes: 3 additions & 3 deletions lib/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { inspect } = require('util');
const url = require('url');

const QuickLRU = require('quick-lru');
const LRU = require('lru-cache');
const objectHash = require('object-hash');

const { RPError } = require('./errors');
Expand Down Expand Up @@ -57,7 +57,7 @@ class Issuer {
}
});

instance(this).set('cache', new QuickLRU({ maxSize: 100 }));
instance(this).set('cache', new LRU({ max: 100 }));

registry.set(this.issuer, this);

Expand All @@ -80,7 +80,7 @@ class Issuer {
const cache = instance(this).get('cache');

if (reload || !keystore) {
cache.clear();
cache.reset();
const response = await request.call(this, {
method: 'GET',
responseType: 'json',
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@
]
},
"dependencies": {
"cacheable-lookup": "^6.0.4",
"jose": "^4.1.0",
"lru-cache": "^6.0.0",
"make-error": "^1.3.6",
"object-hash": "^2.0.1",
"oidc-token-hash": "^5.0.1",
"quick-lru": "^5.1.1"
"oidc-token-hash": "^5.0.1"
},
"devDependencies": {
"@types/node": "^16.11.1",
Expand Down
10 changes: 5 additions & 5 deletions test/issuer/issuer_instance.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { expect } = require('chai');
const QuickLRU = require('quick-lru');
const LRU = require('lru-cache');
const nock = require('nock');
const sinon = require('sinon');
const jose2 = require('jose2');
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('Issuer', () => {

after(nock.cleanAll);
afterEach(function () {
if (QuickLRU.prototype.get.restore) QuickLRU.prototype.get.restore();
if (LRU.prototype.get.restore) LRU.prototype.get.restore();
});

it('does not refetch immidiately', function () {
Expand All @@ -64,7 +64,7 @@ describe('Issuer', () => {
});

it('asks to fetch if the keystore is stale and new key definition is requested', function () {
sinon.stub(QuickLRU.prototype, 'get').returns(undefined);
sinon.stub(LRU.prototype, 'get').returns(undefined);
return this.issuer.queryKeyStore({ use: 'sig', alg: 'RS256', kid: 'yeah' }).then(fail, () => {
nock('https://op.example.com')
.get('/certs')
Expand All @@ -83,7 +83,7 @@ describe('Issuer', () => {
});

it('requires a kid is provided in definition if more keys are in the storage', function () {
sinon.stub(QuickLRU.prototype, 'get').returns(undefined);
sinon.stub(LRU.prototype, 'get').returns(undefined);
return this.keystore.generate('RSA').then(() => {
nock('https://op.example.com')
.get('/certs')
Expand All @@ -97,7 +97,7 @@ describe('Issuer', () => {
});

it('multiple keys can match the JWT header', function () {
sinon.stub(QuickLRU.prototype, 'get').returns(undefined);
sinon.stub(LRU.prototype, 'get').returns(undefined);
const { kid } = this.keystore.get({ kty: 'RSA' });
return this.keystore.generate('RSA', undefined, { kid }).then(() => {
nock('https://op.example.com')
Expand Down

0 comments on commit c9579e7

Please sign in to comment.