From 5b6b200b782e7d97b94091d0de1db4e4e41fb1f7 Mon Sep 17 00:00:00 2001 From: Justin Latimer Date: Thu, 19 Jan 2012 23:11:34 +1000 Subject: [PATCH 1/2] Convert tests from expresso to mocha. Put test dependencies in the devDependencies in package.json, and add the npm script to run the tests. --- Makefile | 7 ++----- package.json | 7 ++++++- test/authplugin.test.js | 28 ++++++++++++++++------------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 49fa7ac..0fb86ba 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,4 @@ test: - @expresso test/authplugin.test.js + @node_modules/.bin/mocha -test-cov: - @TESTFLAGS=--cov $(MAKE) test - -.PHONY: test test-cov +.PHONY: test diff --git a/package.json b/package.json index 100b509..20c0f14 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,12 @@ }, "devDependencies": { "express": ">=2.3.2", - "jade": ">=0.12.1" + "jade": ">=0.12.1", + "mocha": ">=0.10.1", + "should": ">=0.5.1" + }, + "scripts": { + "test": "make" }, "engines": { "node": ">=0.4.0" diff --git a/test/authplugin.test.js b/test/authplugin.test.js index e06bc05..86903c1 100644 --- a/test/authplugin.test.js +++ b/test/authplugin.test.js @@ -11,8 +11,8 @@ UserSchema.plugin(authPlugin, { mongoose.model('User', UserSchema); User = mongoose.model('User'); -module.exports = { - "setting a user's password should generate a salt and set a hash": function () { +describe('User', function () { + it('should generate a salt and set a hash when password is set', function () { var user = new User(); should.strictEqual(undefined, user.salt); should.strictEqual(undefined, user.hash); @@ -20,17 +20,21 @@ module.exports = { user.password.should.equal('hello'); user.salt.should.not.be.undefined; user.hash.should.not.be.undefined; - }, - - 'a user should authenticate with a correct password': function () { + }); + it('should authenticate with a correct password', function (done) { var user = new User(); user.password = 'hello'; - user.authenticate('hello').should.be.true; - }, - - 'a user should fail authentication with an incorrect password': function () { + user.authenticate('hello', function (err, matched) { + matched.should.be.true; + done(); + }); + }); + it('should fail authentication with an incorrect password', function (done) { var user = new User(); user.password = 'correct'; - user.authenticate('incorrect').should.be.false; - } -}; + user.authenticate('incorrect', function (err, matched) { + matched.should.be.false; + done(); + }); + }); +}); From 5ea5d80fb562f859230ffda832b8e7ba603ae471 Mon Sep 17 00:00:00 2001 From: Justin Latimer Date: Thu, 19 Jan 2012 23:15:22 +1000 Subject: [PATCH 2/2] Fix deprecation warnings with bcrypt >= 0.5.0. --- lib/modules/password/plugin.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/modules/password/plugin.js b/lib/modules/password/plugin.js index da4b145..82d16cf 100644 --- a/lib/modules/password/plugin.js +++ b/lib/modules/password/plugin.js @@ -36,8 +36,8 @@ exports = module.exports = function (schema, opts) { return this._password; }).set( function (password) { this._password = password; - var salt = this.salt = bcrypt.gen_salt_sync(10); - this.hash = bcrypt.encrypt_sync(password, salt); + var salt = this.salt = bcrypt.genSaltSync(10); + this.hash = bcrypt.hashSync(password, salt); }); schema.method('authenticate', function (password, callback) { diff --git a/package.json b/package.json index 20c0f14..07b4811 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "lib": "." }, "dependencies": { - "bcrypt":">=0.2.0", + "bcrypt":">=0.5.0", "mongoose": ">=1.4.0", "everyauth": "0.2.23", "mongoose-types": ">=1.0.3"