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

improve tests

This commit is contained in:
José F. Romaniello 2015-05-29 09:39:49 -03:00
parent de40574362
commit 54dfbdf987
3 changed files with 17 additions and 9 deletions

View File

@ -18,6 +18,7 @@ describe('authorizer', function () {
socket.on('error', function(err){
err.message.should.eql("jwt malformed");
err.code.should.eql("invalid_token");
socket.close();
done();
});
});
@ -43,6 +44,7 @@ describe('authorizer', function () {
'query': 'token=' + this.token
});
socket.on('connect', function(){
socket.close();
done();
}).on('error', done);
});
@ -59,8 +61,10 @@ describe('authorizer', function () {
'query': 'token=' + this.token
});
socket.on('connect', function () {
socket.close();
done(new Error('this shouldnt happen'));
}).on('error', function (err) {
socket.close();
err.message.should.eql("jwt signature is required");
done();
});

View File

@ -55,11 +55,12 @@ describe('authorizer without querystring', function () {
});
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 });
socket.on('echo-response', function () {
socket.close();
done();
}).on('authenticated', function () {
socket.emit('echo');
}).emit('authenticate', { token: token });
});
});
});

View File

@ -8,7 +8,7 @@ var jwt = require('jsonwebtoken');
var xtend = require('xtend');
var server;
var server, sio;
exports.start = function (options, callback) {
@ -46,13 +46,12 @@ exports.start = function (options, callback) {
server = http.createServer(app);
var sio = socketIo.listen(server);
sio = socketIo.listen(server);
if (options.handshake) {
// this.set('authorization', socketio_jwt.authorize(options));
sio.use(socketio_jwt.authorize(options));
}
sio.set('log level', 0);
if (options.handshake) {
sio.sockets.on('echo', function (m) {
@ -68,10 +67,14 @@ exports.start = function (options, callback) {
});
}
server.__sockets = [];
server.on('connection', function (c) {
server.__sockets.push(c);
});
server.listen(9000, callback);
};
exports.stop = function (callback) {
server.close();
sio.close();
callback();
};