2020-06-23 13:30:34 -04:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-06-23 13:30:29 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-06-23 13:30:45 -04:00
|
|
|
const RealTimeClient = require('./helpers/RealTimeClient')
|
2023-11-29 09:50:21 -05:00
|
|
|
const FixturesManager = require('./helpers/FixturesManager')
|
2021-07-12 12:47:18 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-06-23 13:30:45 -04:00
|
|
|
const { expect } = require('chai')
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
describe('SessionSockets', function () {
|
2023-11-29 09:50:21 -05:00
|
|
|
beforeEach(function (done) {
|
|
|
|
FixturesManager.setUpProject(
|
|
|
|
{
|
|
|
|
privilegeLevel: 'owner',
|
|
|
|
},
|
|
|
|
(err, options) => {
|
|
|
|
if (err) return done(err)
|
|
|
|
|
|
|
|
this.checkSocket = function (fn) {
|
|
|
|
RealTimeClient.connect(options.project_id, fn)
|
|
|
|
}
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
2020-06-23 13:30:45 -04:00
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
describe('without cookies', function () {
|
2023-11-29 09:50:21 -05:00
|
|
|
beforeEach(function () {
|
2020-06-23 13:30:45 -04:00
|
|
|
return (RealTimeClient.cookie = null)
|
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
return it('should return a lookup error', function (done) {
|
2021-07-13 07:04:45 -04:00
|
|
|
return this.checkSocket(error => {
|
2020-06-23 13:30:45 -04:00
|
|
|
expect(error).to.exist
|
|
|
|
expect(error.message).to.equal('invalid session')
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
describe('with a different cookie', function () {
|
2023-11-29 09:50:21 -05:00
|
|
|
beforeEach(function () {
|
2020-06-23 13:30:45 -04:00
|
|
|
return (RealTimeClient.cookie = 'some.key=someValue')
|
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
return it('should return a lookup error', function (done) {
|
2021-07-13 07:04:45 -04:00
|
|
|
return this.checkSocket(error => {
|
2020-06-23 13:30:45 -04:00
|
|
|
expect(error).to.exist
|
|
|
|
expect(error.message).to.equal('invalid session')
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
describe('with an invalid cookie', function () {
|
2023-11-29 09:50:21 -05:00
|
|
|
beforeEach(function (done) {
|
2021-07-13 07:04:45 -04:00
|
|
|
RealTimeClient.setSession({}, error => {
|
2020-06-23 13:30:45 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
RealTimeClient.cookie = `${
|
|
|
|
Settings.cookieName
|
|
|
|
}=${RealTimeClient.cookie.slice(17, 49)}`
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
return null
|
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
return it('should return a lookup error', function (done) {
|
2021-07-13 07:04:45 -04:00
|
|
|
return this.checkSocket(error => {
|
2020-06-23 13:30:45 -04:00
|
|
|
expect(error).to.exist
|
|
|
|
expect(error.message).to.equal('invalid session')
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
describe('with a valid cookie and no matching session', function () {
|
2023-11-29 09:50:21 -05:00
|
|
|
beforeEach(function () {
|
2020-06-23 13:30:45 -04:00
|
|
|
return (RealTimeClient.cookie = `${Settings.cookieName}=unknownId`)
|
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
return it('should return a lookup error', function (done) {
|
2021-07-13 07:04:45 -04:00
|
|
|
return this.checkSocket(error => {
|
2020-06-23 13:30:45 -04:00
|
|
|
expect(error).to.exist
|
|
|
|
expect(error.message).to.equal('invalid session')
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
return describe('with a valid cookie and a matching session', function () {
|
|
|
|
return it('should not return an error', function (done) {
|
2021-07-13 07:04:45 -04:00
|
|
|
return this.checkSocket(error => {
|
2020-06-23 13:30:45 -04:00
|
|
|
expect(error).to.not.exist
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|