-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: always use real bcrypt lib (#962)
Instead of mocking bcrypt in some test scenarios, decrease the cost factor to the fastest possible value. * remove dependency injection of `bcrypt` * remove `mock-bcrypt.js` * remove multiple paths to `password.verify()`/`verifyPassword()` and `password.hash()`/`hashPassword()` * cut CI build times from ~8.5 mins to ~2.5 mins
- Loading branch information
Showing
17 changed files
with
56 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const appRoot = require('app-root-path'); | ||
const should = require('should'); | ||
const { testTask } = require('../setup'); | ||
const { verifyPassword } = require(appRoot + '/lib/util/crypto'); | ||
const { getOrNotFound } = require(appRoot + '/lib/util/promise'); | ||
const { createUser, promoteUser, setUserPassword } = require(appRoot + '/lib/task/account'); | ||
const { User } = require(appRoot + '/lib/model/frames'); | ||
|
@@ -35,18 +36,18 @@ describe('task: accounts', () => { | |
should(log.details.data.password).equal(null); | ||
}))); | ||
|
||
it('should set the password if given', testTask(({ Users, bcrypt }) => | ||
it('should set the password if given', testTask(({ Users }) => | ||
createUser('[email protected]', 'aoeuidhtns') | ||
.then(() => Users.getByEmail('[email protected]')) | ||
.then(getOrNotFound) | ||
.then((user) => bcrypt.verify('aoeuidhtns', user.password)) | ||
.then((user) => verifyPassword('aoeuidhtns', user.password)) | ||
.then((verified) => verified.should.equal(true)))); | ||
|
||
it('should not verify a null password', testTask(({ Users, bcrypt }) => | ||
it('should not verify a null password', testTask(({ Users }) => | ||
createUser('[email protected]', null) | ||
.then(() => Users.getByEmail('[email protected]')) | ||
.then(getOrNotFound) | ||
.then((user) => bcrypt.verify(null, user.password)) | ||
.then((user) => verifyPassword(null, user.password)) | ||
.then((verified) => verified.should.equal(false)))); | ||
|
||
it('should complain if the password is too short', testTask(() => | ||
|
@@ -85,12 +86,12 @@ describe('task: accounts', () => { | |
}); | ||
|
||
describe('setUserPassword', () => { | ||
it('should set a user password', testTask(({ Users, bcrypt }) => | ||
it('should set a user password', testTask(({ Users }) => | ||
Users.create(User.fromApi({ email: '[email protected]', displayName: 'test user' })) | ||
.then(() => setUserPassword('[email protected]', 'aoeuidhtns')) | ||
.then(() => Users.getByEmail('[email protected]')) | ||
.then(getOrNotFound) | ||
.then((user) => bcrypt.verify('aoeuidhtns', user.password)) | ||
.then((user) => verifyPassword('aoeuidhtns', user.password)) | ||
.then((verified) => verified.should.equal(true)))); | ||
|
||
it('should complain about a password that is too short', testTask(({ Users }) => | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,10 @@ const preprocessors = require(appRoot + '/lib/http/preprocessors'); | |
const { Context } = require(appRoot + '/lib/http/endpoint'); | ||
const { Session, User, Actor } = require(appRoot + '/lib/model/frames'); | ||
const { by } = require(appRoot + '/lib/model/query/auth'); | ||
const { hashPassword } = require(appRoot + '/lib/util/crypto'); | ||
const Problem = require(appRoot + '/lib/util/problem'); | ||
const Option = require(appRoot + '/lib/util/option'); | ||
|
||
const bcrypt = require(appRoot + '/lib/util/crypto').password(require('bcrypt')); | ||
|
||
describe('preprocessors', () => { | ||
// some mock helpers to simplify testing this module in isolation: | ||
const Auth = { by: (x) => by(x)({}) }; | ||
|
@@ -115,7 +114,7 @@ describe('preprocessors', () => { | |
|
||
it('should fail the request if the Basic auth credentials are not right', () => | ||
Promise.resolve(authHandler( | ||
{ Auth, Users: mockUsers('[email protected]', 'willnevermatch'), bcrypt }, | ||
{ Auth, Users: mockUsers('[email protected]', 'willnevermatch') }, | ||
new Context( | ||
createRequest({ headers: { | ||
Authorization: `Basic ${Buffer.from('[email protected]:alice', 'utf8').toString('base64')}`, | ||
|
@@ -126,9 +125,9 @@ describe('preprocessors', () => { | |
)).should.be.rejectedWith(Problem, { problemCode: 401.2 })); | ||
|
||
it('should set the appropriate session if valid Basic auth credentials are given @slow', () => | ||
bcrypt.hash('alice').then((hashed) => | ||
hashPassword('alice').then((hashed) => | ||
Promise.resolve(authHandler( | ||
{ Auth, Users: mockUsers('[email protected]', hashed), bcrypt }, | ||
{ Auth, Users: mockUsers('[email protected]', hashed) }, | ||
new Context( | ||
createRequest({ headers: { | ||
Authorization: `Basic ${Buffer.from('[email protected]:alice', 'utf8').toString('base64')}`, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.