Merge branch 'release/2.9.0' into production

This commit is contained in:
Raymond Feng 2015-01-07 14:04:32 -08:00
commit 54c381a1ce
5 changed files with 101 additions and 25 deletions

View File

@ -1,3 +1,13 @@
2015-01-07, Version 2.9.0
=========================
* Update juggler dep (Raymond Feng)
* Fix Geo test cases (Raymond Feng)
* Allow User.hashPassword/validatePassword to be overridden (Raymond Feng)
2015-01-07, Version 2.8.8
=========================
@ -695,10 +705,6 @@
* Enhance the error message (Raymond Feng)
2014-07-16, Version 2.0.0-beta7
===============================
* Bump version (Raymond Feng)
* 2.0.0-beta6 (Miroslav Bajtoš)
@ -839,6 +845,13 @@
2014-07-16, Version 1.10.0
==========================
2014-07-16, Version 2.0.0-beta7
===============================
* Bump version (Raymond Feng)
* Remove unused dep (Raymond Feng)
* Bump version and update deps (Raymond Feng)
@ -1285,6 +1298,14 @@
* 2.0.0-beta1 (Ritchie Martori)
* Bump version (Raymond Feng)
* Add postgresql to the keywords (Raymond Feng)
* updated package.json with SOAP and framework keywords (altsang)
* updated package.json with keywords and updated description (Raymond Feng)
* Make app.datasources unique per app instance (Miroslav Bajtoš)
* Add RC version (Ritchie Martori)
@ -1350,6 +1371,11 @@
* Add Change model (Ritchie Martori)
2014-05-27, Version 1.8.4
=========================
2014-05-27, Version 1.8.5
=========================
@ -1361,14 +1387,8 @@
* updated package.json with keywords and updated description (Raymond Feng)
2014-05-27, Version 1.8.4
=========================
* Add more keywords (Raymond Feng)
* Bump version (Raymond Feng)
* app: flatten model config (Miroslav Bajtoš)
* Fix the test for mocha 1.19.0 (Raymond Feng)

View File

@ -453,6 +453,24 @@ module.exports = function(User) {
}
};
/*!
* Hash the plain password
*/
User.hashPassword = function(plain) {
this.validatePassword(plain);
var salt = bcrypt.genSaltSync(this.settings.saltWorkFactor || SALT_WORK_FACTOR);
return bcrypt.hashSync(plain, salt);
};
User.validatePassword = function(plain) {
if (typeof plain === 'string' && plain) {
return true;
}
var err = new Error('Invalid password: ' + plain);
err.statusCode = 422;
throw err;
};
/*!
* Setup an extended user model.
*/
@ -467,8 +485,7 @@ module.exports = function(User) {
this.settings.ttl = this.settings.ttl || DEFAULT_TTL;
UserModel.setter.password = function(plain) {
var salt = bcrypt.genSaltSync(this.constructor.settings.saltWorkFactor || SALT_WORK_FACTOR);
this.$password = bcrypt.hashSync(plain, salt);
this.$password = this.constructor.hashPassword(plain);
};
// Make sure emailVerified is not set by creation

View File

@ -1,6 +1,6 @@
{
"name": "loopback",
"version": "2.8.8",
"version": "2.9.0",
"description": "LoopBack: Open Source Framework for Node.js",
"homepage": "http://loopback.io",
"keywords": [
@ -52,7 +52,7 @@
"underscore.string": "~2.3.3"
},
"peerDependencies": {
"loopback-datasource-juggler": "^2.8.0"
"loopback-datasource-juggler": "^2.13.0"
},
"devDependencies": {
"browserify": "~4.2.3",
@ -102,6 +102,6 @@
"url": "https://github.com/strongloop/loopback/blob/master/LICENSE"
},
"optionalDependencies": {
"sl-blip": "http://blip.strongloop.com/loopback@2.8.8"
"sl-blip": "http://blip.strongloop.com/loopback@2.9.0"
}
}

View File

@ -22,14 +22,14 @@ describe('GeoPoint', function() {
describe('GeoPoint()', function() {
it('Create from string', function() {
var point = new GeoPoint('1.234,5.678');
assert.equal(point.lng, 1.234);
assert.equal(point.lat, 5.678);
assert.equal(point.lat, 1.234);
assert.equal(point.lng, 5.678);
var point2 = new GeoPoint('1.222, 5.333');
assert.equal(point2.lng, 1.222);
assert.equal(point2.lat, 5.333);
assert.equal(point2.lat, 1.222);
assert.equal(point2.lng, 5.333);
var point3 = new GeoPoint('1.333, 5.111');
assert.equal(point3.lng, 1.333);
assert.equal(point3.lat, 5.111);
assert.equal(point3.lat, 1.333);
assert.equal(point3.lng, 5.111);
});
it('Serialize as string', function() {
var str = '1.234,5.678';
@ -38,8 +38,8 @@ describe('GeoPoint', function() {
});
it('Create from array', function() {
var point = new GeoPoint([5.555, 6.777]);
assert.equal(point.lng, 5.555);
assert.equal(point.lat, 6.777);
assert.equal(point.lat, 5.555);
assert.equal(point.lng, 6.777);
});
it('Create as Model property', function() {
var Model = loopback.createModel('geo-model', {
@ -51,8 +51,8 @@ describe('GeoPoint', function() {
});
assert(m.geo instanceof GeoPoint);
assert.equal(m.geo.lng, 1.222);
assert.equal(m.geo.lat, 3.444);
assert.equal(m.geo.lat, 1.222);
assert.equal(m.geo.lng, 3.444);
});
});
});

View File

@ -135,6 +135,45 @@ describe('User', function() {
assert(u.password !== 'bar');
});
describe('custom password hash', function() {
var defaultHashPassword;
var defaultValidatePassword;
beforeEach(function() {
defaultHashPassword = User.hashPassword;
defaultValidatePassword = User.defaultValidatePassword;
User.hashPassword = function(plain) {
return plain.toUpperCase();
};
User.validatePassword = function(plain) {
if (!plain || plain.length < 3) {
throw new Error('Password must have at least 3 chars');
}
return true;
};
});
afterEach(function() {
User.hashPassword = defaultHashPassword;
});
it('Reports invalid password', function() {
try {
var u = new User({username: 'foo', password: 'aa'});
assert(false, 'Error should have been thrown');
} catch (e) {
// Ignore
}
});
it('Hashes the given password', function() {
var u = new User({username: 'foo', password: 'bar'});
assert(u.password === 'BAR');
});
});
it('Create a user over REST should remove emailVerified property', function(done) {
request(app)
.post('/users')