From 78b08060abf457c359eaf96c35005bf1bf091ecd Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 27 Apr 2016 16:56:21 +0100 Subject: [PATCH] redis get not multi used for _getServerId --- .../Features/Compile/ClsiCookieManager.coffee | 9 +++++---- .../coffee/Compile/ClsiCookieManagerTests.coffee | 16 ++++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee b/services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee index ff42eb8820..3c2fe8a879 100644 --- a/services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee @@ -9,17 +9,16 @@ buildKey = (project_id)-> return "clsiserver:#{project_id}" +clsiCookiesEnabled = Settings.clsiCookieKey? and Settings.clsiCookieKey.length != 0 + ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7 module.exports = ClsiCookieManager = _getServerId : (project_id, callback = (err, serverId)->)-> - multi = rclient.multi() - multi.get buildKey(project_id) - multi.exec (err, results)-> + rclient.get buildKey(project_id), (err, serverId)-> if err? return callback(err) - serverId = results[0] if serverId? return callback(null, serverId) else @@ -51,6 +50,8 @@ module.exports = ClsiCookieManager = getCookieJar: (project_id, callback = (err, jar)->)-> + # if !clsiCookiesEnabled + # return callback(null, request.jar()) ClsiCookieManager._getServerId project_id, (err, serverId)=> if err? logger.err err:err, project_id:project_id, "error getting server id" diff --git a/services/web/test/UnitTests/coffee/Compile/ClsiCookieManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/ClsiCookieManagerTests.coffee index e4013ff06e..576024e10e 100644 --- a/services/web/test/UnitTests/coffee/Compile/ClsiCookieManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/ClsiCookieManagerTests.coffee @@ -8,12 +8,16 @@ realRequst = require("request") describe "ClsiCookieManager", -> beforeEach -> + self = @ @redisMulti = set:sinon.stub() get:sinon.stub() expire:sinon.stub() exec:sinon.stub() - self = @ + @redis = + auth:-> + get:sinon.stub() + multi: -> return self.redisMulti @project_id = "123423431321" @request = get: sinon.stub() @@ -22,14 +26,14 @@ describe "ClsiCookieManager", -> @ClsiCookieManager = SandboxedModule.require modulePath, requires: "redis-sharelatex" : createClient: => - auth:-> - multi: -> return self.redisMulti + @redis "settings-sharelatex": @settings = redis: web:"redis.something" apis: clsi: url: "http://clsi.example.com" + clsiCookieKey: "coooookie" "request": @request "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() } @@ -39,15 +43,15 @@ describe "ClsiCookieManager", -> describe "getServerId", -> it "should call get for the key", (done)-> - @redisMulti.exec.callsArgWith(0, null, ["clsi-7"]) + @redis.get.callsArgWith(1, null, "clsi-7") @ClsiCookieManager._getServerId @project_id, (err, serverId)=> - @redisMulti.get.calledWith("clsiserver:#{@project_id}").should.equal true + @redis.get.calledWith("clsiserver:#{@project_id}").should.equal true serverId.should.equal "clsi-7" done() it "should _populateServerIdViaRequest if no key is found", (done)-> @ClsiCookieManager._populateServerIdViaRequest = sinon.stub().callsArgWith(1) - @redisMulti.exec.callsArgWith(0, null, []) + @redis.get.callsArgWith(1, null) @ClsiCookieManager._getServerId @project_id, (err, serverId)=> @ClsiCookieManager._populateServerIdViaRequest.calledWith(@project_id).should.equal true done()