Просмотр исходного кода

if clsi cookies are not enabled don't call redis, return empty

Henry Oswald 10 лет назад
Родитель
Сommit
b00bd5cd94

+ 4 - 3
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"

+ 28 - 10
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,17 +97,32 @@ 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()