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
|
|
|
|
*/
|
|
|
|
const RealTimeClient = require("./helpers/RealTimeClient");
|
|
|
|
const Settings = require("settings-sharelatex");
|
|
|
|
const {expect} = require('chai');
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
describe('SessionSockets', function() {
|
|
|
|
before(function() {
|
|
|
|
return this.checkSocket = function(fn) {
|
|
|
|
const client = RealTimeClient.connect();
|
|
|
|
client.on('connectionAccepted', fn);
|
|
|
|
client.on('connectionRejected', fn);
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
});
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
describe('without cookies', function() {
|
|
|
|
before(() => RealTimeClient.cookie = null);
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
return it('should return a lookup error', function(done) {
|
|
|
|
return this.checkSocket(function(error) {
|
|
|
|
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:29 -04:00
|
|
|
describe('with a different cookie', function() {
|
|
|
|
before(() => RealTimeClient.cookie = "some.key=someValue");
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
return it('should return a lookup error', function(done) {
|
|
|
|
return this.checkSocket(function(error) {
|
|
|
|
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:29 -04:00
|
|
|
describe('with an invalid cookie', function() {
|
|
|
|
before(function(done) {
|
|
|
|
RealTimeClient.setSession({}, function(error) {
|
|
|
|
if (error) { return done(error); }
|
|
|
|
RealTimeClient.cookie = `${Settings.cookieName}=${
|
2020-06-06 08:37:40 -04:00
|
|
|
RealTimeClient.cookie.slice(17, 49)
|
2020-06-23 13:30:29 -04:00
|
|
|
}`;
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
return it('should return a lookup error', function(done) {
|
|
|
|
return this.checkSocket(function(error) {
|
|
|
|
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:29 -04:00
|
|
|
describe('with a valid cookie and no matching session', function() {
|
|
|
|
before(() => RealTimeClient.cookie = `${Settings.cookieName}=unknownId`);
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
return it('should return a lookup error', function(done) {
|
|
|
|
return this.checkSocket(function(error) {
|
|
|
|
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:29 -04:00
|
|
|
return describe('with a valid cookie and a matching session', function() {
|
|
|
|
before(function(done) {
|
|
|
|
RealTimeClient.setSession({}, done);
|
|
|
|
return null;
|
|
|
|
});
|
2020-06-06 08:37:40 -04:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
return it('should not return an error', function(done) {
|
|
|
|
return this.checkSocket(function(error) {
|
|
|
|
expect(error).to.not.exist;
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|