Merge pull request #3582 from overleaf/msm-fix-uppercase-email-registration

Generate registration token using `email` field from `users` table

GitOrigin-RevId: ad7ad0ed87abaf25debbbd11ef978ba7b0a723ea
This commit is contained in:
Miguel Serrano 2021-01-27 11:10:53 +01:00 committed by Copybot
parent 1036708e0e
commit 6135defdbe
2 changed files with 7 additions and 3 deletions

View file

@ -122,7 +122,7 @@ const UserRegistrationHandler = {
const ONE_WEEK = 7 * 24 * 60 * 60 // seconds const ONE_WEEK = 7 * 24 * 60 * 60 // seconds
OneTimeTokenHandler.getNewToken( OneTimeTokenHandler.getNewToken(
'password', 'password',
{ user_id: user._id.toString(), email }, { user_id: user._id.toString(), email: user.email },
{ expiresIn: ONE_WEEK }, { expiresIn: ONE_WEEK },
(err, token) => { (err, token) => {
if (err != null) { if (err != null) {

View file

@ -250,7 +250,7 @@ describe('UserRegistrationHandler', function() {
describe('registerNewUserAndSendActivationEmail', function() { describe('registerNewUserAndSendActivationEmail', function() {
beforeEach(function() { beforeEach(function() {
this.email = 'email@example.com' this.email = 'Email@example.com'
this.crypto.randomBytes = sinon.stub().returns({ this.crypto.randomBytes = sinon.stub().returns({
toString: () => { toString: () => {
return (this.password = 'mock-password') return (this.password = 'mock-password')
@ -266,6 +266,7 @@ describe('UserRegistrationHandler', function() {
describe('with a new user', function() { describe('with a new user', function() {
beforeEach(function() { beforeEach(function() {
this.user.email = this.email.toLowerCase()
this.handler.registerNewUser.callsArgWith(1, null, this.user) this.handler.registerNewUser.callsArgWith(1, null, this.user)
return this.handler.registerNewUserAndSendActivationEmail( return this.handler.registerNewUserAndSendActivationEmail(
this.email, this.email,
@ -283,7 +284,10 @@ describe('UserRegistrationHandler', function() {
}) })
it('should generate a new password reset token', 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 return this.OneTimeTokenHandler.getNewToken
.calledWith('password', data, { expiresIn: 7 * 24 * 60 * 60 }) .calledWith('password', data, { expiresIn: 7 * 24 * 60 * 60 })
.should.equal(true) .should.equal(true)