Skip to content

Commit

Permalink
fix: empty params are handled as if they were not provided at all
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Aug 17, 2019
1 parent 3397d65 commit a9e0f8c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/helpers/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module.exports = function getParams(whitelist) {

const klass = class Params {
constructor(params) {
whitelist.forEach((prop) => { this[prop] = params[prop]; });
whitelist.forEach((prop) => {
this[prop] = params[prop] || undefined;
});
}

toPlainObject() {
Expand Down
5 changes: 4 additions & 1 deletion lib/helpers/validate_presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const { InvalidRequest } = require('./errors');
module.exports = function validatePresence(ctx, ...required) {
const { params } = ctx.oidc;
const missing = required.map((param) => {
if (params[param] === undefined) return param;
if (params[param] === undefined) {
return param;
}

return undefined;
}).filter(Boolean);

Expand Down
2 changes: 1 addition & 1 deletion test/body_parser/body_parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('body parser', () => {
.expect(200);

expect(
spy.calledWithMatch({ oidc: { params: { scope: '' } } }),
spy.calledWithMatch({ oidc: { params: { scope: undefined } } }),
).to.be.true;
});
});
Expand Down

0 comments on commit a9e0f8c

Please sign in to comment.