mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 12:14:05 -05:00
redis get not multi used for _getServerId
This commit is contained in:
parent
1ee94f9bf5
commit
78b08060ab
2 changed files with 15 additions and 10 deletions
|
@ -9,17 +9,16 @@ buildKey = (project_id)->
|
|||
return "clsiserver:#{project_id}"
|
||||
|
||||
|
||||
clsiCookiesEnabled = Settings.clsiCookieKey? and Settings.clsiCookieKey.length != 0
|
||||
|
||||
ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7
|
||||
|
||||
module.exports = ClsiCookieManager =
|
||||
|
||||
_getServerId : (project_id, callback = (err, serverId)->)->
|
||||
multi = rclient.multi()
|
||||
multi.get buildKey(project_id)
|
||||
multi.exec (err, results)->
|
||||
rclient.get buildKey(project_id), (err, serverId)->
|
||||
if err?
|
||||
return callback(err)
|
||||
serverId = results[0]
|
||||
if serverId?
|
||||
return callback(null, serverId)
|
||||
else
|
||||
|
@ -51,6 +50,8 @@ module.exports = ClsiCookieManager =
|
|||
|
||||
|
||||
getCookieJar: (project_id, callback = (err, jar)->)->
|
||||
# if !clsiCookiesEnabled
|
||||
# return callback(null, request.jar())
|
||||
ClsiCookieManager._getServerId project_id, (err, serverId)=>
|
||||
if err?
|
||||
logger.err err:err, project_id:project_id, "error getting server id"
|
||||
|
|
|
@ -8,12 +8,16 @@ realRequst = require("request")
|
|||
|
||||
describe "ClsiCookieManager", ->
|
||||
beforeEach ->
|
||||
self = @
|
||||
@redisMulti =
|
||||
set:sinon.stub()
|
||||
get:sinon.stub()
|
||||
expire:sinon.stub()
|
||||
exec:sinon.stub()
|
||||
self = @
|
||||
@redis =
|
||||
auth:->
|
||||
get:sinon.stub()
|
||||
multi: -> return self.redisMulti
|
||||
@project_id = "123423431321"
|
||||
@request =
|
||||
get: sinon.stub()
|
||||
|
@ -22,14 +26,14 @@ describe "ClsiCookieManager", ->
|
|||
@ClsiCookieManager = SandboxedModule.require modulePath, requires:
|
||||
"redis-sharelatex" :
|
||||
createClient: =>
|
||||
auth:->
|
||||
multi: -> return self.redisMulti
|
||||
@redis
|
||||
"settings-sharelatex": @settings =
|
||||
redis:
|
||||
web:"redis.something"
|
||||
apis:
|
||||
clsi:
|
||||
url: "http://clsi.example.com"
|
||||
clsiCookieKey: "coooookie"
|
||||
"request": @request
|
||||
|
||||
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() }
|
||||
|
@ -39,15 +43,15 @@ describe "ClsiCookieManager", ->
|
|||
describe "getServerId", ->
|
||||
|
||||
it "should call get for the key", (done)->
|
||||
@redisMulti.exec.callsArgWith(0, null, ["clsi-7"])
|
||||
@redis.get.callsArgWith(1, null, "clsi-7")
|
||||
@ClsiCookieManager._getServerId @project_id, (err, serverId)=>
|
||||
@redisMulti.get.calledWith("clsiserver:#{@project_id}").should.equal true
|
||||
@redis.get.calledWith("clsiserver:#{@project_id}").should.equal true
|
||||
serverId.should.equal "clsi-7"
|
||||
done()
|
||||
|
||||
it "should _populateServerIdViaRequest if no key is found", (done)->
|
||||
@ClsiCookieManager._populateServerIdViaRequest = sinon.stub().callsArgWith(1)
|
||||
@redisMulti.exec.callsArgWith(0, null, [])
|
||||
@redis.get.callsArgWith(1, null)
|
||||
@ClsiCookieManager._getServerId @project_id, (err, serverId)=>
|
||||
@ClsiCookieManager._populateServerIdViaRequest.calledWith(@project_id).should.equal true
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue