From 6135defdbe3648415aa7f8e761c4e5823082f834 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Wed, 27 Jan 2021 11:10:53 +0100 Subject: [PATCH] Merge pull request #3582 from overleaf/msm-fix-uppercase-email-registration Generate registration token using `email` field from `users` table GitOrigin-RevId: ad7ad0ed87abaf25debbbd11ef978ba7b0a723ea --- .../web/app/src/Features/User/UserRegistrationHandler.js | 2 +- .../test/unit/src/User/UserRegistrationHandlerTests.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/web/app/src/Features/User/UserRegistrationHandler.js b/services/web/app/src/Features/User/UserRegistrationHandler.js index 809adb2db7..09f98bc9b7 100644 --- a/services/web/app/src/Features/User/UserRegistrationHandler.js +++ b/services/web/app/src/Features/User/UserRegistrationHandler.js @@ -122,7 +122,7 @@ const UserRegistrationHandler = { const ONE_WEEK = 7 * 24 * 60 * 60 // seconds OneTimeTokenHandler.getNewToken( 'password', - { user_id: user._id.toString(), email }, + { user_id: user._id.toString(), email: user.email }, { expiresIn: ONE_WEEK }, (err, token) => { if (err != null) { diff --git a/services/web/test/unit/src/User/UserRegistrationHandlerTests.js b/services/web/test/unit/src/User/UserRegistrationHandlerTests.js index ec220f3a8f..541fca5034 100644 --- a/services/web/test/unit/src/User/UserRegistrationHandlerTests.js +++ b/services/web/test/unit/src/User/UserRegistrationHandlerTests.js @@ -250,7 +250,7 @@ describe('UserRegistrationHandler', function() { describe('registerNewUserAndSendActivationEmail', function() { beforeEach(function() { - this.email = 'email@example.com' + this.email = 'Email@example.com' this.crypto.randomBytes = sinon.stub().returns({ toString: () => { return (this.password = 'mock-password') @@ -266,6 +266,7 @@ describe('UserRegistrationHandler', function() { describe('with a new user', function() { beforeEach(function() { + this.user.email = this.email.toLowerCase() this.handler.registerNewUser.callsArgWith(1, null, this.user) return this.handler.registerNewUserAndSendActivationEmail( this.email, @@ -283,7 +284,10 @@ describe('UserRegistrationHandler', function() { }) it('should generate a new password reset token', function() { - const data = { user_id: this.user._id.toString(), email: this.email } + const data = { + user_id: this.user._id.toString(), + email: this.user.email + } return this.OneTimeTokenHandler.getNewToken .calledWith('password', data, { expiresIn: 7 * 24 * 60 * 60 }) .should.equal(true)