diff --git a/spec/PasswordPolicy.spec.js b/spec/PasswordPolicy.spec.js index cdd6b274..b03ca7ff 100644 --- a/spec/PasswordPolicy.spec.js +++ b/spec/PasswordPolicy.spec.js @@ -219,6 +219,28 @@ describe("Password Policy: ", () => { }) }); + it('signup should fail if password is empty', (done) => { + const user = new Parse.User(); + reconfigureServer({ + appName: 'passwordPolicy', + passwordPolicy: { + validatorPattern: "^.{8,}" // password should contain at least 8 char + }, + publicServerURL: "http://localhost:8378/1" + }).then(() => { + user.setUsername("user1"); + user.setPassword(""); + user.set('email', 'user1@parse.com'); + user.signUp().then(() => { + fail('Should have failed as password does not conform to the policy.'); + done(); + }).catch((error) => { + expect(error.message).toEqual('Cannot sign up user with an empty password.'); + done(); + }); + }) + }); + it('signup should succeed if password conforms to the policy enforced using validatorPattern', (done) => { const user = new Parse.User(); reconfigureServer({ diff --git a/src/RestWrite.js b/src/RestWrite.js index 188660d7..43738ae3 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -366,7 +366,7 @@ RestWrite.prototype.transformUser = function() { return promise.then(() => { // Transform the password - if (!this.data.password) { + if (this.data.password === undefined) { // ignore only if undefined. should proceed if empty ('') return Promise.resolve(); }