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

This commit is contained in:
Henry Oswald 2016-04-20 16:17:06 +01:00
parent 4d54de8b9a
commit 18560d8621
4 changed files with 50 additions and 8 deletions

View file

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

View file

@ -40,7 +40,11 @@ module.exports = ClsiManager =
logger.err err:err, "error getting cookie jar for clsi request" logger.err err:err, "error getting cookie jar for clsi request"
return callback(err) return callback(err)
opts.jar = jar 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) -> _getCompilerUrl: (compileGroup) ->

View file

@ -44,12 +44,6 @@ describe "ClsiCookieManager", ->
serverId.should.equal "clsi-7" serverId.should.equal "clsi-7"
done() 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)-> it "should _populateServerIdViaRequest if no key is found", (done)->
@ClsiCookieManager._populateServerIdViaRequest = sinon.stub().callsArgWith(1) @ClsiCookieManager._populateServerIdViaRequest = sinon.stub().callsArgWith(1)
@redisMulti.exec.callsArgWith(0, null, []) @redisMulti.exec.callsArgWith(0, null, [])

View file

@ -10,6 +10,7 @@ describe "ClsiManager", ->
@jar = {cookie:"stuff"} @jar = {cookie:"stuff"}
@ClsiCookieManager = @ClsiCookieManager =
getCookieJar: sinon.stub().callsArgWith(1, null, @jar) getCookieJar: sinon.stub().callsArgWith(1, null, @jar)
setServerId: sinon.stub().callsArgWith(2)
@ClsiManager = SandboxedModule.require modulePath, requires: @ClsiManager = SandboxedModule.require modulePath, requires:
"settings-sharelatex": @settings = "settings-sharelatex": @settings =
apis: apis:
@ -310,3 +311,47 @@ describe "ClsiManager", ->
@ClsiManager._makeRequest @ClsiManager._makeRequest
.calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex&image=#{encodeURIComponent(@image)}" }) .calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex&image=#{encodeURIComponent(@image)}" })
.should.equal true .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()