2
1
mirror of https://github.com/Thream/socketio-jwt.git synced 2024-07-21 09:38:31 +02:00
socketio-jwt/test/authorizer_noqs.test.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-01-13 22:41:10 +01:00
var fixture = require('./fixture');
var request = require('request');
var io = require('socket.io-client');
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 () {
it('should close the connection after a timeout if no auth message is received', function (done){
var socket = io.connect('http://localhost:9000');
socket.on('disconnect', function () {
done();
});
});
it('should not respond echo', function (done){
var socket = io.connect('http://localhost:9000', {
'forceNew':true,
2014-01-13 22:41:10 +01:00
});
socket.on('echo-response', function () {
done(new Error('this should not happen'));
}).emit('echo', { hi: 123 });
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));
});
it('should do the handshake and connect', function (done){
var socket = io.connect('http://localhost:9000', {
'forceNew':true,
2014-01-13 22:41:10 +01:00
});
var token = this.token;
socket.on('connect', function(){
console.log('connected');
socket.on('echo-response', done)
.on('authenticated', function () {
socket.emit('echo');
}).emit('authenticate', { token: token });
});
});
});
});