diff --git a/services/web/app/coffee/Features/PasswordReset/TokenGenerator.coffee b/services/web/app/coffee/Features/PasswordReset/TokenGenerator.coffee index d20bfa8b80..dd94e4b4a5 100644 --- a/services/web/app/coffee/Features/PasswordReset/TokenGenerator.coffee +++ b/services/web/app/coffee/Features/PasswordReset/TokenGenerator.coffee @@ -18,3 +18,9 @@ module.exports = callback(err, token) getUserIdFromToken: (token, callback)-> + multi = rclient.multi() + multi.get token + multi.del token + multi.exec (err, results)-> + callback err, results[0] + diff --git a/services/web/test/UnitTests/coffee/PasswordReset/TokenGeneratorTests.coffee b/services/web/test/UnitTests/coffee/PasswordReset/TokenGeneratorTests.coffee index 7c4b263fa2..39a5dd1733 100644 --- a/services/web/test/UnitTests/coffee/PasswordReset/TokenGeneratorTests.coffee +++ b/services/web/test/UnitTests/coffee/PasswordReset/TokenGeneratorTests.coffee @@ -17,6 +17,8 @@ describe "TokenGenerator", -> web:{} @redisMulti = set:sinon.stub() + get:sinon.stub() + del:sinon.stub() expire:sinon.stub() exec:sinon.stub() @uuid = v4 : -> return @stubbedToken @@ -46,3 +48,17 @@ describe "TokenGenerator", -> @TokenGenerator.getNewToken @user_id, (err, token)=> err.should.exist done() + + + describe "getUserIdFromToken", -> + + it "should get and delete the token", (done)-> + @redisMulti.exec.callsArgWith(0, null, [@user_id]) + @TokenGenerator.getUserIdFromToken @stubbedToken, (err, user_id)=> + user_id.should.equal @user_id + @redisMulti.get.calledWith(@stubbedToken).should.equal true + @redisMulti.del.calledWith(@stubbedToken).should.equal true + done() + + +