Skip to content
Merged
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
6 changes: 6 additions & 0 deletions common/models/user.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -421,6 +421,12 @@ module.exports = function(User) {
return cb(err);
}

try {
User.validatePassword(newPassword);
} catch (err) {
return cb(err);
}

const delta = {password: newPassword};
this.patchAttributes(delta, options, (err, updated) => cb(err));
});
Expand Down
21 changes: 20 additions & 1 deletion test/user.test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -449,6 +449,25 @@ describe('User', function() {
});
});
});

it('rejects changePassword when new password is longer than 72 chars', function() {
return User.create({email: 'test@example.com', password: pass72Char})
.then(u => u.changePassword(pass72Char, pass73Char))
.then(
success => { throw new Error('changePassword should have failed'); },
err => {
expect(err.message).to.match(/Password too long/);

// workaround for chai problem
// object tested must be an array, an object, or a string,
// but error given
const props = Object.assign({}, err);
expect(props).to.contain({
code: 'PASSWORD_TOO_LONG',
statusCode: 422,
});
});
});
});

describe('Access-hook for queries with email NOT case-sensitive', function() {
Expand DownExpand Up@@ -1339,7 +1358,7 @@ describe('User', function() {
err => {
// workaround for chai problem
// object tested must be an array, an object, or a string,
// but error given
// but error given
const props = Object.assign({}, err);
expect(props).to.contain({
code: 'USER_NOT_FOUND',
Expand Down