From 344afcef278ee0fd423638d98bd802e42b7baf91 Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:43:41 +0100 Subject: [PATCH 1/3] Update UsersRouter.js --- src/Routers/UsersRouter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Routers/UsersRouter.js b/src/Routers/UsersRouter.js index 63e3f60df2..5de6077d54 100644 --- a/src/Routers/UsersRouter.js +++ b/src/Routers/UsersRouter.js @@ -142,6 +142,7 @@ export class UsersRouter extends ClassesRouter { master: req.auth.isMaster, ip: req.config.ip, installationId: req.auth.installationId, + object: Parse.User.fromJSON(Object.assign({ className: '_User' }, user)), }; // Get verification conditions which can be booleans or functions; the purpose of this async/await // structure is to avoid unnecessarily executing subsequent functions if previous ones fail in the From 4ea4fe525b8a6bb8e0cb1a64451bb1eb423ab87a Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Thu, 28 Dec 2023 00:12:11 +0100 Subject: [PATCH 2/3] add test --- spec/ValidationAndPasswordsReset.spec.js | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/ValidationAndPasswordsReset.spec.js b/spec/ValidationAndPasswordsReset.spec.js index 2efae6505c..42313bca58 100644 --- a/spec/ValidationAndPasswordsReset.spec.js +++ b/spec/ValidationAndPasswordsReset.spec.js @@ -267,6 +267,38 @@ describe('Custom Pages, Email Verification, Password Reset', () => { expect(loginRes.message).toEqual('User email is not verified.'); }); + it('provides function arguments in verifyUserEmails on login', async () => { + const user = new Parse.User(); + user.setUsername('user'); + user.setPassword('pass'); + user.set('email', 'test@example.com'); + await user.signUp(); + + const verifyUserEmails = { + method: async (params) => { + expect(params.object).toBeInstanceOf(Parse.User); + return true; + }, + }; + const verifyUserEmailsSpy = spyOn(verifyUserEmails, 'method').and.callThrough(); + await reconfigureServer({ + appName: 'test', + publicServerURL: 'http://localhost:1337/1', + verifyUserEmails: verifyUserEmails.method, + preventLoginWithUnverifiedEmail: verifyUserEmails.method, + preventSignupWithUnverifiedEmail: true, + emailAdapter: MockEmailAdapterWithOptions({ + fromAddress: 'parse@example.com', + apiKey: 'k', + domain: 'd', + }), + }); + + const res = await Parse.User.logIn('user', 'pass').catch(e => e); + expect(res.code).toBe(205); + expect(verifyUserEmailsSpy).toHaveBeenCalledTimes(2); + }); + it('allows user to login only after user clicks on the link to confirm email address if preventLoginWithUnverifiedEmail is set to true', async () => { let sendEmailOptions; const emailAdapter = { From e6aacec639d67bcbc1ca2fde3805dd7aaa8d34dc Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Thu, 28 Dec 2023 00:14:21 +0100 Subject: [PATCH 3/3] improve test --- spec/ValidationAndPasswordsReset.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/ValidationAndPasswordsReset.spec.js b/spec/ValidationAndPasswordsReset.spec.js index 42313bca58..5b450c1e68 100644 --- a/spec/ValidationAndPasswordsReset.spec.js +++ b/spec/ValidationAndPasswordsReset.spec.js @@ -277,6 +277,9 @@ describe('Custom Pages, Email Verification, Password Reset', () => { const verifyUserEmails = { method: async (params) => { expect(params.object).toBeInstanceOf(Parse.User); + expect(params.ip).toBeDefined(); + expect(params.master).toBeDefined(); + expect(params.installationId).toBeDefined(); return true; }, };