mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
set server cookie on every compile response and don't expire on get
This commit is contained in:
parent
4d54de8b9a
commit
18560d8621
4 changed files with 50 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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) ->
|
||||
|
|
|
@ -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, [])
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue