From b00bd5cd946b90c157d4e02b916798390ff879b1 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 27 Apr 2016 17:05:12 +0100 Subject: [PATCH] if clsi cookies are not enabled don't call redis, return empty --- .../Features/Compile/ClsiCookieManager.coffee | 7 ++-- .../Compile/ClsiCookieManagerTests.coffee | 42 +++++++++++++------ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee b/services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee index 3c2fe8a879..ad8c908cee 100644 --- a/services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee @@ -8,7 +8,6 @@ logger = require "logger-sharelatex" buildKey = (project_id)-> return "clsiserver:#{project_id}" - clsiCookiesEnabled = Settings.clsiCookieKey? and Settings.clsiCookieKey.length != 0 ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7 @@ -41,6 +40,8 @@ module.exports = ClsiCookieManager = return cookies?[Settings.clsiCookieKey] setServerId: (project_id, response, callback = (err, serverId)->)-> + if !clsiCookiesEnabled + return callback() serverId = ClsiCookieManager._parseServerIdFromResponse(response) multi = rclient.multi() multi.set buildKey(project_id), serverId @@ -50,8 +51,8 @@ module.exports = ClsiCookieManager = getCookieJar: (project_id, callback = (err, jar)->)-> - # if !clsiCookiesEnabled - # return callback(null, request.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 576024e10e..28dad51d8b 100644 --- a/services/web/test/UnitTests/coffee/Compile/ClsiCookieManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/ClsiCookieManagerTests.coffee @@ -1,5 +1,6 @@ sinon = require('sinon') chai = require('chai') +assert = chai.assert should = chai.should() expect = chai.expect modulePath = "../../../../app/js/Features/Compile/ClsiCookieManager.js" @@ -23,20 +24,22 @@ describe "ClsiCookieManager", -> get: sinon.stub() cookie:realRequst.cookie jar: realRequst.jar - @ClsiCookieManager = SandboxedModule.require modulePath, requires: + @settings = + redis: + web:"redis.something" + apis: + clsi: + url: "http://clsi.example.com" + clsiCookieKey: "coooookie" + @requires = "redis-sharelatex" : createClient: => @redis - "settings-sharelatex": @settings = - redis: - web:"redis.something" - apis: - clsi: - url: "http://clsi.example.com" - clsiCookieKey: "coooookie" + "settings-sharelatex": @settings "request": @request "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() } + @ClsiCookieManager = SandboxedModule.require modulePath, requires:@requires @@ -94,21 +97,36 @@ describe "ClsiCookieManager", -> serverId.should.equal "clsi-8" done() + + it "should not set the server id if clsiCookies are not enabled", (done)-> + delete @settings.clsiCookieKey + @ClsiCookieManager = SandboxedModule.require modulePath, requires:@requires + @ClsiCookieManager.setServerId @project_id, @response, (err, serverId)=> + @redisMulti.exec.called.should.equal false + done() + describe "getCookieJar", -> - it "should return a jar with the cookie set populated from redis", (done)-> + beforeEach -> @ClsiCookieManager._getServerId = sinon.stub().callsArgWith(1, null, "clsi-11") - opts = {} + + it "should return a jar with the cookie set populated from redis", (done)-> @ClsiCookieManager.getCookieJar @project_id, (err, jar)-> jar._jar.store.idx["clsi.example.com"]["/"].clsiserver.key.should.equal "clsiserver" jar._jar.store.idx["clsi.example.com"]["/"].clsiserver.value.should.equal "clsi-11" done() + it "should return empty cookie jar if clsiCookies are not enabled", (done)-> + delete @settings.clsiCookieKey + @ClsiCookieManager = SandboxedModule.require modulePath, requires:@requires + @ClsiCookieManager.getCookieJar @project_id, (err, jar)-> + assert.deepEqual jar, realRequst.jar() + done() + + - -