Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardise responses for invalid existing passwords #1410

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/util/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const BCRYPT_COST_FACTOR = process.env.BCRYPT === 'insecure' ? 1 : 12;
// These functions call into bcrypt to hash or verify passwords.
const hashPassword = (plain) =>
(isBlank(plain) ? resolve(null) : bcrypt.hash(plain, BCRYPT_COST_FACTOR));
const verifyPassword = (plain, hash) => ((isBlank(plain) || (isBlank(hash)))
const verifyPassword = (plain, hash) => ((typeof plain !== 'string' || isBlank(plain) || isBlank(hash))
? resolve(false)
: bcrypt.compare(plain, hash));

Expand Down
20 changes: 15 additions & 5 deletions test/integration/api/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,21 @@ describe('api: /sessions', () => {
body[0].details.userAgent.should.equal('central/tests');
}))));

it('should return a 401 if the password is wrong', testService((service) =>
service.post('/v1/sessions')
.send({ email: '[email protected]', password: 'letmein' })
.expect(401)
.then(({ body }) => body.message.should.equal('Could not authenticate with the provided credentials.'))));
[
[ 'undefined', undefined, 400, 'Required parameters missing. Expected (email, password), got (email: \'[email protected]\', password: undefined).' ], // eslint-disable-line no-multi-spaces
[ 'null', null, 400, 'Required parameters missing. Expected (email, password), got (email: \'[email protected]\', password: null).' ], // eslint-disable-line no-multi-spaces
[ 'empty string', '', 400, 'Required parameters missing. Expected (email, password), got (email: \'[email protected]\', password: \'\').' ], // eslint-disable-line no-multi-spaces
[ 'wrong password', 'letmein', 401, 'Could not authenticate with the provided credentials.' ], // eslint-disable-line no-multi-spaces
[ 'number', 123, 401, 'Could not authenticate with the provided credentials.' ], // eslint-disable-line no-multi-spaces
[ 'array', [], 401, 'Could not authenticate with the provided credentials.' ], // eslint-disable-line no-multi-spaces
[ 'object', {}, 401, 'Could not authenticate with the provided credentials.' ], // eslint-disable-line no-multi-spaces
].forEach(([ description, password, expectedStatus, expectedError ]) => {
it(`should return a ${expectedStatus} for invalid password (${description})`, testService((service) =>
service.post('/v1/sessions')
.send({ email: '[email protected]', password })
.expect(expectedStatus)
.then(({ body }) => body.message.should.equal(expectedError))));
});

it('should return a 401 if the email is wrong', testService((service) =>
service.post('/v1/sessions')
Expand Down