2019-10-13 15:52:14 +02:00
|
|
|
const fixture = require('./fixture');
|
|
|
|
const request = require('request');
|
|
|
|
const io = require('socket.io-client');
|
2014-01-13 22:41:10 +01:00
|
|
|
|
|
|
|
describe('authorizer without querystring', function () {
|
|
|
|
|
|
|
|
//start and stop the server
|
|
|
|
before(function (done) {
|
|
|
|
fixture.start({
|
2014-01-14 12:30:39 +01:00
|
|
|
handshake: false
|
2014-01-13 22:41:10 +01:00
|
|
|
} , done);
|
|
|
|
});
|
|
|
|
|
|
|
|
after(fixture.stop);
|
|
|
|
|
|
|
|
describe('when the user is not logged in', function () {
|
|
|
|
|
2019-10-13 15:52:14 +02:00
|
|
|
it('should close the connection after a timeout if no auth message is received', function (done) {
|
|
|
|
io.connect('http://localhost:9000', { forceNew: true })
|
|
|
|
.once('disconnect', function () { done(); });
|
2014-01-13 22:41:10 +01:00
|
|
|
});
|
|
|
|
|
2019-10-13 15:52:14 +02:00
|
|
|
it('should not respond echo', function (done) {
|
|
|
|
io.connect('http://localhost:9000', { forceNew: true })
|
|
|
|
.on('echo-response', function () {
|
|
|
|
done(new Error('this should not happen'));
|
|
|
|
})
|
|
|
|
.emit('echo', { hi: 123 });
|
2014-01-13 22:41:10 +01:00
|
|
|
|
|
|
|
setTimeout(done, 1200);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the user is logged in', function() {
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
|
|
|
request.post({
|
|
|
|
url: 'http://localhost:9000/login',
|
|
|
|
form: { username: 'jose', password: 'Pa123' },
|
|
|
|
json: true
|
|
|
|
}, function (err, resp, body) {
|
|
|
|
this.token = body.token;
|
|
|
|
done();
|
|
|
|
}.bind(this));
|
|
|
|
});
|
|
|
|
|
2019-10-13 15:52:14 +02:00
|
|
|
it('should do the handshake and connect', function (done) {
|
|
|
|
const socket = io.connect('http://localhost:9000', { forceNew: true });
|
|
|
|
|
|
|
|
socket
|
|
|
|
.on('echo-response', function () {
|
2015-05-29 14:39:49 +02:00
|
|
|
socket.close();
|
|
|
|
done();
|
2019-10-13 15:52:14 +02:00
|
|
|
})
|
|
|
|
.on('authenticated', function () {
|
2015-05-29 14:39:49 +02:00
|
|
|
socket.emit('echo');
|
2019-10-13 15:52:14 +02:00
|
|
|
})
|
|
|
|
.emit('authenticate', { token: this.token });
|
2014-01-13 22:41:10 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|