Skip to content

Update bcrypt #70

Merged
merged 2 commits into from Feb 3, 2012
View
7 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
View
4 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) {
View
9 package.json
@@ -13,14 +13,19 @@
"lib": "."
},
"dependencies": {
- "bcrypt":">=0.2.0",
+ "bcrypt":">=0.5.0",
"mongoose": ">=1.4.0",
"everyauth": "0.2.23",
"mongoose-types": ">=1.0.3"
},
"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"
View
28 test/authplugin.test.js
@@ -11,26 +11,30 @@ 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);
user.password = 'hello';
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();
+ });
+ });
+});
Something went wrong with that request. Please try again.