This repository has been archived on 2024-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
socketio-jwt/test/authorizer_noqs.test.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

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', () => {
2014-01-13 22:41:10 +01:00
//start and stop the server
before((done) => {
fixture.start({ handshake: false }, done);
2014-01-13 22:41:10 +01:00
});
after(fixture.stop);
describe('when the user is not logged in', () => {
2014-01-13 22:41:10 +01:00
it('should close the connection after a timeout if no auth message is received', (done) => {
io.connect('http://localhost:9000', { forceNew: true })
.once('disconnect', () => done());
2014-01-13 22:41:10 +01:00
});
it('should not respond echo', (done) => {
io.connect('http://localhost:9000', { forceNew: true })
.on('echo-response', () => 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', () => {
2014-01-13 22:41:10 +01:00
beforeEach((done) => {
2014-01-13 22:41:10 +01:00
request.post({
url: 'http://localhost:9000/login',
form: { username: 'jose', password: 'Pa123' },
json: true
}, (err, resp, body) => {
2014-01-13 22:41:10 +01:00
this.token = body.token;
done();
});
2014-01-13 22:41:10 +01:00
});
it('should do the authentication and connect', (done) => {
const socket = io.connect('http://localhost:9000', { forceNew: true });
socket
.on('echo-response', () => {
2015-05-29 14:39:49 +02:00
socket.close();
done();
})
.on('authenticated', () => { socket.emit('echo'); })
.emit('authenticate', { token: this.token });
2014-01-13 22:41:10 +01:00
});
});
});