mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 01:12:27 +00:00
put clsiCookie vals into subobject in settings
This commit is contained in:
parent
04e70735d2
commit
61b9a683aa
2 changed files with 12 additions and 11 deletions
|
@ -8,7 +8,7 @@ logger = require "logger-sharelatex"
|
|||
buildKey = (project_id)->
|
||||
return "clsiserver:#{project_id}"
|
||||
|
||||
clsiCookiesEnabled = Settings.clsiCookieKey? and Settings.clsiCookieKey.length != 0
|
||||
clsiCookiesEnabled = Settings.clsiCookie?.key? and Settings.clsiCookie.key.length != 0
|
||||
|
||||
|
||||
module.exports = ClsiCookieManager =
|
||||
|
@ -36,7 +36,7 @@ module.exports = ClsiCookieManager =
|
|||
|
||||
_parseServerIdFromResponse : (response)->
|
||||
cookies = Cookie.parse(response.headers["set-cookie"]?[0] or "")
|
||||
return cookies?[Settings.clsiCookieKey]
|
||||
return cookies?[Settings.clsiCookie.key]
|
||||
|
||||
setServerId: (project_id, response, callback = (err, serverId)->)->
|
||||
if !clsiCookiesEnabled
|
||||
|
@ -44,7 +44,7 @@ module.exports = ClsiCookieManager =
|
|||
serverId = ClsiCookieManager._parseServerIdFromResponse(response)
|
||||
multi = rclient.multi()
|
||||
multi.set buildKey(project_id), serverId
|
||||
multi.expire buildKey(project_id), Settings.clsi_cookie_expire_length_seconds
|
||||
multi.expire buildKey(project_id), Settings.clsiCookie.ttl
|
||||
multi.exec (err)->
|
||||
callback(err, serverId)
|
||||
|
||||
|
@ -56,7 +56,7 @@ module.exports = ClsiCookieManager =
|
|||
if err?
|
||||
logger.err err:err, project_id:project_id, "error getting server id"
|
||||
return callback(err)
|
||||
serverCookie = request.cookie("#{Settings.clsiCookieKey}=#{serverId}")
|
||||
serverCookie = request.cookie("#{Settings.clsiCookie.key}=#{serverId}")
|
||||
jar = request.jar()
|
||||
jar.setCookie serverCookie, Settings.apis.clsi.url
|
||||
callback(null, jar)
|
||||
|
|
|
@ -30,8 +30,9 @@ describe "ClsiCookieManager", ->
|
|||
apis:
|
||||
clsi:
|
||||
url: "http://clsi.example.com"
|
||||
clsi_cookie_expire_length_seconds: Math.random()
|
||||
clsiCookieKey: "coooookie"
|
||||
clsiCookie:
|
||||
ttl:Math.random()
|
||||
key: "coooookie"
|
||||
@requires =
|
||||
"redis-sharelatex" :
|
||||
createClient: =>
|
||||
|
@ -90,7 +91,7 @@ describe "ClsiCookieManager", ->
|
|||
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}", @settings.clsi_cookie_expire_length_seconds).should.equal true
|
||||
@redisMulti.expire.calledWith("clsiserver:#{@project_id}", @settings.clsiCookie.ttl).should.equal true
|
||||
done()
|
||||
|
||||
it "should return the server id", (done)->
|
||||
|
@ -100,7 +101,7 @@ describe "ClsiCookieManager", ->
|
|||
|
||||
|
||||
it "should not set the server id if clsiCookies are not enabled", (done)->
|
||||
delete @settings.clsiCookieKey
|
||||
delete @settings.clsiCookie.key
|
||||
@ClsiCookieManager = SandboxedModule.require modulePath, requires:@requires
|
||||
@ClsiCookieManager.setServerId @project_id, @response, (err, serverId)=>
|
||||
@redisMulti.exec.called.should.equal false
|
||||
|
@ -113,13 +114,13 @@ describe "ClsiCookieManager", ->
|
|||
|
||||
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"]["/"][@settings.clsiCookieKey].key.should.equal
|
||||
jar._jar.store.idx["clsi.example.com"]["/"][@settings.clsiCookieKey].value.should.equal "clsi-11"
|
||||
jar._jar.store.idx["clsi.example.com"]["/"][@settings.clsiCookie.key].key.should.equal
|
||||
jar._jar.store.idx["clsi.example.com"]["/"][@settings.clsiCookie.key].value.should.equal "clsi-11"
|
||||
done()
|
||||
|
||||
|
||||
it "should return empty cookie jar if clsiCookies are not enabled", (done)->
|
||||
delete @settings.clsiCookieKey
|
||||
delete @settings.clsiCookie.key
|
||||
@ClsiCookieManager = SandboxedModule.require modulePath, requires:@requires
|
||||
@ClsiCookieManager.getCookieJar @project_id, (err, jar)->
|
||||
assert.deepEqual jar, realRequst.jar()
|
||||
|
|
Loading…
Reference in a new issue