This commit is contained in:
Florent Vilmart
2016-04-11 14:27:55 -04:00
committed by Drew
parent 281568edd2
commit 73a3db44ab
2 changed files with 27 additions and 0 deletions

View File

@@ -1514,6 +1514,29 @@ describe('Parse.User testing', () => {
});
});
it('should properly error when password is missing', (done) => {
var provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);
Parse.User._logInWith("facebook", {
success: function(user) {
user.set('username', 'myUser');
user.set('email', 'foo@example.com');
user.save().then(() => {
return Parse.User.logOut();
}).then(() => {
return Parse.User.logIn('myUser', 'password');
}).then(() => {
fail('should not succeed');
done();
}, (err) => {
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
expect(err.message).toEqual('Invalid username/password.');
done();
})
}
});
});
it('should have authData in beforeSave and afterSave', (done) => {
Parse.Cloud.beforeSave('_User', (request, response) => {

View File

@@ -19,6 +19,10 @@ function hash(password) {
// hashed password.
function compare(password, hashedPassword) {
return new Promise(function(fulfill, reject) {
// Cannot bcrypt compare when one is undefined
if (!password || !hashedPassword) {
return fulfill(false);
}
bcrypt.compare(password, hashedPassword, function(err, success) {
if (err) {
reject(err);