diff --git a/services/web/app/src/Features/Security/OneTimeTokenHandler.js b/services/web/app/src/Features/Security/OneTimeTokenHandler.js index 29e3f279ff..ef49c68059 100644 --- a/services/web/app/src/Features/Security/OneTimeTokenHandler.js +++ b/services/web/app/src/Features/Security/OneTimeTokenHandler.js @@ -7,7 +7,7 @@ const { callbackify } = require('util') const ONE_HOUR_IN_S = 60 * 60 async function peekValueFromToken(use, token) { - const result = await db.tokens.findOneAndUpdate( + const tokenDoc = await db.tokens.findOneAndUpdate( { use, token, @@ -22,8 +22,6 @@ async function peekValueFromToken(use, token) { returnDocument: 'after', } ) - - const tokenDoc = result.value if (!tokenDoc) { throw new Errors.NotFoundError('no token found') } @@ -82,11 +80,10 @@ const OneTimeTokenHandler = { usedAt: now, }, }, - function (error, result) { + function (error, token) { if (error) { return callback(error) } - const token = result.value if (!token) { return callback(new Errors.NotFoundError('no token found')) } diff --git a/services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js b/services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js index f9cc1c7aeb..70203691aa 100644 --- a/services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js +++ b/services/web/test/unit/src/Security/OneTimeTokenHandlerTests.js @@ -97,7 +97,7 @@ describe('OneTimeTokenHandler', function () { beforeEach(async function () { this.db.tokens.findOneAndUpdate = sinon .stub() - .resolves({ value: { data, peekCount: 1 } }) + .resolves({ data, peekCount: 1 }) result = await this.OneTimeTokenHandler.promises.peekValueFromToken( 'password', 'mock-token' @@ -128,7 +128,7 @@ describe('OneTimeTokenHandler', function () { describe('when a valid token is not found', function () { beforeEach(function () { - this.db.tokens.findOneAndUpdate = sinon.stub().resolves({ value: null }) + this.db.tokens.findOneAndUpdate = sinon.stub().resolves(null) }) it('should return a NotFoundError', async function () { @@ -175,7 +175,7 @@ describe('OneTimeTokenHandler', function () { beforeEach(function () { this.db.tokens.findOneAndUpdate = sinon .stub() - .yields(null, { value: { data: 'mock-data' } }) + .yields(null, { data: 'mock-data' }) this.OneTimeTokenHandler.getValueFromTokenAndExpire( 'password', 'mock-token', @@ -207,9 +207,7 @@ describe('OneTimeTokenHandler', function () { describe('when a valid token is not found', function () { beforeEach(function () { - this.db.tokens.findOneAndUpdate = sinon - .stub() - .yields(null, { value: null }) + this.db.tokens.findOneAndUpdate = sinon.stub().yields(null, null) this.OneTimeTokenHandler.getValueFromTokenAndExpire( 'password', 'mock-token',