redis get not multi used for _getServerId

This commit is contained in:
Henry Oswald 2016-04-27 16:56:21 +01:00
parent 1ee94f9bf5
commit 78b08060ab
2 changed files with 15 additions and 10 deletions

View file

@ -9,17 +9,16 @@ buildKey = (project_id)->
return "clsiserver:#{project_id}" return "clsiserver:#{project_id}"
clsiCookiesEnabled = Settings.clsiCookieKey? and Settings.clsiCookieKey.length != 0
ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7 ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7
module.exports = ClsiCookieManager = module.exports = ClsiCookieManager =
_getServerId : (project_id, callback = (err, serverId)->)-> _getServerId : (project_id, callback = (err, serverId)->)->
multi = rclient.multi() rclient.get buildKey(project_id), (err, serverId)->
multi.get buildKey(project_id)
multi.exec (err, results)->
if err? if err?
return callback(err) return callback(err)
serverId = results[0]
if serverId? if serverId?
return callback(null, serverId) return callback(null, serverId)
else else
@ -51,6 +50,8 @@ module.exports = ClsiCookieManager =
getCookieJar: (project_id, callback = (err, jar)->)-> getCookieJar: (project_id, callback = (err, jar)->)->
# if !clsiCookiesEnabled
# return callback(null, request.jar())
ClsiCookieManager._getServerId project_id, (err, serverId)=> ClsiCookieManager._getServerId project_id, (err, serverId)=>
if err? if err?
logger.err err:err, project_id:project_id, "error getting server id" logger.err err:err, project_id:project_id, "error getting server id"

View file

@ -8,12 +8,16 @@ realRequst = require("request")
describe "ClsiCookieManager", -> describe "ClsiCookieManager", ->
beforeEach -> beforeEach ->
self = @
@redisMulti = @redisMulti =
set:sinon.stub() set:sinon.stub()
get:sinon.stub() get:sinon.stub()
expire:sinon.stub() expire:sinon.stub()
exec:sinon.stub() exec:sinon.stub()
self = @ @redis =
auth:->
get:sinon.stub()
multi: -> return self.redisMulti
@project_id = "123423431321" @project_id = "123423431321"
@request = @request =
get: sinon.stub() get: sinon.stub()
@ -22,14 +26,14 @@ describe "ClsiCookieManager", ->
@ClsiCookieManager = SandboxedModule.require modulePath, requires: @ClsiCookieManager = SandboxedModule.require modulePath, requires:
"redis-sharelatex" : "redis-sharelatex" :
createClient: => createClient: =>
auth:-> @redis
multi: -> return self.redisMulti
"settings-sharelatex": @settings = "settings-sharelatex": @settings =
redis: redis:
web:"redis.something" web:"redis.something"
apis: apis:
clsi: clsi:
url: "http://clsi.example.com" url: "http://clsi.example.com"
clsiCookieKey: "coooookie"
"request": @request "request": @request
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() } "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() }
@ -39,15 +43,15 @@ describe "ClsiCookieManager", ->
describe "getServerId", -> describe "getServerId", ->
it "should call get for the key", (done)-> 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)=> @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" serverId.should.equal "clsi-7"
done() 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, []) @redis.get.callsArgWith(1, null)
@ClsiCookieManager._getServerId @project_id, (err, serverId)=> @ClsiCookieManager._getServerId @project_id, (err, serverId)=>
@ClsiCookieManager._populateServerIdViaRequest.calledWith(@project_id).should.equal true @ClsiCookieManager._populateServerIdViaRequest.calledWith(@project_id).should.equal true
done() done()