2019-06-14 12:31:46 -04:00
|
|
|
/* eslint-disable
|
|
|
|
handle-callback-err,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
2019-06-14 12:31:46 -04:00
|
|
|
const assert = require('assert')
|
2019-05-29 05:21:06 -04:00
|
|
|
const path = require('path')
|
|
|
|
const sinon = require('sinon')
|
2019-06-14 12:31:46 -04:00
|
|
|
const sinonChai = require('sinon-chai')
|
|
|
|
const chai = require('chai')
|
2019-05-29 05:21:06 -04:00
|
|
|
const modulePath = path.join(
|
|
|
|
__dirname,
|
|
|
|
'../../../../app/src/Features/PasswordReset/PasswordResetHandler'
|
|
|
|
)
|
2019-06-14 12:31:46 -04:00
|
|
|
const should = require('chai').should()
|
|
|
|
chai.use(sinonChai)
|
|
|
|
const { expect } = chai
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
describe('PasswordResetHandler', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.settings = { siteUrl: 'www.sharelatex.com' }
|
|
|
|
this.OneTimeTokenHandler = {
|
|
|
|
getNewToken: sinon.stub(),
|
|
|
|
getValueFromTokenAndExpire: sinon.stub()
|
|
|
|
}
|
|
|
|
this.UserGetter = {
|
|
|
|
getUserByMainEmail: sinon.stub(),
|
|
|
|
getUser: sinon.stub(),
|
|
|
|
getUserByAnyEmail: sinon.stub()
|
|
|
|
}
|
|
|
|
this.EmailHandler = { sendEmail: sinon.stub() }
|
|
|
|
this.AuthenticationManager = {
|
2020-08-13 09:42:28 -04:00
|
|
|
setUserPasswordInV2: sinon.stub(),
|
|
|
|
promises: {
|
|
|
|
setUserPassword: sinon.stub().resolves()
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.PasswordResetHandler = SandboxedModule.require(modulePath, {
|
2019-06-14 12:31:46 -04:00
|
|
|
globals: { console: console },
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
2020-08-13 09:42:28 -04:00
|
|
|
'../User/UserAuditLogHandler': (this.UserAuditLogHandler = {
|
|
|
|
promises: {
|
|
|
|
addEntry: sinon.stub().resolves()
|
|
|
|
}
|
|
|
|
}),
|
2019-05-29 05:21:06 -04:00
|
|
|
'../User/UserGetter': this.UserGetter,
|
|
|
|
'../Security/OneTimeTokenHandler': this.OneTimeTokenHandler,
|
|
|
|
'../Email/EmailHandler': this.EmailHandler,
|
|
|
|
'../Authentication/AuthenticationManager': this.AuthenticationManager,
|
|
|
|
'settings-sharelatex': this.settings,
|
|
|
|
'logger-sharelatex': {
|
|
|
|
log() {},
|
|
|
|
err() {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.token = '12312321i'
|
2019-06-14 12:31:46 -04:00
|
|
|
this.user_id = 'user_id_here'
|
2020-08-13 09:42:28 -04:00
|
|
|
this.user = { email: (this.email = 'bob@bob.com'), _id: this.user_id }
|
2019-05-29 05:21:06 -04:00
|
|
|
this.password = 'my great secret password'
|
2019-07-04 08:40:12 -04:00
|
|
|
this.callback = sinon.stub()
|
2019-06-14 12:31:46 -04:00
|
|
|
// this should not have any effect now
|
|
|
|
this.settings.overleaf = true
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
this.settings.overleaf = false
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('generateAndEmailResetToken', function() {
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should check the user exists', function() {
|
|
|
|
this.UserGetter.getUserByAnyEmail.yields()
|
|
|
|
this.PasswordResetHandler.generateAndEmailResetToken(
|
|
|
|
this.user.email,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
this.UserGetter.getUserByAnyEmail.should.have.been.calledWith(
|
|
|
|
this.user.email
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should send the email with the token', function(done) {
|
|
|
|
this.UserGetter.getUserByAnyEmail.yields(null, this.user)
|
|
|
|
this.OneTimeTokenHandler.getNewToken.yields(null, this.token)
|
|
|
|
this.EmailHandler.sendEmail.yields()
|
|
|
|
this.PasswordResetHandler.generateAndEmailResetToken(
|
|
|
|
this.user.email,
|
|
|
|
(err, status) => {
|
|
|
|
this.EmailHandler.sendEmail.called.should.equal(true)
|
|
|
|
status.should.equal('primary')
|
|
|
|
const args = this.EmailHandler.sendEmail.args[0]
|
|
|
|
args[0].should.equal('passwordResetRequested')
|
|
|
|
args[1].setNewPasswordUrl.should.equal(
|
|
|
|
`${this.settings.siteUrl}/user/password/set?passwordResetToken=${
|
|
|
|
this.token
|
|
|
|
}&email=${encodeURIComponent(this.user.email)}`
|
|
|
|
)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the email exists', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.UserGetter.getUserByAnyEmail.yields(null, this.user)
|
|
|
|
this.OneTimeTokenHandler.getNewToken.yields(null, this.token)
|
|
|
|
this.EmailHandler.sendEmail.yields()
|
2019-07-04 08:40:12 -04:00
|
|
|
this.PasswordResetHandler.generateAndEmailResetToken(
|
2019-06-14 12:31:46 -04:00
|
|
|
this.email,
|
|
|
|
this.callback
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should set the password token data to the user id and email', function() {
|
|
|
|
this.OneTimeTokenHandler.getNewToken.should.have.been.calledWith(
|
|
|
|
'password',
|
|
|
|
{
|
|
|
|
email: this.email,
|
|
|
|
user_id: this.user._id
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should send an email with the token', function() {
|
|
|
|
this.EmailHandler.sendEmail.called.should.equal(true)
|
|
|
|
const args = this.EmailHandler.sendEmail.args[0]
|
|
|
|
args[0].should.equal('passwordResetRequested')
|
|
|
|
args[1].setNewPasswordUrl.should.equal(
|
|
|
|
`${this.settings.siteUrl}/user/password/set?passwordResetToken=${
|
|
|
|
this.token
|
|
|
|
}&email=${encodeURIComponent(this.user.email)}`
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
})
|
2019-07-04 08:40:12 -04:00
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should return status == true', function() {
|
|
|
|
this.callback.calledWith(null, 'primary').should.equal(true)
|
2019-07-04 08:40:12 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
describe("when the email doesn't exist", function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
2019-06-14 12:31:46 -04:00
|
|
|
this.UserGetter.getUserByAnyEmail.yields(null, null)
|
|
|
|
this.PasswordResetHandler.generateAndEmailResetToken(
|
|
|
|
this.email,
|
|
|
|
this.callback
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should not set the password token data', function() {
|
|
|
|
this.OneTimeTokenHandler.getNewToken.called.should.equal(false)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should send an email with the token', function() {
|
|
|
|
this.EmailHandler.sendEmail.called.should.equal(false)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should return status == null', function() {
|
|
|
|
this.callback.calledWith(null, null).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2019-06-14 12:31:46 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
describe('when the email is a secondary email', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.UserGetter.getUserByAnyEmail.callsArgWith(1, null, this.user)
|
|
|
|
this.PasswordResetHandler.generateAndEmailResetToken(
|
|
|
|
'secondary@email.com',
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should not set the password token data', function() {
|
|
|
|
this.OneTimeTokenHandler.getNewToken.called.should.equal(false)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should not send an email with the token', function() {
|
|
|
|
this.EmailHandler.sendEmail.called.should.equal(false)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-06-14 12:31:46 -04:00
|
|
|
it('should return status == secondary', function() {
|
|
|
|
this.callback.calledWith(null, 'secondary').should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('setNewUserPassword', function() {
|
2020-08-13 09:42:28 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.auditLog = { ip: '0:0:0:0' }
|
|
|
|
})
|
2019-06-14 12:31:46 -04:00
|
|
|
describe('when no data is found', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.OneTimeTokenHandler.getValueFromTokenAndExpire.yields(null, null)
|
2020-08-13 09:42:28 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return found == false and reset == false', function() {
|
2019-07-04 08:40:12 -04:00
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.token,
|
|
|
|
this.password,
|
2020-08-13 09:42:28 -04:00
|
|
|
this.auditLog,
|
|
|
|
(error, result) => {
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
found: false,
|
|
|
|
reset: false,
|
|
|
|
userId: null
|
|
|
|
})
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-16 05:10:18 -04:00
|
|
|
describe('when the token has a user_id and email', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
2019-07-16 05:10:18 -04:00
|
|
|
this.OneTimeTokenHandler.getValueFromTokenAndExpire
|
|
|
|
.withArgs('password', this.token)
|
|
|
|
.yields(null, {
|
|
|
|
user_id: this.user._id,
|
|
|
|
email: this.email
|
|
|
|
})
|
2020-08-13 09:42:28 -04:00
|
|
|
this.AuthenticationManager.promises.setUserPassword
|
2020-10-22 04:11:43 -04:00
|
|
|
.withArgs(this.user, this.password)
|
2020-08-13 09:42:28 -04:00
|
|
|
.resolves(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-07-16 05:10:18 -04:00
|
|
|
describe('when no user is found with this email', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.UserGetter.getUserByMainEmail
|
|
|
|
.withArgs(this.email)
|
|
|
|
.yields(null, null)
|
|
|
|
})
|
|
|
|
|
2020-08-13 09:42:28 -04:00
|
|
|
it('should return found == false and reset == false', function(done) {
|
2019-07-16 05:10:18 -04:00
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
2020-08-13 09:42:28 -04:00
|
|
|
this.auditLog,
|
|
|
|
(err, result) => {
|
|
|
|
const { found, reset, userId } = result
|
|
|
|
expect(err).to.not.exist
|
2019-07-16 05:10:18 -04:00
|
|
|
expect(found).to.be.false
|
2020-08-13 09:42:28 -04:00
|
|
|
expect(reset).to.be.false
|
2019-07-16 05:10:18 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-07-16 05:10:18 -04:00
|
|
|
describe("when the email and user don't match", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.UserGetter.getUserByMainEmail
|
|
|
|
.withArgs(this.email)
|
|
|
|
.yields(null, { _id: 'not-the-same', email: this.email })
|
|
|
|
})
|
|
|
|
|
2020-08-13 09:42:28 -04:00
|
|
|
it('should return found == false and reset == false', function(done) {
|
2019-07-16 05:10:18 -04:00
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
2020-08-13 09:42:28 -04:00
|
|
|
this.auditLog,
|
|
|
|
(err, result) => {
|
|
|
|
const { found, reset, userId } = result
|
|
|
|
expect(err).to.not.exist
|
2019-07-16 05:10:18 -04:00
|
|
|
expect(found).to.be.false
|
2020-08-13 09:42:28 -04:00
|
|
|
expect(reset).to.be.false
|
2019-07-16 05:10:18 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the email and user match', function() {
|
2020-08-13 09:42:28 -04:00
|
|
|
describe('success', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.UserGetter.getUserByMainEmail.yields(null, this.user)
|
|
|
|
})
|
2019-07-16 05:10:18 -04:00
|
|
|
|
2020-08-13 09:42:28 -04:00
|
|
|
it('should update the user audit log', function(done) {
|
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
|
|
|
this.auditLog,
|
|
|
|
(error, result) => {
|
|
|
|
const { reset, userId } = result
|
|
|
|
expect(error).to.not.exist
|
|
|
|
const logCall = this.UserAuditLogHandler.promises.addEntry
|
|
|
|
.lastCall
|
|
|
|
expect(logCall.args[0]).to.equal(this.user_id)
|
|
|
|
expect(logCall.args[1]).to.equal('reset-password')
|
|
|
|
expect(logCall.args[2]).to.equal(undefined)
|
|
|
|
expect(logCall.args[3]).to.equal(this.auditLog.ip)
|
|
|
|
expect(logCall.args[4]).to.equal(undefined)
|
|
|
|
done()
|
2019-07-16 05:10:18 -04:00
|
|
|
}
|
2020-08-13 09:42:28 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return reset == true and the user id', function(done) {
|
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
|
|
|
this.auditLog,
|
|
|
|
(err, result) => {
|
|
|
|
const { reset, userId } = result
|
|
|
|
expect(err).to.not.exist
|
|
|
|
expect(reset).to.be.true
|
|
|
|
expect(userId).to.equal(this.user._id)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when logged in', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.auditLog.initiatorId = this.user_id
|
|
|
|
})
|
|
|
|
it('should update the user audit log with initiatorId', function(done) {
|
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
|
|
|
this.auditLog,
|
|
|
|
(error, result) => {
|
|
|
|
const { reset, userId } = result
|
|
|
|
expect(error).to.not.exist
|
|
|
|
const logCall = this.UserAuditLogHandler.promises.addEntry
|
|
|
|
.lastCall
|
|
|
|
expect(logCall.args[0]).to.equal(this.user_id)
|
|
|
|
expect(logCall.args[1]).to.equal('reset-password')
|
|
|
|
expect(logCall.args[2]).to.equal(this.user_id)
|
|
|
|
expect(logCall.args[3]).to.equal(this.auditLog.ip)
|
|
|
|
expect(logCall.args[4]).to.equal(undefined)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('errors', function() {
|
|
|
|
describe('via UserAuditLogHandler', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.PasswordResetHandler.promises.getUserForPasswordResetToken = sinon
|
|
|
|
.stub()
|
|
|
|
.withArgs(this.token)
|
|
|
|
.resolves(this.user)
|
|
|
|
this.UserAuditLogHandler.promises.addEntry.rejects(
|
|
|
|
new Error('oops')
|
|
|
|
)
|
|
|
|
})
|
2020-10-22 04:11:43 -04:00
|
|
|
it('should return the error', function(done) {
|
2020-08-13 09:42:28 -04:00
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
|
|
|
this.auditLog,
|
2020-10-22 04:11:43 -04:00
|
|
|
(error, _result) => {
|
2020-08-13 09:42:28 -04:00
|
|
|
expect(error).to.exist
|
|
|
|
expect(
|
|
|
|
this.UserAuditLogHandler.promises.addEntry.callCount
|
|
|
|
).to.equal(1)
|
|
|
|
expect(this.AuthenticationManager.promises.setUserPassword).to
|
2020-10-22 04:11:43 -04:00
|
|
|
.have.been.called
|
2020-08-13 09:42:28 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2019-07-16 05:10:18 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-16 05:10:18 -04:00
|
|
|
describe('when the token has a v1_user_id and email', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
2019-07-16 05:10:18 -04:00
|
|
|
this.user.overleaf = { id: 184 }
|
|
|
|
this.OneTimeTokenHandler.getValueFromTokenAndExpire
|
|
|
|
.withArgs('password', this.token)
|
|
|
|
.yields(null, {
|
|
|
|
v1_user_id: this.user.overleaf.id,
|
|
|
|
email: this.email
|
|
|
|
})
|
2020-08-13 09:42:28 -04:00
|
|
|
this.AuthenticationManager.promises.setUserPassword
|
2020-10-22 04:11:43 -04:00
|
|
|
.withArgs(this.user, this.password)
|
2020-08-13 09:42:28 -04:00
|
|
|
.resolves(true)
|
2019-07-16 05:10:18 -04:00
|
|
|
})
|
|
|
|
|
2020-08-13 09:42:28 -04:00
|
|
|
describe('when no user is reset with this email', function() {
|
2019-07-16 05:10:18 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.UserGetter.getUserByMainEmail
|
|
|
|
.withArgs(this.email)
|
|
|
|
.yields(null, null)
|
|
|
|
})
|
|
|
|
|
2020-08-13 09:42:28 -04:00
|
|
|
it('should return reset == false', function(done) {
|
2019-07-16 05:10:18 -04:00
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
2020-08-13 09:42:28 -04:00
|
|
|
this.auditLog,
|
|
|
|
(err, result) => {
|
|
|
|
const { reset, userId } = result
|
|
|
|
expect(err).to.not.exist
|
|
|
|
expect(reset).to.be.false
|
2019-07-16 05:10:18 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-16 05:10:18 -04:00
|
|
|
describe("when the email and user don't match", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.UserGetter.getUserByMainEmail.withArgs(this.email).yields(null, {
|
|
|
|
_id: this.user._id,
|
|
|
|
email: this.email,
|
|
|
|
overleaf: { id: 'not-the-same' }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-13 09:42:28 -04:00
|
|
|
it('should return reset == false', function(done) {
|
2019-07-16 05:10:18 -04:00
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
2020-08-13 09:42:28 -04:00
|
|
|
this.auditLog,
|
|
|
|
(err, result) => {
|
|
|
|
const { reset, userId } = result
|
|
|
|
expect(err).to.not.exist
|
|
|
|
expect(reset).to.be.false
|
2019-07-16 05:10:18 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-07-16 05:10:18 -04:00
|
|
|
describe('when the email and user match', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.UserGetter.getUserByMainEmail
|
|
|
|
.withArgs(this.email)
|
|
|
|
.yields(null, this.user)
|
|
|
|
})
|
|
|
|
|
2020-08-13 09:42:28 -04:00
|
|
|
it('should return reset == true and the user id', function(done) {
|
2019-07-16 05:10:18 -04:00
|
|
|
this.PasswordResetHandler.setNewUserPassword(
|
|
|
|
this.token,
|
|
|
|
this.password,
|
2020-08-13 09:42:28 -04:00
|
|
|
this.auditLog,
|
|
|
|
(err, result) => {
|
|
|
|
const { reset, userId } = result
|
|
|
|
expect(err).to.not.exist
|
|
|
|
expect(reset).to.be.true
|
2019-07-16 05:10:18 -04:00
|
|
|
expect(userId).to.equal(this.user._id)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|