Browse Source

set server cookie on every compile response and don't expire on get

Henry Oswald 10 năm trước cách đây
mục cha
commit
18560d8621

+ 0 - 1
services/web/app/coffee/Features/Compile/ClsiCookieManager.coffee

@@ -16,7 +16,6 @@ module.exports = ClsiCookieManager =
 	_getServerId : (project_id, callback = (err, serverId)->)->
 		multi = rclient.multi()
 		multi.get buildKey(project_id)
-		multi.expire buildKey(project_id), ONE_WEEK_IN_SECONDS
 		multi.exec (err, results)->
 			if err?
 				return callback(err)

+ 5 - 1
services/web/app/coffee/Features/Compile/ClsiManager.coffee

@@ -40,7 +40,11 @@ module.exports = ClsiManager =
 				logger.err err:err, "error getting cookie jar for clsi request"
 				return callback(err)
 			opts.jar = jar
-			request opts, callback
+			request opts, (err, response, body)->
+				if err?
+					logger.err err:err, project_id:project_id, url:opts?.url, "error making request to clsi"
+					return callback(err)
+				ClsiCookieManager.setServerId project_id, response, callback
 
 
 	_getCompilerUrl: (compileGroup) ->

+ 0 - 6
services/web/test/UnitTests/coffee/Compile/ClsiCookieManagerTests.coffee

@@ -44,12 +44,6 @@ describe "ClsiCookieManager", ->
 				serverId.should.equal "clsi-7"
 				done()
 
-		it "should expire the key", (done)->
-			@redisMulti.exec.callsArgWith(0, null, ["clsi-7"])
-			@ClsiCookieManager._getServerId @project_id, (err, serverId)=>
-				@redisMulti.expire.calledWith("clsiserver:#{@project_id}", 60 * 60 * 24 * 7).should.equal true
-				done()
-
 		it "should _populateServerIdViaRequest if no key is found", (done)->
 			@ClsiCookieManager._populateServerIdViaRequest = sinon.stub().callsArgWith(1)
 			@redisMulti.exec.callsArgWith(0, null, [])

+ 45 - 0
services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee

@@ -10,6 +10,7 @@ describe "ClsiManager", ->
 		@jar = {cookie:"stuff"}
 		@ClsiCookieManager = 
 			getCookieJar: sinon.stub().callsArgWith(1, null, @jar)
+			setServerId: sinon.stub().callsArgWith(2)
 		@ClsiManager = SandboxedModule.require modulePath, requires:
 			"settings-sharelatex": @settings =
 				apis:
@@ -310,3 +311,47 @@ describe "ClsiManager", ->
 				@ClsiManager._makeRequest
 					.calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex&image=#{encodeURIComponent(@image)}" })
 					.should.equal true
+
+
+
+	describe "_makeRequest", ->
+
+		beforeEach ->
+			@response = {there:"something"}
+			@request.callsArgWith(1, null, @response)
+			@opts = 
+				method: "SOMETHIGN"
+				url: "http://a place on the web"
+
+		it "should process a request with a cookie jar", (done)->
+			@ClsiManager._makeRequest @project_id, @opts, =>
+				args = @request.args[0]
+				args[0].method.should.equal @opts.method
+				args[0].url.should.equal @opts.url
+				args[0].jar.should.equal @jar
+				done()
+
+		it "should set the cookie again on response as it might have changed", (done)->
+			@ClsiManager._makeRequest @project_id, @opts, =>
+				@ClsiCookieManager.setServerId.calledWith(@project_id, @response).should.equal true
+				done()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+