From a34101c3010622869285da25b83a70b6d7d9b2fe Mon Sep 17 00:00:00 2001 From: GERMAN Date: Tue, 21 Jul 2020 19:37:39 -0300 Subject: [PATCH 1/9] adding reset password feature using api --- src/Controllers/UserController.js | 15 ++++++++----- src/Routers/PublicAPIRouter.js | 2 +- src/Routers/UsersRouter.js | 37 +++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/Controllers/UserController.js b/src/Controllers/UserController.js index 959f6416d4..1a83e2d45f 100644 --- a/src/Controllers/UserController.js +++ b/src/Controllers/UserController.js @@ -90,7 +90,10 @@ export class UserController extends AdaptableController { ) .then(results => { if (results.length != 1) { - throw 'Failed to reset password: username / email / token is invalid'; + throw new Parse.Error( + Parse.Error.RESET_PASSWORD_ERROR, + 'Failed to reset password: username / email / token is invalid' + ); } if ( @@ -102,7 +105,10 @@ export class UserController extends AdaptableController { expiresDate = new Date(expiresDate.iso); } if (expiresDate < new Date()) - throw 'The password reset link has expired'; + throw new Parse.Error( + Parse.Error.RESET_LINK_EXPIRED, + 'The password reset link has expired' + ); } return results[0]; @@ -246,10 +252,7 @@ export class UserController extends AdaptableController { return this.checkResetTokenValidity(username, token) .then(user => updateUserPassword(user.objectId, password, this.config)) .catch(error => { - if (error && error.message) { - // in case of Parse.Error, fail with the error message only - return Promise.reject(error.message); - } else { + if (error) { return Promise.reject(error); } }); diff --git a/src/Routers/PublicAPIRouter.js b/src/Routers/PublicAPIRouter.js index 7453835473..8a00f10e27 100644 --- a/src/Routers/PublicAPIRouter.js +++ b/src/Routers/PublicAPIRouter.js @@ -203,7 +203,7 @@ export class PublicAPIRouter extends PromiseRouter { username: username, token: token, id: config.applicationId, - error: result.err, + error: result.err.message, app: config.appName, }); diff --git a/src/Routers/UsersRouter.js b/src/Routers/UsersRouter.js index 9d015f9659..f3f95874e6 100644 --- a/src/Routers/UsersRouter.js +++ b/src/Routers/UsersRouter.js @@ -361,6 +361,40 @@ export class UsersRouter extends ClassesRouter { } } + handlePasswordReset(req) { + this._throwOnBadEmailConfig(req); + + const { username, token, new_password } = req.body; + + if (!username) { + throw new Parse.Error( + Parse.Error.USERNAME_MISSING, + 'you must provide an username' + ); + } + return req.config.database + .find('_User', { + username: username, + }) + .then(results => { + if (!results.length || results.length < 1) { + throw new Parse.Error( + Parse.Error.USERNAME_NOT_FOUND, + `No user found with ${username}` + ); + } + + const userController = req.config.userController; + return userController + .updatePassword(username, token, new_password) + .then(() => { + return { + response: {}, + }; + }); + }); + } + handleResetRequest(req) { this._throwOnBadEmailConfig(req); @@ -473,6 +507,9 @@ export class UsersRouter extends ClassesRouter { this.route('POST', '/requestPasswordReset', req => { return this.handleResetRequest(req); }); + this.route('POST', '/passwordReset', req => { + return this.handlePasswordReset(req); + }); this.route('POST', '/verificationEmailRequest', req => { return this.handleVerificationEmailRequest(req); }); From 1addf84a7b8333829ba10bcf052cf46aca7677b0 Mon Sep 17 00:00:00 2001 From: GERMAN Date: Sat, 25 Jul 2020 20:26:04 -0300 Subject: [PATCH 2/9] adding unit tests --- spec/PublicAPI.spec.js | 260 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 258 insertions(+), 2 deletions(-) diff --git a/spec/PublicAPI.spec.js b/spec/PublicAPI.spec.js index 22c1383d5a..988716a65d 100644 --- a/spec/PublicAPI.spec.js +++ b/spec/PublicAPI.spec.js @@ -1,9 +1,13 @@ const req = require('../lib/request'); +const Config = require('../lib/Config'); -const request = function(url, callback) { +const request = function (url, callback) { return req({ url, - }).then(response => callback(null, response), err => callback(err, err)); + }).then( + response => callback(null, response), + err => callback(err, err) + ); }; describe('public API', () => { @@ -208,4 +212,256 @@ describe('public API supplied with invalid application id', () => { } ); }); + + fdescribe('resetPassword', () => { + let makeRequest; + const re = new RegExp('^(?=.*[a-z]).{8,}'); + let sendEmailOptions; + const emailAdapter = { + sendVerificationEmail: {}, + sendPasswordResetEmail: options => { + sendEmailOptions = options; + }, + sendMail: () => {}, + }; + + const serverURL = 'http://localhost:8378/1'; + + const headers = { + 'Content-Type': 'application/json', + 'X-Parse-Application-Id': 'test', + 'X-Parse-REST-API-Key': 'rest', + 'X-Parse-Installation-Id': 'yolo', + }; + + beforeEach(() => { + makeRequest = reconfigureServer({ + appName: 'coolapp', + publicServerURL: 'http://localhost:1337/1', + emailAdapter: emailAdapter, + passwordPolicy: { + validatorPattern: re, + doNotAllowUsername: true, + maxPasswordHistory: 1, + resetTokenValidityDuration: 0.5, // 0.5 second + }, + }).then(() => { + const config = Config.get('test'); + const user = new Parse.User(); + user.setPassword('asdsweqwasas'); + user.setUsername('test'); + user.set('email', 'test@parse.com'); + return user + .signUp(null) + .then(() => { + // build history + user.setPassword('aaaaaaaaaaaa'); + return user.save(); + }) + .then(() => Parse.User.requestPasswordReset('test@parse.com')) + .then(() => + config.database.adapter.find( + '_User', + { fields: {} }, + { username: 'test' }, + { limit: 1 } + ) + ); + }); + }); + + it('Password reset failed due to password policy', done => { + makeRequest.then(results => { + req({ + url: `${serverURL}/passwordReset`, + method: 'POST', + headers, + body: JSON.stringify({ + _method: 'POST', + username: 'test', + token: results[0]['_perishable_token'], + new_password: 'zxcv', + }), + }).then( + () => { + fail('Expected to be failed'); + done(); + }, + err => { + // TODO: Parse.Error.VALIDATION_ERROR is generic, there should be another error code like Parse.Error.PASSWORD_POLICY_NOT_MEET + expect(err.data.code).not.toBe(undefined); + expect(err.data.code).toBe(Parse.Error.VALIDATION_ERROR); + done(); + } + ); + }); + }); + + it('Password reset failed due to invalid token', done => { + makeRequest.then(results => { + req({ + url: `${serverURL}/passwordReset`, + method: 'POST', + headers, + body: JSON.stringify({ + _method: 'POST', + username: 'test', + token: results[0]['_perishable_token'] + 'invalid', + new_password: 'zxcv', + }), + }).then( + () => { + fail('Expected to be failed'); + done(); + }, + err => { + // TODO: Missing Parse.Error code, only string message, there should be an error code like Parse.Error.RESET_PASSWORD_ERROR + expect(err.data.code).not.toBe(undefined); + done(); + } + ); + }); + }); + + it('Password reset failed due to password is repeated', done => { + makeRequest.then(results => { + req({ + url: `${serverURL}/passwordReset`, + method: 'POST', + headers, + body: JSON.stringify({ + _method: 'POST', + username: 'test', + token: results[0]['_perishable_token'], + new_password: 'aaaaaaaaaaaa', + }), + }).then( + () => { + fail('Expected to be failed'); + done(); + }, + err => { + // TODO: Parse.Error.VALIDATION_ERROR is generic, there should be another error code like Parse.Error.PASSWORD_POLICY_REPEAT + expect(err.data.code).not.toBe(undefined); + expect(err.data.code).toBe(Parse.Error.VALIDATION_ERROR); + done(); + } + ); + }); + }); + + it('Password reset failed due to it contains username', done => { + makeRequest.then(results => { + req({ + url: `${serverURL}/passwordReset`, + method: 'POST', + headers, + body: JSON.stringify({ + _method: 'POST', + username: 'test', + token: results[0]['_perishable_token'], + new_password: 'asdsweqwasastest', + }), + }).then( + () => { + fail('Expected to be failed'); + done(); + }, + err => { + // TODO: Parse.Error.VALIDATION_ERROR is generic, there should be another error code like Parse.Error.PASSWORD_POLICY_USERNAME + expect(err.data.code).not.toBe(undefined); + expect(err.data.code).toBe(Parse.Error.VALIDATION_ERROR); + done(); + } + ); + }); + }); + + it('Password reset username not found', done => { + makeRequest.then(results => { + req({ + url: `${serverURL}/passwordReset`, + method: 'POST', + headers, + body: JSON.stringify({ + _method: 'POST', + username: 'test1', + token: results[0]['_perishable_token'], + new_password: 'asdsweqwasastest', + }), + }).then( + () => { + fail('Expected to be failed'); + done(); + }, + err => { + // TODO: Missing Parse.Error code, only string message, there should be an error code like Parse.Error.USERNAME_NOT_FOUND + expect(err.data.code).not.toBe(undefined); + done(); + } + ); + }); + }); + + it('Password reset failed due to link has expired', done => { + makeRequest + .then(results => { + // wait for a bit more than the validity duration set + setTimeout(() => { + expect(sendEmailOptions).not.toBeUndefined(); + + req({ + url: `${serverURL}/passwordReset`, + method: 'POST', + headers, + body: JSON.stringify({ + _method: 'POST', + username: 'test', + token: results[0]['_perishable_token'], + new_password: 'asdsweqwasas', + }), + }) + .then(() => { + fail('Expected to be failed'); + done(); + }) + .catch(error => { + // TODO: Missing Parse.Error code, only string message, there should be an error code like Parse.Error.RESET_LINK_EXPIRED + expect(error.data.code).not.toBe(undefined); + expect(error.data.code).toBe(Parse.Error.RESET_LINK_EXPIRED); + }); + done(); + }, 1000); + }) + .catch(err => { + jfail(err); + done(); + }); + }); + + it('Password successfully reset', done => { + makeRequest.then(results => { + req({ + url: `${serverURL}/passwordReset`, + method: 'POST', + headers, + body: JSON.stringify({ + _method: 'POST', + username: 'test', + token: results[0]['_perishable_token'], + new_password: 'asdsweqwasas', + }), + }).then( + res => { + expect(res.status).toBe(200); + done(); + }, + () => { + fail('Expected to not fail'); + done(); + } + ); + }); + }); + }); }); From 7037a1eedf8f114eaef48da88861eed9c5798a33 Mon Sep 17 00:00:00 2001 From: GERMAN Date: Sat, 25 Jul 2020 20:31:43 -0300 Subject: [PATCH 3/9] remove focus describe --- spec/PublicAPI.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/PublicAPI.spec.js b/spec/PublicAPI.spec.js index 988716a65d..9a43fbe4ee 100644 --- a/spec/PublicAPI.spec.js +++ b/spec/PublicAPI.spec.js @@ -213,7 +213,7 @@ describe('public API supplied with invalid application id', () => { ); }); - fdescribe('resetPassword', () => { + describe('resetPassword', () => { let makeRequest; const re = new RegExp('^(?=.*[a-z]).{8,}'); let sendEmailOptions; From 0196b414b8831d8e7197ba0b62ac4fc5b9b657f9 Mon Sep 17 00:00:00 2001 From: GERMAN Date: Sun, 26 Jul 2020 12:13:34 -0300 Subject: [PATCH 4/9] fix public api router error message --- spec/PasswordPolicy.spec.js | 20 ++++++++++---------- src/Routers/PublicAPIRouter.js | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/PasswordPolicy.spec.js b/spec/PasswordPolicy.spec.js index 6bc076af78..2f40acac7b 100644 --- a/spec/PasswordPolicy.spec.js +++ b/spec/PasswordPolicy.spec.js @@ -305,7 +305,7 @@ describe('Password Policy: ', () => { Parse.User.logOut() .then(() => { Parse.User.logIn('user1', '1digit') - .then(function() { + .then(function () { done(); }) .catch(err => { @@ -348,7 +348,7 @@ describe('Password Policy: ', () => { Parse.User.logOut() .then(() => { Parse.User.logIn('user1', 'p@sswrod') - .then(function() { + .then(function () { done(); }) .catch(err => { @@ -418,7 +418,7 @@ describe('Password Policy: ', () => { Parse.User.logOut() .then(() => { Parse.User.logIn('user1', 'oneUpper') - .then(function() { + .then(function () { done(); }) .catch(err => { @@ -516,7 +516,7 @@ describe('Password Policy: ', () => { Parse.User.logOut() .then(() => { Parse.User.logIn('user1', 'oneUpper') - .then(function() { + .then(function () { done(); }) .catch(err => { @@ -579,7 +579,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'has2init') - .then(function() { + .then(function () { done(); }) .catch(err => { @@ -671,7 +671,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'has 1 digit') - .then(function() { + .then(function () { done(); }) .catch(err => { @@ -861,7 +861,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'r@nd0m') - .then(function() { + .then(function () { done(); }) .catch(err => { @@ -947,7 +947,7 @@ describe('Password Policy: ', () => { } catch (error) { expect(error.status).not.toBe(302); expect(error.text).toEqual( - '{"code":-1,"error":"Password cannot contain your username."}' + '{"code":-1,"error":"ParseError: 142 Password cannot contain your username."}' ); } await Parse.User.logIn('user1', 'r@nd0m'); @@ -1012,7 +1012,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'uuser11') - .then(function() { + .then(function () { done(); }) .catch(err => { @@ -1284,7 +1284,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'uuser11') - .then(function() { + .then(function () { done(); }) .catch(err => { diff --git a/src/Routers/PublicAPIRouter.js b/src/Routers/PublicAPIRouter.js index 8a00f10e27..3f918e1e80 100644 --- a/src/Routers/PublicAPIRouter.js +++ b/src/Routers/PublicAPIRouter.js @@ -203,7 +203,7 @@ export class PublicAPIRouter extends PromiseRouter { username: username, token: token, id: config.applicationId, - error: result.err.message, + error: result.err ? result.err.message : result.err, app: config.appName, }); From eee7b1b79128c0a119ea1691661fff77e811e2b7 Mon Sep 17 00:00:00 2001 From: GERMAN Date: Sat, 1 Aug 2020 13:39:31 -0300 Subject: [PATCH 5/9] revert back changes for adding new reset password api --- spec/PasswordPolicy.spec.js | 2 +- spec/PublicAPI.spec.js | 253 --------------------------------- src/Routers/PublicAPIRouter.js | 2 +- src/Routers/UsersRouter.js | 37 ----- 4 files changed, 2 insertions(+), 292 deletions(-) diff --git a/spec/PasswordPolicy.spec.js b/spec/PasswordPolicy.spec.js index 2f40acac7b..241364b9e6 100644 --- a/spec/PasswordPolicy.spec.js +++ b/spec/PasswordPolicy.spec.js @@ -947,7 +947,7 @@ describe('Password Policy: ', () => { } catch (error) { expect(error.status).not.toBe(302); expect(error.text).toEqual( - '{"code":-1,"error":"ParseError: 142 Password cannot contain your username."}' + '{"code":142,"error":"Password cannot contain your username."}' ); } await Parse.User.logIn('user1', 'r@nd0m'); diff --git a/spec/PublicAPI.spec.js b/spec/PublicAPI.spec.js index 9a43fbe4ee..1e3ed8d7ca 100644 --- a/spec/PublicAPI.spec.js +++ b/spec/PublicAPI.spec.js @@ -1,5 +1,4 @@ const req = require('../lib/request'); -const Config = require('../lib/Config'); const request = function (url, callback) { return req({ @@ -212,256 +211,4 @@ describe('public API supplied with invalid application id', () => { } ); }); - - describe('resetPassword', () => { - let makeRequest; - const re = new RegExp('^(?=.*[a-z]).{8,}'); - let sendEmailOptions; - const emailAdapter = { - sendVerificationEmail: {}, - sendPasswordResetEmail: options => { - sendEmailOptions = options; - }, - sendMail: () => {}, - }; - - const serverURL = 'http://localhost:8378/1'; - - const headers = { - 'Content-Type': 'application/json', - 'X-Parse-Application-Id': 'test', - 'X-Parse-REST-API-Key': 'rest', - 'X-Parse-Installation-Id': 'yolo', - }; - - beforeEach(() => { - makeRequest = reconfigureServer({ - appName: 'coolapp', - publicServerURL: 'http://localhost:1337/1', - emailAdapter: emailAdapter, - passwordPolicy: { - validatorPattern: re, - doNotAllowUsername: true, - maxPasswordHistory: 1, - resetTokenValidityDuration: 0.5, // 0.5 second - }, - }).then(() => { - const config = Config.get('test'); - const user = new Parse.User(); - user.setPassword('asdsweqwasas'); - user.setUsername('test'); - user.set('email', 'test@parse.com'); - return user - .signUp(null) - .then(() => { - // build history - user.setPassword('aaaaaaaaaaaa'); - return user.save(); - }) - .then(() => Parse.User.requestPasswordReset('test@parse.com')) - .then(() => - config.database.adapter.find( - '_User', - { fields: {} }, - { username: 'test' }, - { limit: 1 } - ) - ); - }); - }); - - it('Password reset failed due to password policy', done => { - makeRequest.then(results => { - req({ - url: `${serverURL}/passwordReset`, - method: 'POST', - headers, - body: JSON.stringify({ - _method: 'POST', - username: 'test', - token: results[0]['_perishable_token'], - new_password: 'zxcv', - }), - }).then( - () => { - fail('Expected to be failed'); - done(); - }, - err => { - // TODO: Parse.Error.VALIDATION_ERROR is generic, there should be another error code like Parse.Error.PASSWORD_POLICY_NOT_MEET - expect(err.data.code).not.toBe(undefined); - expect(err.data.code).toBe(Parse.Error.VALIDATION_ERROR); - done(); - } - ); - }); - }); - - it('Password reset failed due to invalid token', done => { - makeRequest.then(results => { - req({ - url: `${serverURL}/passwordReset`, - method: 'POST', - headers, - body: JSON.stringify({ - _method: 'POST', - username: 'test', - token: results[0]['_perishable_token'] + 'invalid', - new_password: 'zxcv', - }), - }).then( - () => { - fail('Expected to be failed'); - done(); - }, - err => { - // TODO: Missing Parse.Error code, only string message, there should be an error code like Parse.Error.RESET_PASSWORD_ERROR - expect(err.data.code).not.toBe(undefined); - done(); - } - ); - }); - }); - - it('Password reset failed due to password is repeated', done => { - makeRequest.then(results => { - req({ - url: `${serverURL}/passwordReset`, - method: 'POST', - headers, - body: JSON.stringify({ - _method: 'POST', - username: 'test', - token: results[0]['_perishable_token'], - new_password: 'aaaaaaaaaaaa', - }), - }).then( - () => { - fail('Expected to be failed'); - done(); - }, - err => { - // TODO: Parse.Error.VALIDATION_ERROR is generic, there should be another error code like Parse.Error.PASSWORD_POLICY_REPEAT - expect(err.data.code).not.toBe(undefined); - expect(err.data.code).toBe(Parse.Error.VALIDATION_ERROR); - done(); - } - ); - }); - }); - - it('Password reset failed due to it contains username', done => { - makeRequest.then(results => { - req({ - url: `${serverURL}/passwordReset`, - method: 'POST', - headers, - body: JSON.stringify({ - _method: 'POST', - username: 'test', - token: results[0]['_perishable_token'], - new_password: 'asdsweqwasastest', - }), - }).then( - () => { - fail('Expected to be failed'); - done(); - }, - err => { - // TODO: Parse.Error.VALIDATION_ERROR is generic, there should be another error code like Parse.Error.PASSWORD_POLICY_USERNAME - expect(err.data.code).not.toBe(undefined); - expect(err.data.code).toBe(Parse.Error.VALIDATION_ERROR); - done(); - } - ); - }); - }); - - it('Password reset username not found', done => { - makeRequest.then(results => { - req({ - url: `${serverURL}/passwordReset`, - method: 'POST', - headers, - body: JSON.stringify({ - _method: 'POST', - username: 'test1', - token: results[0]['_perishable_token'], - new_password: 'asdsweqwasastest', - }), - }).then( - () => { - fail('Expected to be failed'); - done(); - }, - err => { - // TODO: Missing Parse.Error code, only string message, there should be an error code like Parse.Error.USERNAME_NOT_FOUND - expect(err.data.code).not.toBe(undefined); - done(); - } - ); - }); - }); - - it('Password reset failed due to link has expired', done => { - makeRequest - .then(results => { - // wait for a bit more than the validity duration set - setTimeout(() => { - expect(sendEmailOptions).not.toBeUndefined(); - - req({ - url: `${serverURL}/passwordReset`, - method: 'POST', - headers, - body: JSON.stringify({ - _method: 'POST', - username: 'test', - token: results[0]['_perishable_token'], - new_password: 'asdsweqwasas', - }), - }) - .then(() => { - fail('Expected to be failed'); - done(); - }) - .catch(error => { - // TODO: Missing Parse.Error code, only string message, there should be an error code like Parse.Error.RESET_LINK_EXPIRED - expect(error.data.code).not.toBe(undefined); - expect(error.data.code).toBe(Parse.Error.RESET_LINK_EXPIRED); - }); - done(); - }, 1000); - }) - .catch(err => { - jfail(err); - done(); - }); - }); - - it('Password successfully reset', done => { - makeRequest.then(results => { - req({ - url: `${serverURL}/passwordReset`, - method: 'POST', - headers, - body: JSON.stringify({ - _method: 'POST', - username: 'test', - token: results[0]['_perishable_token'], - new_password: 'asdsweqwasas', - }), - }).then( - res => { - expect(res.status).toBe(200); - done(); - }, - () => { - fail('Expected to not fail'); - done(); - } - ); - }); - }); - }); }); diff --git a/src/Routers/PublicAPIRouter.js b/src/Routers/PublicAPIRouter.js index 3f918e1e80..bceadb0fbd 100644 --- a/src/Routers/PublicAPIRouter.js +++ b/src/Routers/PublicAPIRouter.js @@ -215,7 +215,7 @@ export class PublicAPIRouter extends PromiseRouter { }); } if (result.err) { - throw new Parse.Error(Parse.Error.OTHER_CAUSE, `${result.err}`); + throw result.err; } } diff --git a/src/Routers/UsersRouter.js b/src/Routers/UsersRouter.js index f3f95874e6..9d015f9659 100644 --- a/src/Routers/UsersRouter.js +++ b/src/Routers/UsersRouter.js @@ -361,40 +361,6 @@ export class UsersRouter extends ClassesRouter { } } - handlePasswordReset(req) { - this._throwOnBadEmailConfig(req); - - const { username, token, new_password } = req.body; - - if (!username) { - throw new Parse.Error( - Parse.Error.USERNAME_MISSING, - 'you must provide an username' - ); - } - return req.config.database - .find('_User', { - username: username, - }) - .then(results => { - if (!results.length || results.length < 1) { - throw new Parse.Error( - Parse.Error.USERNAME_NOT_FOUND, - `No user found with ${username}` - ); - } - - const userController = req.config.userController; - return userController - .updatePassword(username, token, new_password) - .then(() => { - return { - response: {}, - }; - }); - }); - } - handleResetRequest(req) { this._throwOnBadEmailConfig(req); @@ -507,9 +473,6 @@ export class UsersRouter extends ClassesRouter { this.route('POST', '/requestPasswordReset', req => { return this.handleResetRequest(req); }); - this.route('POST', '/passwordReset', req => { - return this.handlePasswordReset(req); - }); this.route('POST', '/verificationEmailRequest', req => { return this.handleVerificationEmailRequest(req); }); From 23705def91839d4827374ed71bc474648ef61afb Mon Sep 17 00:00:00 2001 From: GERMAN Date: Sat, 1 Aug 2020 15:13:52 -0300 Subject: [PATCH 6/9] adding comment to unit test --- spec/PasswordPolicy.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/PasswordPolicy.spec.js b/spec/PasswordPolicy.spec.js index 241364b9e6..e5008dc6c0 100644 --- a/spec/PasswordPolicy.spec.js +++ b/spec/PasswordPolicy.spec.js @@ -946,6 +946,7 @@ describe('Password Policy: ', () => { }); } catch (error) { expect(error.status).not.toBe(302); + // 142 error is too generic, a more specific error code should be thrown like Parse.Error.PASSWORD_POLICY_USERNAME expect(error.text).toEqual( '{"code":142,"error":"Password cannot contain your username."}' ); From dd47f58c5a3b12e52b64f12252a2a10fbcdbd12e Mon Sep 17 00:00:00 2001 From: GERMAN Date: Sat, 1 Aug 2020 15:24:55 -0300 Subject: [PATCH 7/9] adding comment to unit test --- spec/PasswordPolicy.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/PasswordPolicy.spec.js b/spec/PasswordPolicy.spec.js index e5008dc6c0..59d2e0ad29 100644 --- a/spec/PasswordPolicy.spec.js +++ b/spec/PasswordPolicy.spec.js @@ -946,7 +946,7 @@ describe('Password Policy: ', () => { }); } catch (error) { expect(error.status).not.toBe(302); - // 142 error is too generic, a more specific error code should be thrown like Parse.Error.PASSWORD_POLICY_USERNAME + // ToDO: 142 error is too generic, a more specific error code should be thrown like Parse.Error.PASSWORD_POLICY_USERNAME expect(error.text).toEqual( '{"code":142,"error":"Password cannot contain your username."}' ); From f0da9707c576ffbf9df4a393a14e908a9fbe0b56 Mon Sep 17 00:00:00 2001 From: GERMAN Date: Sat, 1 Aug 2020 15:29:25 -0300 Subject: [PATCH 8/9] adding comment to unit test --- spec/PasswordPolicy.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/PasswordPolicy.spec.js b/spec/PasswordPolicy.spec.js index 59d2e0ad29..30bfe31080 100644 --- a/spec/PasswordPolicy.spec.js +++ b/spec/PasswordPolicy.spec.js @@ -225,6 +225,7 @@ describe('Password Policy: ', () => { done(); }) .catch(error => { + // ToDO: 142 error is too generic, a more specific error code should be thrown like Parse.Error.PASSWORD_POLICY_USERNAME expect(error.code).toEqual(142); done(); }); From 62b3ade020241bc7b9822d05ffb71013530a65a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Bisogno?= <68487907+germanbisogno@users.noreply.github.com> Date: Sun, 2 Aug 2020 00:31:39 -0300 Subject: [PATCH 9/9] Update PasswordPolicy.spec.js code formatting --- spec/PasswordPolicy.spec.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/PasswordPolicy.spec.js b/spec/PasswordPolicy.spec.js index 30bfe31080..aea136fb4a 100644 --- a/spec/PasswordPolicy.spec.js +++ b/spec/PasswordPolicy.spec.js @@ -306,7 +306,7 @@ describe('Password Policy: ', () => { Parse.User.logOut() .then(() => { Parse.User.logIn('user1', '1digit') - .then(function () { + .then(function() { done(); }) .catch(err => { @@ -349,7 +349,7 @@ describe('Password Policy: ', () => { Parse.User.logOut() .then(() => { Parse.User.logIn('user1', 'p@sswrod') - .then(function () { + .then(function() { done(); }) .catch(err => { @@ -419,7 +419,7 @@ describe('Password Policy: ', () => { Parse.User.logOut() .then(() => { Parse.User.logIn('user1', 'oneUpper') - .then(function () { + .then(function() { done(); }) .catch(err => { @@ -517,7 +517,7 @@ describe('Password Policy: ', () => { Parse.User.logOut() .then(() => { Parse.User.logIn('user1', 'oneUpper') - .then(function () { + .then(function() { done(); }) .catch(err => { @@ -580,7 +580,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'has2init') - .then(function () { + .then(function() { done(); }) .catch(err => { @@ -672,7 +672,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'has 1 digit') - .then(function () { + .then(function() { done(); }) .catch(err => { @@ -862,7 +862,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'r@nd0m') - .then(function () { + .then(function() { done(); }) .catch(err => { @@ -1014,7 +1014,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'uuser11') - .then(function () { + .then(function() { done(); }) .catch(err => { @@ -1286,7 +1286,7 @@ describe('Password Policy: ', () => { ); Parse.User.logIn('user1', 'uuser11') - .then(function () { + .then(function() { done(); }) .catch(err => {