From 34b51f72892666657ca9dd6f2d121edccb7ee40b Mon Sep 17 00:00:00 2001 From: Arthur Cinader <700572+acinader@users.noreply.github.com> Date: Tue, 2 Oct 2018 15:01:50 -0700 Subject: [PATCH] Add failing test to show that changing a user's email does not delete their perishable token. --- spec/ValidationAndPasswordsReset.spec.js | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/spec/ValidationAndPasswordsReset.spec.js b/spec/ValidationAndPasswordsReset.spec.js index 77a4ca63..50730bcd 100644 --- a/spec/ValidationAndPasswordsReset.spec.js +++ b/spec/ValidationAndPasswordsReset.spec.js @@ -909,4 +909,56 @@ describe('Custom Pages, Email Verification, Password Reset', () => { }); }); }); + + it('deletes password reset token', done => { + reconfigureServer({ + appName: 'coolapp', + publicServerURL: 'http://localhost:1337/1', + emailAdapter: MockEmailAdapterWithOptions({ + fromAddress: 'parse@example.com', + apiKey: 'k', + domain: 'd', + }), + }) + .then(() => { + const config = Config.get('test'); + const user = new Parse.User(); + user.setPassword('asdf'); + user.setUsername('zxcv'); + user.set('email', 'test@parse.com'); + return user + .signUp(null) + .then(() => Parse.User.requestPasswordReset('test@parse.com')) + .then(() => config.database.adapter + .find( + '_User', + { fields: {} }, + { username: 'zxcv' }, + { limit: 1 } + )) + .then(results => { + // validate that there is a token + expect(results.length).toEqual(1); + expect(results[0]['_perishable_token']).not.toBeNull(); + user.set('email', 'test2@parse.com'); + return user.save(); + }) + .then(() => config.database.adapter + .find( + '_User', + { fields: {} }, + { username: 'zxcv' }, + { limit: 1 }) + ) + .then(results => { + expect(results.length).toEqual(1); + expect(results[0]['_perishable_token']).toBeNull(); + done(); + }) + }) + .catch(error => { + fail(JSON.stringify(error)); + done(); + }); + }); });