Skip to content

Commit

Permalink
fix: remove deprecated Session.find upsert behaviour
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Session.find default upsert behaviour is changed to
return a new empty session instead
  • Loading branch information
panva committed Sep 26, 2018
1 parent ef40f6d commit 73e07bd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/actions/authorization/resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function getResumeAction(provider, whitelist, resumeRouteName)
throw new SessionNotFound('authorization request has expired');
}

const interactionSession = await provider.Session.find(cookieId, { upsert: false });
const interactionSession = await provider.Session.find(cookieId);
if (!interactionSession) {
throw new SessionNotFound('interaction session not found');
}
Expand Down
13 changes: 3 additions & 10 deletions lib/models/session.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const assert = require('assert');
const { deprecate } = require('util');

const uuid = require('uuid/v4');
const hash = require('object-hash');

const epochTime = require('../helpers/epoch_time');
const instance = require('../helpers/weak_cache');

const deprecated = deprecate(() => {}, 'Session.find returning new sessions if none is found is deprecated');

const NON_REJECTABLE_CLAIMS = new Set(['sub', 'sid', 'auth_time', 'acr', 'amr', 'iss']);
const NON_REJECTABLE_SCOPES = new Set(['openid']);

Expand Down Expand Up @@ -169,7 +166,7 @@ module.exports = function getSession(provider) {
return getterSetTransformation(authorization.rejectedClaims);
}

static async find(id, { upsert = true } = {}) {
static async find(id) {
assert(id, 'id must be provided to Session#find');
const data = await getAdapter().find(id);
if (data) {
Expand All @@ -180,11 +177,7 @@ module.exports = function getSession(provider) {
return new Session(id, data);
}
}
/* istanbul ignore if */
if (upsert) {
deprecated();
return new Session(id);
}

return undefined;
}

Expand All @@ -196,7 +189,7 @@ module.exports = function getSession(provider) {

let session;
if (sessionId) {
session = await this.find(sessionId, { upsert: false });
session = await this.find(sessionId);
}
if (!session) {
sessionId = uuid();
Expand Down
2 changes: 1 addition & 1 deletion lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function getInteraction(req, res) {
if (!id) {
throw new SessionNotFound('interaction session id cookie not found');
}
const interaction = await this.Session.find(id, { upsert: false });
const interaction = await this.Session.find(id);
if (!interaction) {
throw new SessionNotFound('interaction session not found');
}
Expand Down

0 comments on commit 73e07bd

Please sign in to comment.