Merge pull request #4840 from overleaf/revert-4736-ho-clsi-user-id-mapping-minimal

Revert "Clsi user id mapping (mono repo)"

GitOrigin-RevId: 046bf21f1ab90f375d3945d8baa22600d8cdbf2b
This commit is contained in:
Jakob Ackermann 2021-08-20 13:00:03 +02:00 committed by Copybot
parent 9c86e14462
commit 8bbf6fb52c
6 changed files with 99 additions and 163 deletions

View file

@ -29,50 +29,43 @@ const clsiCookiesEnabled =
module.exports = function (backendGroup) { module.exports = function (backendGroup) {
return { return {
buildKey(project_id, user_id) { buildKey(project_id) {
if (backendGroup != null) { if (backendGroup != null) {
return `clsiserver:${backendGroup}:${project_id}:${user_id}` return `clsiserver:${backendGroup}:${project_id}`
} else { } else {
return `clsiserver:${project_id}:${user_id}` return `clsiserver:${project_id}`
} }
}, },
_getServerId(project_id, user_id, callback) { _getServerId(project_id, callback) {
if (callback == null) { if (callback == null) {
callback = function (err, serverId) {} callback = function (err, serverId) {}
} }
return rclient.get( return rclient.get(this.buildKey(project_id), (err, serverId) => {
this.buildKey(project_id, user_id), if (err != null) {
(err, serverId) => { return callback(err)
if (err != null) {
return callback(err)
}
if (serverId == null || serverId === '') {
return this._populateServerIdViaRequest(
project_id,
user_id,
callback
)
} else {
return callback(null, serverId)
}
} }
) if (serverId == null || serverId === '') {
return this._populateServerIdViaRequest(project_id, callback)
} else {
return callback(null, serverId)
}
})
}, },
_populateServerIdViaRequest(project_id, user_id, callback) { _populateServerIdViaRequest(project_id, callback) {
if (callback == null) { if (callback == null) {
callback = function (err, serverId) {} callback = function (err, serverId) {}
} }
const url = `${Settings.apis.clsi.url}/project/${project_id}/status` const url = `${Settings.apis.clsi.url}/project/${project_id}/status`
request.post(url, (err, res, body) => { return request.post(url, (err, res, body) => {
if (err != null) { if (err != null) {
OError.tag(err, 'error getting initial server id for project', { OError.tag(err, 'error getting initial server id for project', {
project_id, project_id,
}) })
return callback(err) return callback(err)
} }
this.setServerId(project_id, user_id, res, function (err, serverId) { return this.setServerId(project_id, res, function (err, serverId) {
if (err != null) { if (err != null) {
logger.warn( logger.warn(
{ err, project_id }, { err, project_id },
@ -93,7 +86,7 @@ module.exports = function (backendGroup) {
return cookies != null ? cookies[Settings.clsiCookie.key] : undefined return cookies != null ? cookies[Settings.clsiCookie.key] : undefined
}, },
setServerId(project_id, user_id, response, callback) { setServerId(project_id, response, callback) {
if (callback == null) { if (callback == null) {
callback = function (err, serverId) {} callback = function (err, serverId) {}
} }
@ -103,55 +96,50 @@ module.exports = function (backendGroup) {
const serverId = this._parseServerIdFromResponse(response) const serverId = this._parseServerIdFromResponse(response)
if (serverId == null) { if (serverId == null) {
// We don't get a cookie back if it hasn't changed // We don't get a cookie back if it hasn't changed
rclient.expire( return rclient.expire(
this.buildKey(project_id, user_id), this.buildKey(project_id),
Settings.clsiCookie.ttl, Settings.clsiCookie.ttl,
err => callback(err, undefined) err => callback(err, undefined)
) )
} }
if (rclient_secondary != null) { if (rclient_secondary != null) {
this._setServerIdInRedis( this._setServerIdInRedis(rclient_secondary, project_id, serverId)
rclient_secondary,
project_id,
user_id,
serverId
)
} }
this._setServerIdInRedis(rclient, project_id, user_id, serverId, err => return this._setServerIdInRedis(rclient, project_id, serverId, err =>
callback(err, serverId) callback(err, serverId)
) )
}, },
_setServerIdInRedis(rclient, project_id, user_id, serverId, callback) { _setServerIdInRedis(rclient, project_id, serverId, callback) {
if (callback == null) { if (callback == null) {
callback = function (err) {} callback = function (err) {}
} }
rclient.setex( rclient.setex(
this.buildKey(project_id, user_id), this.buildKey(project_id),
Settings.clsiCookie.ttl, Settings.clsiCookie.ttl,
serverId, serverId,
callback callback
) )
}, },
clearServerId(project_id, user_id, callback) { clearServerId(project_id, callback) {
if (callback == null) { if (callback == null) {
callback = function (err) {} callback = function (err) {}
} }
if (!clsiCookiesEnabled) { if (!clsiCookiesEnabled) {
return callback() return callback()
} }
return rclient.del(this.buildKey(project_id, user_id), callback) return rclient.del(this.buildKey(project_id), callback)
}, },
getCookieJar(project_id, user_id, callback) { getCookieJar(project_id, callback) {
if (callback == null) { if (callback == null) {
callback = function (err, jar, clsiServerId) {} callback = function (err, jar, clsiServerId) {}
} }
if (!clsiCookiesEnabled) { if (!clsiCookiesEnabled) {
return callback(null, request.jar(), undefined) return callback(null, request.jar(), undefined)
} }
return this._getServerId(project_id, user_id, (err, serverId) => { return this._getServerId(project_id, (err, serverId) => {
if (err != null) { if (err != null) {
OError.tag(err, 'error getting server id', { OError.tag(err, 'error getting server id', {
project_id, project_id,

View file

@ -132,7 +132,7 @@ const ClsiManager = {
url: compilerUrl, url: compilerUrl,
method: 'POST', method: 'POST',
} }
ClsiManager._makeRequest(projectId, userId, opts, callback) ClsiManager._makeRequest(projectId, opts, callback)
}, },
deleteAuxFiles(projectId, userId, options, clsiserverid, callback) { deleteAuxFiles(projectId, userId, options, clsiserverid, callback) {
@ -150,14 +150,13 @@ const ClsiManager = {
} }
ClsiManager._makeRequestWithClsiServerId( ClsiManager._makeRequestWithClsiServerId(
projectId, projectId,
userId,
opts, opts,
clsiserverid, clsiserverid,
clsiErr => { clsiErr => {
// always clear the project state from the docupdater, even if there // always clear the project state from the docupdater, even if there
// was a problem with the request to the clsi // was a problem with the request to the clsi
DocumentUpdaterHandler.clearProjectState(projectId, docUpdaterErr => { DocumentUpdaterHandler.clearProjectState(projectId, docUpdaterErr => {
ClsiCookieManager.clearServerId(projectId, userId, redisError => { ClsiCookieManager.clearServerId(projectId, redisError => {
if (clsiErr) { if (clsiErr) {
return callback( return callback(
OError.tag(clsiErr, 'Failed to delete aux files', { projectId }) OError.tag(clsiErr, 'Failed to delete aux files', { projectId })
@ -195,7 +194,7 @@ const ClsiManager = {
} }
if (options.forceNewClsiServer) { if (options.forceNewClsiServer) {
// Clear clsi cookie, then try again // Clear clsi cookie, then try again
return ClsiCookieManager.clearServerId(projectId, userId, err => { return ClsiCookieManager.clearServerId(projectId, err => {
if (err) { if (err) {
return callback(err) return callback(err)
} }
@ -271,13 +270,7 @@ const ClsiManager = {
) )
}, },
_makeRequestWithClsiServerId( _makeRequestWithClsiServerId(projectId, opts, clsiserverid, callback) {
projectId,
userId,
opts,
clsiserverid,
callback
) {
if (clsiserverid) { if (clsiserverid) {
// ignore cookies and newBackend, go straight to the clsi node // ignore cookies and newBackend, go straight to the clsi node
opts.qs = Object.assign({ clsiserverid }, opts.qs) opts.qs = Object.assign({ clsiserverid }, opts.qs)
@ -290,18 +283,17 @@ const ClsiManager = {
callback(null, response, body) callback(null, response, body)
}) })
} else { } else {
ClsiManager._makeRequest(projectId, userId, opts, callback) ClsiManager._makeRequest(projectId, opts, callback)
} }
}, },
_makeRequest(projectId, userId, opts, callback) { _makeRequest(projectId, opts, callback) {
async.series( async.series(
{ {
currentBackend(cb) { currentBackend(cb) {
const startTime = new Date() const startTime = new Date()
ClsiCookieManager.getCookieJar( ClsiCookieManager.getCookieJar(
projectId, projectId,
userId,
(err, jar, clsiServerId) => { (err, jar, clsiServerId) => {
if (err != null) { if (err != null) {
return callback( return callback(
@ -326,7 +318,6 @@ const ClsiManager = {
) )
ClsiCookieManager.setServerId( ClsiCookieManager.setServerId(
projectId, projectId,
userId,
response, response,
(err, newClsiServerId) => { (err, newClsiServerId) => {
if (err != null) { if (err != null) {
@ -359,7 +350,6 @@ const ClsiManager = {
const startTime = new Date() const startTime = new Date()
ClsiManager._makeNewBackendRequest( ClsiManager._makeNewBackendRequest(
projectId, projectId,
userId,
opts, opts,
(err, response, body) => { (err, response, body) => {
if (err != null) { if (err != null) {
@ -406,7 +396,7 @@ const ClsiManager = {
) )
}, },
_makeNewBackendRequest(projectId, userId, baseOpts, callback) { _makeNewBackendRequest(projectId, baseOpts, callback) {
if (Settings.apis.clsi_new == null || Settings.apis.clsi_new.url == null) { if (Settings.apis.clsi_new == null || Settings.apis.clsi_new.url == null) {
return callback() return callback()
} }
@ -417,47 +407,42 @@ const ClsiManager = {
Settings.apis.clsi_new.url Settings.apis.clsi_new.url
), ),
} }
NewBackendCloudClsiCookieManager.getCookieJar( NewBackendCloudClsiCookieManager.getCookieJar(projectId, (err, jar) => {
projectId, if (err != null) {
userId, return callback(
(err, jar) => { OError.tag(err, 'error getting cookie jar for CLSI request', {
projectId,
})
)
}
opts.jar = jar
const timer = new Metrics.Timer('compile.newBackend')
request(opts, (err, response, body) => {
timer.done()
if (err != null) { if (err != null) {
return callback( return callback(
OError.tag(err, 'error getting cookie jar for CLSI request', { OError.tag(err, 'error making request to new CLSI', {
projectId, projectId,
opts,
}) })
) )
} }
opts.jar = jar NewBackendCloudClsiCookieManager.setServerId(
const timer = new Metrics.Timer('compile.newBackend') projectId,
request(opts, (err, response, body) => { response,
timer.done() err => {
if (err != null) { if (err != null) {
return callback( return callback(
OError.tag(err, 'error making request to new CLSI', { OError.tag(err, 'error setting server id on new backend', {
projectId, projectId,
opts, })
}) )
)
}
NewBackendCloudClsiCookieManager.setServerId(
projectId,
userId,
response,
err => {
if (err != null) {
return callback(
OError.tag(err, 'error setting server id on new backend', {
projectId,
})
)
}
callback(null, response, body)
} }
) callback(null, response, body)
}) }
} )
) })
})
}, },
_getCompilerUrl(compileGroup, projectId, userId, action) { _getCompilerUrl(compileGroup, projectId, userId, action) {
@ -486,7 +471,6 @@ const ClsiManager = {
} }
ClsiManager._makeRequest( ClsiManager._makeRequest(
projectId, projectId,
userId,
opts, opts,
(err, response, body, clsiServerId) => { (err, response, body, clsiServerId) => {
if (err != null) { if (err != null) {
@ -661,7 +645,7 @@ const ClsiManager = {
getOutputFileStream(projectId, userId, buildId, outputFilePath, callback) { getOutputFileStream(projectId, userId, buildId, outputFilePath, callback) {
const url = `${Settings.apis.clsi.url}/project/${projectId}/user/${userId}/build/${buildId}/output/${outputFilePath}` const url = `${Settings.apis.clsi.url}/project/${projectId}/user/${userId}/build/${buildId}/output/${outputFilePath}`
ClsiCookieManager.getCookieJar(projectId, userId, (err, jar) => { ClsiCookieManager.getCookieJar(projectId, (err, jar) => {
if (err != null) { if (err != null) {
return callback( return callback(
OError.tag(err, 'Failed to get cookie jar', { OError.tag(err, 'Failed to get cookie jar', {
@ -892,7 +876,6 @@ const ClsiManager = {
} }
ClsiManager._makeRequestWithClsiServerId( ClsiManager._makeRequestWithClsiServerId(
projectId, projectId,
userId,
opts, opts,
clsiserverid, clsiserverid,
(err, response, body) => { (err, response, body) => {

View file

@ -572,11 +572,10 @@ module.exports = CompileController = {
function _getPersistenceOptions(req, projectId, callback) { function _getPersistenceOptions(req, projectId, callback) {
const { clsiserverid } = req.query const { clsiserverid } = req.query
const user_id = SessionManager.getLoggedInUserId(req)
if (clsiserverid && typeof clsiserverid === 'string') { if (clsiserverid && typeof clsiserverid === 'string') {
callback(null, { qs: { clsiserverid } }) callback(null, { qs: { clsiserverid } })
} else { } else {
ClsiCookieManager.getCookieJar(projectId, user_id, (err, jar) => { ClsiCookieManager.getCookieJar(projectId, (err, jar) => {
callback(err, { jar }) callback(err, { jar })
}) })
} }

View file

@ -25,8 +25,7 @@ describe('ClsiCookieManager', function () {
get: sinon.stub(), get: sinon.stub(),
setex: sinon.stub().callsArg(3), setex: sinon.stub().callsArg(3),
} }
this.project_id = '123423431321-proj-id' this.project_id = '123423431321'
this.user_id = 'abc-user-id'
this.request = { this.request = {
post: sinon.stub(), post: sinon.stub(),
cookie: realRequst.cookie, cookie: realRequst.cookie,
@ -66,10 +65,9 @@ describe('ClsiCookieManager', function () {
this.redis.get.callsArgWith(1, null, 'clsi-7') this.redis.get.callsArgWith(1, null, 'clsi-7')
return this.ClsiCookieManager._getServerId( return this.ClsiCookieManager._getServerId(
this.project_id, this.project_id,
this.user_id,
(err, serverId) => { (err, serverId) => {
this.redis.get this.redis.get
.calledWith(`clsiserver:${this.project_id}:${this.user_id}`) .calledWith(`clsiserver:${this.project_id}`)
.should.equal(true) .should.equal(true)
serverId.should.equal('clsi-7') serverId.should.equal('clsi-7')
return done() return done()
@ -80,14 +78,13 @@ describe('ClsiCookieManager', function () {
it('should _populateServerIdViaRequest if no key is found', function (done) { it('should _populateServerIdViaRequest if no key is found', function (done) {
this.ClsiCookieManager._populateServerIdViaRequest = sinon this.ClsiCookieManager._populateServerIdViaRequest = sinon
.stub() .stub()
.callsArgWith(2) .callsArgWith(1)
this.redis.get.callsArgWith(1, null) this.redis.get.callsArgWith(1, null)
return this.ClsiCookieManager._getServerId( return this.ClsiCookieManager._getServerId(
this.project_id, this.project_id,
this.user_id,
(err, serverId) => { (err, serverId) => {
this.ClsiCookieManager._populateServerIdViaRequest this.ClsiCookieManager._populateServerIdViaRequest
.calledWith(this.project_id, this.user_id) .calledWith(this.project_id)
.should.equal(true) .should.equal(true)
return done() return done()
} }
@ -97,14 +94,13 @@ describe('ClsiCookieManager', function () {
it('should _populateServerIdViaRequest if no key is blank', function (done) { it('should _populateServerIdViaRequest if no key is blank', function (done) {
this.ClsiCookieManager._populateServerIdViaRequest = sinon this.ClsiCookieManager._populateServerIdViaRequest = sinon
.stub() .stub()
.callsArgWith(2) .callsArgWith(1)
this.redis.get.callsArgWith(1, null, '') this.redis.get.callsArgWith(1, null, '')
return this.ClsiCookieManager._getServerId( return this.ClsiCookieManager._getServerId(
this.project_id, this.project_id,
this.user_id,
(err, serverId) => { (err, serverId) => {
this.ClsiCookieManager._populateServerIdViaRequest this.ClsiCookieManager._populateServerIdViaRequest
.calledWith(this.project_id, this.user_id) .calledWith(this.project_id)
.should.equal(true) .should.equal(true)
return done() return done()
} }
@ -118,18 +114,16 @@ describe('ClsiCookieManager', function () {
this.request.post.callsArgWith(1, null, this.response) this.request.post.callsArgWith(1, null, this.response)
return (this.ClsiCookieManager.setServerId = sinon return (this.ClsiCookieManager.setServerId = sinon
.stub() .stub()
.callsArgWith(3, null, 'clsi-9')) .callsArgWith(2, null, 'clsi-9'))
}) })
it('should make a request to the clsi', function (done) { it('should make a request to the clsi', function (done) {
return this.ClsiCookieManager._populateServerIdViaRequest( return this.ClsiCookieManager._populateServerIdViaRequest(
this.project_id, this.project_id,
this.user_id,
(err, serverId) => { (err, serverId) => {
const args = this.ClsiCookieManager.setServerId.args[0] const args = this.ClsiCookieManager.setServerId.args[0]
args[0].should.equal(this.project_id) args[0].should.equal(this.project_id)
args[1].should.equal(this.user_id) args[1].should.deep.equal(this.response)
args[2].should.deep.equal(this.response)
return done() return done()
} }
) )
@ -138,7 +132,6 @@ describe('ClsiCookieManager', function () {
it('should return the server id', function (done) { it('should return the server id', function (done) {
return this.ClsiCookieManager._populateServerIdViaRequest( return this.ClsiCookieManager._populateServerIdViaRequest(
this.project_id, this.project_id,
this.user_id,
(err, serverId) => { (err, serverId) => {
serverId.should.equal('clsi-9') serverId.should.equal('clsi-9')
return done() return done()
@ -158,12 +151,11 @@ describe('ClsiCookieManager', function () {
it('should set the server id with a ttl', function (done) { it('should set the server id with a ttl', function (done) {
return this.ClsiCookieManager.setServerId( return this.ClsiCookieManager.setServerId(
this.project_id, this.project_id,
this.user_id,
this.response, this.response,
err => { err => {
this.redis.setex this.redis.setex
.calledWith( .calledWith(
`clsiserver:${this.project_id}:${this.user_id}`, `clsiserver:${this.project_id}`,
this.settings.clsiCookie.ttl, this.settings.clsiCookie.ttl,
'clsi-8' 'clsi-8'
) )
@ -176,7 +168,6 @@ describe('ClsiCookieManager', function () {
it('should return the server id', function (done) { it('should return the server id', function (done) {
return this.ClsiCookieManager.setServerId( return this.ClsiCookieManager.setServerId(
this.project_id, this.project_id,
this.user_id,
this.response, this.response,
(err, serverId) => { (err, serverId) => {
serverId.should.equal('clsi-8') serverId.should.equal('clsi-8')
@ -195,7 +186,6 @@ describe('ClsiCookieManager', function () {
})() })()
return this.ClsiCookieManager.setServerId( return this.ClsiCookieManager.setServerId(
this.project_id, this.project_id,
this.user_id,
this.response, this.response,
(err, serverId) => { (err, serverId) => {
this.redis.setex.called.should.equal(false) this.redis.setex.called.should.equal(false)
@ -210,7 +200,6 @@ describe('ClsiCookieManager', function () {
.returns(null) .returns(null)
return this.ClsiCookieManager.setServerId( return this.ClsiCookieManager.setServerId(
this.project_id, this.project_id,
this.user_id,
this.response, this.response,
(err, serverId) => { (err, serverId) => {
this.redis.setex.called.should.equal(false) this.redis.setex.called.should.equal(false)
@ -238,12 +227,11 @@ describe('ClsiCookieManager', function () {
.returns('clsi-8') .returns('clsi-8')
return this.ClsiCookieManager.setServerId( return this.ClsiCookieManager.setServerId(
this.project_id, this.project_id,
this.user_id,
this.response, this.response,
(err, serverId) => { (err, serverId) => {
this.redis_secondary.setex this.redis_secondary.setex
.calledWith( .calledWith(
`clsiserver:${this.project_id}:${this.user_id}`, `clsiserver:${this.project_id}`,
this.settings.clsiCookie.ttl, this.settings.clsiCookie.ttl,
'clsi-8' 'clsi-8'
) )
@ -258,13 +246,12 @@ describe('ClsiCookieManager', function () {
beforeEach(function () { beforeEach(function () {
return (this.ClsiCookieManager._getServerId = sinon return (this.ClsiCookieManager._getServerId = sinon
.stub() .stub()
.callsArgWith(2, null, 'clsi-11')) .callsArgWith(1, null, 'clsi-11'))
}) })
it('should return a jar with the cookie set populated from redis', function (done) { it('should return a jar with the cookie set populated from redis', function (done) {
return this.ClsiCookieManager.getCookieJar( return this.ClsiCookieManager.getCookieJar(
this.project_id, this.project_id,
this.user_id,
(err, jar) => { (err, jar) => {
jar._jar.store.idx['clsi.example.com']['/'][ jar._jar.store.idx['clsi.example.com']['/'][
this.settings.clsiCookie.key this.settings.clsiCookie.key
@ -287,7 +274,6 @@ describe('ClsiCookieManager', function () {
})() })()
return this.ClsiCookieManager.getCookieJar( return this.ClsiCookieManager.getCookieJar(
this.project_id, this.project_id,
this.user_id,
(err, jar) => { (err, jar) => {
assert.deepEqual(jar, realRequst.jar()) assert.deepEqual(jar, realRequst.jar())
return done() return done()

View file

@ -8,8 +8,8 @@ describe('ClsiManager', function () {
this.jar = { cookie: 'stuff' } this.jar = { cookie: 'stuff' }
this.ClsiCookieManager = { this.ClsiCookieManager = {
clearServerId: sinon.stub().yields(), clearServerId: sinon.stub().yields(),
getCookieJar: sinon.stub().callsArgWith(2, null, this.jar), getCookieJar: sinon.stub().callsArgWith(1, null, this.jar),
setServerId: sinon.stub().callsArgWith(3), setServerId: sinon.stub().callsArgWith(2),
_getServerId: sinon.stub(), _getServerId: sinon.stub(),
} }
this.ClsiStateManager = { this.ClsiStateManager = {
@ -73,7 +73,7 @@ describe('ClsiManager', function () {
this.ClsiManager._buildRequest = sinon this.ClsiManager._buildRequest = sinon
.stub() .stub()
.callsArgWith(2, null, (this.request = 'mock-request')) .callsArgWith(2, null, (this.request = 'mock-request'))
this.ClsiCookieManager._getServerId.callsArgWith(2, null, 'clsi3') this.ClsiCookieManager._getServerId.callsArgWith(1, null, 'clsi3')
}) })
describe('with a successful compile', function () { describe('with a successful compile', function () {
@ -354,7 +354,7 @@ describe('ClsiManager', function () {
beforeEach(function () { beforeEach(function () {
this.submission_id = 'submission-id' this.submission_id = 'submission-id'
this.clsi_request = 'mock-request' this.clsi_request = 'mock-request'
this.ClsiCookieManager._getServerId.callsArgWith(2, null, 'clsi3') this.ClsiCookieManager._getServerId.callsArgWith(1, null, 'clsi3')
}) })
describe('with a successful compile', function () { describe('with a successful compile', function () {
@ -490,7 +490,6 @@ describe('ClsiManager', function () {
this.ClsiManager._makeRequestWithClsiServerId this.ClsiManager._makeRequestWithClsiServerId
.calledWith( .calledWith(
this.project_id, this.project_id,
this.user_id,
{ {
method: 'DELETE', method: 'DELETE',
url: `${this.settings.apis.clsi.url}/project/${this.project_id}/user/${this.user_id}`, url: `${this.settings.apis.clsi.url}/project/${this.project_id}/user/${this.user_id}`,
@ -508,7 +507,7 @@ describe('ClsiManager', function () {
it('should clear the clsi persistance', function () { it('should clear the clsi persistance', function () {
this.ClsiCookieManager.clearServerId this.ClsiCookieManager.clearServerId
.calledWith(this.project_id, this.user_id) .calledWith(this.project_id)
.should.equal(true) .should.equal(true)
}) })
@ -925,7 +924,7 @@ describe('ClsiManager', function () {
this.ClsiManager._makeRequest = sinon this.ClsiManager._makeRequest = sinon
.stub() .stub()
.callsArgWith( .callsArgWith(
3, 2,
null, null,
{ statusCode: 204 }, { statusCode: 204 },
(this.body = { mock: 'foo' }) (this.body = { mock: 'foo' })
@ -942,7 +941,7 @@ describe('ClsiManager', function () {
it('should send the request to the CLSI', function () { it('should send the request to the CLSI', function () {
const url = `${this.settings.apis.clsi.url}/project/${this.project_id}/user/${this.user_id}/compile` const url = `${this.settings.apis.clsi.url}/project/${this.project_id}/user/${this.user_id}/compile`
this.ClsiManager._makeRequest this.ClsiManager._makeRequest
.calledWith(this.project_id, this.user_id, { .calledWith(this.project_id, {
method: 'POST', method: 'POST',
url, url,
json: this.req, json: this.req,
@ -960,7 +959,7 @@ describe('ClsiManager', function () {
this.ClsiManager._makeRequest = sinon this.ClsiManager._makeRequest = sinon
.stub() .stub()
.callsArgWith( .callsArgWith(
3, 2,
null, null,
{ statusCode: 500 }, { statusCode: 500 },
(this.body = { mock: 'foo' }) (this.body = { mock: 'foo' })
@ -1010,7 +1009,6 @@ describe('ClsiManager', function () {
this.ClsiManager._makeRequestWithClsiServerId this.ClsiManager._makeRequestWithClsiServerId
.calledWith( .calledWith(
this.project_id, this.project_id,
this.user_id,
{ {
method: 'GET', method: 'GET',
url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount`, url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount`,
@ -1045,7 +1043,6 @@ describe('ClsiManager', function () {
this.ClsiManager._makeRequestWithClsiServerId this.ClsiManager._makeRequestWithClsiServerId
.calledWith( .calledWith(
this.project_id, this.project_id,
this.user_id,
{ {
method: 'GET', method: 'GET',
url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount`, url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount`,
@ -1075,7 +1072,6 @@ describe('ClsiManager', function () {
this.ClsiManager._makeRequestWithClsiServerId this.ClsiManager._makeRequestWithClsiServerId
.calledWith( .calledWith(
this.project_id, this.project_id,
this.user_id,
{ {
method: 'GET', method: 'GET',
url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount`, url: `http://clsi.example.com/project/${this.project_id}/user/${this.user_id}/wordcount`,
@ -1099,32 +1095,22 @@ describe('ClsiManager', function () {
}) })
it('should process a request with a cookie jar', function (done) { it('should process a request with a cookie jar', function (done) {
this.ClsiManager._makeRequest( this.ClsiManager._makeRequest(this.project_id, this.opts, () => {
this.project_id, const args = this.request.args[0]
this.user_id, args[0].method.should.equal(this.opts.method)
this.opts, args[0].url.should.equal(this.opts.url)
() => { args[0].jar.should.equal(this.jar)
const args = this.request.args[0] done()
args[0].method.should.equal(this.opts.method) })
args[0].url.should.equal(this.opts.url)
args[0].jar.should.equal(this.jar)
done()
}
)
}) })
it('should set the cookie again on response as it might have changed', function (done) { it('should set the cookie again on response as it might have changed', function (done) {
this.ClsiManager._makeRequest( this.ClsiManager._makeRequest(this.project_id, this.opts, () => {
this.project_id, this.ClsiCookieManager.setServerId
this.user_id, .calledWith(this.project_id, this.response)
this.opts, .should.equal(true)
() => { done()
this.ClsiCookieManager.setServerId })
.calledWith(this.project_id, this.user_id, this.response)
.should.equal(true)
done()
}
)
}) })
}) })
@ -1142,7 +1128,6 @@ describe('ClsiManager', function () {
it('should process a request with a cookie jar', function (done) { it('should process a request with a cookie jar', function (done) {
this.ClsiManager._makeRequestWithClsiServerId( this.ClsiManager._makeRequestWithClsiServerId(
this.project_id, this.project_id,
this.user_id,
this.opts, this.opts,
undefined, undefined,
err => { err => {
@ -1160,13 +1145,12 @@ describe('ClsiManager', function () {
it('should persist the cookie from the response', function (done) { it('should persist the cookie from the response', function (done) {
this.ClsiManager._makeRequestWithClsiServerId( this.ClsiManager._makeRequestWithClsiServerId(
this.project_id, this.project_id,
this.user_id,
this.opts, this.opts,
undefined, undefined,
err => { err => {
if (err) return done(err) if (err) return done(err)
this.ClsiCookieManager.setServerId this.ClsiCookieManager.setServerId
.calledWith(this.project_id, this.user_id, this.response) .calledWith(this.project_id, this.response)
.should.equal(true) .should.equal(true)
done() done()
} }
@ -1178,7 +1162,6 @@ describe('ClsiManager', function () {
it('should not add a cookie jar', function (done) { it('should not add a cookie jar', function (done) {
this.ClsiManager._makeRequestWithClsiServerId( this.ClsiManager._makeRequestWithClsiServerId(
this.project_id, this.project_id,
this.user_id,
this.opts, this.opts,
'node-1', 'node-1',
err => { err => {
@ -1196,7 +1179,6 @@ describe('ClsiManager', function () {
it('should not persist a cookie on response', function (done) { it('should not persist a cookie on response', function (done) {
this.ClsiManager._makeRequestWithClsiServerId( this.ClsiManager._makeRequestWithClsiServerId(
this.project_id, this.project_id,
this.user_id,
this.opts, this.opts,
'node-1', 'node-1',
err => { err => {
@ -1222,7 +1204,6 @@ describe('ClsiManager', function () {
it('should change the domain on the url', function (done) { it('should change the domain on the url', function (done) {
this.ClsiManager._makeNewBackendRequest( this.ClsiManager._makeNewBackendRequest(
this.project_id, this.project_id,
this.user_id,
this.opts, this.opts,
() => { () => {
const args = this.request.args[0] const args = this.request.args[0]
@ -1238,7 +1219,6 @@ describe('ClsiManager', function () {
this.settings.apis.clsi_new = undefined this.settings.apis.clsi_new = undefined
this.ClsiManager._makeNewBackendRequest( this.ClsiManager._makeNewBackendRequest(
this.project_id, this.project_id,
this.user_id,
this.opts, this.opts,
err => { err => {
expect(err).to.equal(undefined) expect(err).to.equal(undefined)

View file

@ -49,7 +49,7 @@ describe('CompileController', function () {
} }
this.jar = { cookie: 'stuff' } this.jar = { cookie: 'stuff' }
this.ClsiCookieManager = { this.ClsiCookieManager = {
getCookieJar: sinon.stub().callsArgWith(2, null, this.jar), getCookieJar: sinon.stub().callsArgWith(1, null, this.jar),
} }
this.SessionManager = { this.SessionManager = {
getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user), getLoggedInUser: sinon.stub().callsArgWith(1, null, this.user),