Merge pull request #13510 from overleaf/em-promisify-clsi-manager

Clean up of ClsiManager and ClsiCookieManager

GitOrigin-RevId: e5047b253613e87fd6cb4f12855b821028fcaf8e
This commit is contained in:
Eric Mc Sween
2023-07-17 10:41:13 +00:00
committed by Copybot
parent 8cdfffa6f9
commit 1fc13b8cbf
5 changed files with 1723 additions and 2088 deletions
@@ -1,16 +1,3 @@
/* eslint-disable
n/handle-callback-err,
max-len,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const sinon = require('sinon')
const { assert, expect } = require('chai')
const modulePath = '../../../../app/src/Features/Compile/ClsiCookieManager.js'
@@ -19,7 +6,6 @@ const realRequst = require('request')
describe('ClsiCookieManager', function () {
beforeEach(function () {
const self = this
this.redis = {
auth() {},
get: sinon.stub(),
@@ -57,25 +43,28 @@ describe('ClsiCookieManager', function () {
'@overleaf/settings': this.settings,
request: this.request,
}
return (this.ClsiCookieManager = SandboxedModule.require(modulePath, {
this.ClsiCookieManager = SandboxedModule.require(modulePath, {
requires: this.requires,
})())
})()
})
describe('getServerId', function () {
it('should call get for the key', function (done) {
this.redis.get.callsArgWith(1, null, 'clsi-7')
return this.ClsiCookieManager._getServerId(
this.ClsiCookieManager._getServerId(
this.project_id,
this.user_id,
'',
'e2',
(err, serverId) => {
if (err) {
return done(err)
}
this.redis.get
.calledWith(`clsiserver:${this.project_id}:${this.user_id}`)
.should.equal(true)
serverId.should.equal('clsi-7')
return done()
done()
}
)
})
@@ -85,15 +74,18 @@ describe('ClsiCookieManager', function () {
.stub()
.yields(null)
this.redis.get.callsArgWith(1, null)
return this.ClsiCookieManager._getServerId(
this.ClsiCookieManager._getServerId(
this.project_id,
this.user_id,
'',
(err, serverId) => {
if (err) {
return done(err)
}
this.ClsiCookieManager._populateServerIdViaRequest
.calledWith(this.project_id, this.user_id)
.should.equal(true)
return done()
done()
}
)
})
@@ -103,16 +95,19 @@ describe('ClsiCookieManager', function () {
.stub()
.yields(null)
this.redis.get.callsArgWith(1, null, '')
return this.ClsiCookieManager._getServerId(
this.ClsiCookieManager._getServerId(
this.project_id,
this.user_id,
'',
'e2',
(err, serverId) => {
if (err) {
return done(err)
}
this.ClsiCookieManager._populateServerIdViaRequest
.calledWith(this.project_id, this.user_id)
.should.equal(true)
return done()
done()
}
)
})
@@ -122,38 +117,42 @@ describe('ClsiCookieManager', function () {
beforeEach(function () {
this.response = 'some data'
this.request.post.callsArgWith(1, null, this.response)
return (this.ClsiCookieManager.setServerId = sinon
.stub()
.yields(null, 'clsi-9'))
this.ClsiCookieManager.setServerId = sinon.stub().yields(null, 'clsi-9')
})
it('should make a request to the clsi', function (done) {
return this.ClsiCookieManager._populateServerIdViaRequest(
this.ClsiCookieManager._populateServerIdViaRequest(
this.project_id,
this.user_id,
'standard',
'e2',
(err, serverId) => {
if (err) {
return done(err)
}
const args = this.ClsiCookieManager.setServerId.args[0]
args[0].should.equal(this.project_id)
args[1].should.equal(this.user_id)
args[2].should.equal('standard')
args[3].should.equal('e2')
args[4].should.deep.equal(this.response)
return done()
done()
}
)
})
it('should return the server id', function (done) {
return this.ClsiCookieManager._populateServerIdViaRequest(
this.ClsiCookieManager._populateServerIdViaRequest(
this.project_id,
this.user_id,
'',
'e2',
(err, serverId) => {
if (err) {
return done(err)
}
serverId.should.equal('clsi-9')
return done()
done()
}
)
})
@@ -168,7 +167,7 @@ describe('ClsiCookieManager', function () {
})
it('should set the server id with a ttl', function (done) {
return this.ClsiCookieManager.setServerId(
this.ClsiCookieManager.setServerId(
this.project_id,
this.user_id,
'standard',
@@ -176,6 +175,9 @@ describe('ClsiCookieManager', function () {
this.response,
null,
err => {
if (err) {
return done(err)
}
this.redis.setex
.calledWith(
`clsiserver:${this.project_id}:${this.user_id}`,
@@ -183,7 +185,7 @@ describe('ClsiCookieManager', function () {
'clsi-8'
)
.should.equal(true)
return done()
done()
}
)
})
@@ -200,6 +202,9 @@ describe('ClsiCookieManager', function () {
this.response,
null,
err => {
if (err) {
return done(err)
}
expect(this.redis.setex).to.have.been.calledWith(
`clsiserver:${this.project_id}:${this.user_id}`,
this.settings.clsiCookie.ttlInSecondsRegular,
@@ -211,7 +216,7 @@ describe('ClsiCookieManager', function () {
})
it('should return the server id', function (done) {
return this.ClsiCookieManager.setServerId(
this.ClsiCookieManager.setServerId(
this.project_id,
this.user_id,
'standard',
@@ -219,8 +224,11 @@ describe('ClsiCookieManager', function () {
this.response,
null,
(err, serverId) => {
if (err) {
return done(err)
}
serverId.should.equal('clsi-8')
return done()
done()
}
)
})
@@ -233,7 +241,7 @@ describe('ClsiCookieManager', function () {
},
requires: this.requires,
})()
return this.ClsiCookieManager.setServerId(
this.ClsiCookieManager.setServerId(
this.project_id,
this.user_id,
'standard',
@@ -241,8 +249,11 @@ describe('ClsiCookieManager', function () {
this.response,
null,
(err, serverId) => {
if (err) {
return done(err)
}
this.redis.setex.called.should.equal(false)
return done()
done()
}
)
})
@@ -251,7 +262,7 @@ describe('ClsiCookieManager', function () {
this.ClsiCookieManager._parseServerIdFromResponse = sinon
.stub()
.returns(null)
return this.ClsiCookieManager.setServerId(
this.ClsiCookieManager.setServerId(
this.project_id,
this.user_id,
'standard',
@@ -259,8 +270,11 @@ describe('ClsiCookieManager', function () {
this.response,
null,
(err, serverId) => {
if (err) {
return done(err)
}
this.redis.setex.called.should.equal(false)
return done()
done()
}
)
})
@@ -282,7 +296,7 @@ describe('ClsiCookieManager', function () {
this.ClsiCookieManager._parseServerIdFromResponse = sinon
.stub()
.returns('clsi-8')
return this.ClsiCookieManager.setServerId(
this.ClsiCookieManager.setServerId(
this.project_id,
this.user_id,
'standard',
@@ -290,6 +304,9 @@ describe('ClsiCookieManager', function () {
this.response,
null,
(err, serverId) => {
if (err) {
return done(err)
}
this.redis_secondary.setex
.calledWith(
`clsiserver:${this.project_id}:${this.user_id}`,
@@ -297,7 +314,7 @@ describe('ClsiCookieManager', function () {
'clsi-8'
)
.should.equal(true)
return done()
done()
}
)
})
@@ -305,25 +322,26 @@ describe('ClsiCookieManager', function () {
describe('getCookieJar', function () {
beforeEach(function () {
return (this.ClsiCookieManager._getServerId = sinon
.stub()
.yields(null, 'clsi-11'))
this.ClsiCookieManager._getServerId = sinon.stub().yields(null, 'clsi-11')
})
it('should return a jar with the cookie set populated from redis', function (done) {
return this.ClsiCookieManager.getCookieJar(
this.ClsiCookieManager.getCookieJar(
this.project_id,
this.user_id,
'',
'e2',
(err, jar) => {
if (err) {
return done(err)
}
jar._jar.store.idx['clsi.example.com']['/'][
this.settings.clsiCookie.key
].key.should.equal
jar._jar.store.idx['clsi.example.com']['/'][
this.settings.clsiCookie.key
].value.should.equal('clsi-11')
return done()
done()
}
)
})
@@ -336,14 +354,17 @@ describe('ClsiCookieManager', function () {
},
requires: this.requires,
})()
return this.ClsiCookieManager.getCookieJar(
this.ClsiCookieManager.getCookieJar(
this.project_id,
this.user_id,
'',
'e2',
(err, jar) => {
if (err) {
return done(err)
}
assert.deepEqual(jar, realRequst.jar())
return done()
done()
}
)
})
File diff suppressed because it is too large Load Diff