Skip to content

Commit

Permalink
refactor: simplify cache directives
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed May 31, 2022
1 parent 2767272 commit 95fc825
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 32 deletions.
3 changes: 1 addition & 2 deletions example/routes/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ module.exports = (app, provider) => {
});

function setNoCache(req, res, next) {
res.set('Pragma', 'no-cache');
res.set('Cache-Control', 'no-cache, no-store');
res.set('cache-control', 'no-store');
next();
}

Expand Down
3 changes: 1 addition & 2 deletions example/routes/koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ module.exports = (provider) => {
const { constructor: { errors: { SessionNotFound } } } = provider;

router.use(async (ctx, next) => {
ctx.set('Pragma', 'no-cache');
ctx.set('Cache-Control', 'no-cache, no-store');
ctx.set('cache-control', 'no-store');
try {
await next();
} catch (err) {
Expand Down
3 changes: 1 addition & 2 deletions lib/shared/no_cache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = async function noCache(ctx, next) {
ctx.set('Pragma', 'no-cache');
ctx.set('Cache-Control', 'no-cache, no-store');
ctx.set('cache-control', 'no-store');
await next();
};
6 changes: 2 additions & 4 deletions test/authorization_code/code.grant.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ describe('grant_type=authorization_code', () => {
grant_type: 'authorization_code',
redirect_uri: 'https://client.example.com/cb',
})
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store');
.expect('cache-control', 'no-store');
});

context('', () => {
Expand Down Expand Up @@ -431,8 +430,7 @@ describe('grant_type=authorization_code', () => {
code: this.ac,
grant_type: 'authorization_code',
})
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store');
.expect('cache-control', 'no-store');
});

context('', () => {
Expand Down
9 changes: 3 additions & 6 deletions test/dynamic_registration/dynamic_registration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ describe('registration features', () => {
.send({
redirect_uris: ['https://client.example.com/cb'],
})
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store');
.expect('cache-control', 'no-store');
});

it('stores the client and emits an event', function () {
Expand Down Expand Up @@ -522,8 +521,7 @@ describe('registration features', () => {
it('returns token-endpoint-like cache headers', function () {
return this.agent.get(`/reg/${this.clientId}`)
.auth(this.token, { type: 'bearer' })
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store');
.expect('cache-control', 'no-store');
});

it('validates client is a valid client', function () {
Expand Down Expand Up @@ -567,8 +565,7 @@ describe('registration features', () => {

return this.agent.get('/reg/foobar')
.auth(this.token, { type: 'bearer' })
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store')
.expect('cache-control', 'no-store')
.expect(this.failWith(401, 'invalid_token', 'invalid token provided'))
.expect(() => {
expect(spy.calledOnce).to.be.true;
Expand Down
3 changes: 1 addition & 2 deletions test/introspection/introspection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ describe('introspection features', () => {
.auth('client', 'secret')
.send({})
.type('form')
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store');
.expect('cache-control', 'no-store');
});

it('validates token param presence', function () {
Expand Down
6 changes: 2 additions & 4 deletions test/registration_management/registration_management.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ describe('OAuth 2.0 Dynamic Client Registration Management Protocol', () => {
}))
.expect(200)
.expect('content-type', /application\/json/)
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store')
.expect('cache-control', 'no-store')
.expect((res) => {
expect(res.body).to.have.property('registration_access_token', client.registration_access_token);
expect(res.body).to.have.property('registration_client_uri', client.registration_client_uri);
Expand Down Expand Up @@ -273,8 +272,7 @@ describe('OAuth 2.0 Dynamic Client Registration Management Protocol', () => {
const client = await setup.call(this, {});
await this.agent.del(`/reg/${client.client_id}`)
.auth(client.registration_access_token, { type: 'bearer' })
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store')
.expect('cache-control', 'no-store')
.expect('') // empty body
.expect(204);

Expand Down
15 changes: 5 additions & 10 deletions test/web_message/web_message.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ describe('configuration features.webMessageResponseMode', () => {

await this.wrap({ route, auth, verb: 'get' })
.expect(200)
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store')
.expect('cache-control', 'no-store')
.expect('content-type', 'text/html; charset=utf-8')
.expect((response) => {
expect(response.headers['x-frame-options']).not.to.be.ok;
Expand Down Expand Up @@ -76,8 +75,7 @@ describe('configuration features.webMessageResponseMode', () => {

await this.wrap({ route, auth, verb: 'get' })
.expect(200)
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store')
.expect('cache-control', 'no-store')
.expect('content-type', 'text/html; charset=utf-8')
.expect((response) => {
expect(response.headers['x-frame-options']).not.to.be.ok;
Expand Down Expand Up @@ -107,8 +105,7 @@ describe('configuration features.webMessageResponseMode', () => {

await this.wrap({ route, auth, verb: 'get' })
.expect(200)
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store')
.expect('cache-control', 'no-store')
.expect('content-type', 'text/html; charset=utf-8')
.expect((response) => {
expect(response.headers['x-frame-options']).not.to.be.ok;
Expand Down Expand Up @@ -136,8 +133,7 @@ describe('configuration features.webMessageResponseMode', () => {

await this.wrap({ route, auth, verb: 'get' })
.expect(200)
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store')
.expect('cache-control', 'no-store')
.expect('content-type', 'text/html; charset=utf-8')
.expect((response) => {
expect(response.headers['x-frame-options']).not.to.be.ok;
Expand Down Expand Up @@ -269,8 +265,7 @@ describe('configuration features.webMessageResponseMode', () => {

await this.wrap({ route, auth, verb: 'get' })
.expect(400)
.expect('pragma', 'no-cache')
.expect('cache-control', 'no-cache, no-store')
.expect('cache-control', 'no-store')
.expect('content-type', 'text/html; charset=utf-8')
.expect((response) => {
expect(response.headers['x-frame-options']).not.to.be.ok;
Expand Down

0 comments on commit 95fc825

Please sign in to comment.