mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 01:05:50 +00:00
return server id for set server id and _populateServerIdViaRequest
This commit is contained in:
parent
616630200a
commit
1ee94f9bf5
2 changed files with 26 additions and 11 deletions
|
@ -32,21 +32,22 @@ module.exports = ClsiCookieManager =
|
|||
if err?
|
||||
logger.err err:err, project_id:project_id, "error getting initial server id for project"
|
||||
return callback(err)
|
||||
ClsiCookieManager.setServerId project_id, res, (err)->
|
||||
ClsiCookieManager.setServerId project_id, res, (err, serverId)->
|
||||
if err?
|
||||
logger.err err:err, project_id:project_id, "error setting server id via populate request"
|
||||
callback(err)
|
||||
callback(err, serverId)
|
||||
|
||||
_parseServerIdFromResponse : (response)->
|
||||
cookies = Cookie.parse(response.headers["set-cookie"]?[0] or "")
|
||||
return cookies?[Settings.clsiCookieKey]
|
||||
|
||||
setServerId: (project_id, response, callback = ->)->
|
||||
setServerId: (project_id, response, callback = (err, serverId)->)->
|
||||
serverId = ClsiCookieManager._parseServerIdFromResponse(response)
|
||||
multi = rclient.multi()
|
||||
multi.set buildKey(project_id), serverId
|
||||
multi.expire buildKey(project_id), ONE_WEEK_IN_SECONDS
|
||||
multi.exec callback
|
||||
multi.exec (err)->
|
||||
callback(err, serverId)
|
||||
|
||||
|
||||
getCookieJar: (project_id, callback = (err, jar)->)->
|
||||
|
|
|
@ -5,6 +5,7 @@ expect = chai.expect
|
|||
modulePath = "../../../../app/js/Features/Compile/ClsiCookieManager.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
realRequst = require("request")
|
||||
|
||||
describe "ClsiCookieManager", ->
|
||||
beforeEach ->
|
||||
@redisMulti =
|
||||
|
@ -54,27 +55,40 @@ describe "ClsiCookieManager", ->
|
|||
|
||||
describe "_populateServerIdViaRequest", ->
|
||||
|
||||
beforeEach ->
|
||||
@response = "some data"
|
||||
@request.get.callsArgWith(1, null, @response)
|
||||
@ClsiCookieManager.setServerId = sinon.stub().callsArgWith(2, null, "clsi-9")
|
||||
|
||||
it "should make a request to the clsi", (done)->
|
||||
response = "some data"
|
||||
@request.get.callsArgWith(1, null, response)
|
||||
@ClsiCookieManager.setServerId = sinon.stub().callsArgWith(2)
|
||||
@ClsiCookieManager._populateServerIdViaRequest @project_id, (err, serverId)=>
|
||||
args = @ClsiCookieManager.setServerId.args[0]
|
||||
args[0].should.equal @project_id
|
||||
args[1].should.deep.equal response
|
||||
args[1].should.deep.equal @response
|
||||
done()
|
||||
|
||||
it "should return the server id", (done)->
|
||||
@ClsiCookieManager._populateServerIdViaRequest @project_id, (err, serverId)=>
|
||||
serverId.should.equal "clsi-9"
|
||||
done()
|
||||
|
||||
describe "setServerId", ->
|
||||
|
||||
it "should set the server id with a ttl", (done)->
|
||||
beforeEach ->
|
||||
@response = "dsadsakj"
|
||||
@ClsiCookieManager._parseServerIdFromResponse = sinon.stub().returns("clsi-8")
|
||||
response = "dsadsakj"
|
||||
@redisMulti.exec.callsArgWith(0)
|
||||
@ClsiCookieManager.setServerId @project_id, response, (err)=>
|
||||
|
||||
it "should set the server id with a ttl", (done)->
|
||||
@ClsiCookieManager.setServerId @project_id, @response, (err)=>
|
||||
@redisMulti.set.calledWith("clsiserver:#{@project_id}", "clsi-8").should.equal true
|
||||
@redisMulti.expire.calledWith("clsiserver:#{@project_id}", 60 * 60 * 24 * 7).should.equal true
|
||||
done()
|
||||
|
||||
it "should return the server id", (done)->
|
||||
@ClsiCookieManager.setServerId @project_id, @response, (err, serverId)=>
|
||||
serverId.should.equal "clsi-8"
|
||||
done()
|
||||
|
||||
describe "getCookieJar", ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue