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:
parent
de40574362
commit
54dfbdf987
@ -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();
|
||||
});
|
||||
|
@ -55,9 +55,10 @@ 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.on('echo-response', function () {
|
||||
socket.close();
|
||||
done();
|
||||
}).on('authenticated', function () {
|
||||
socket.emit('echo');
|
||||
}).emit('authenticate', { token: token });
|
||||
});
|
||||
|
@ -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();
|
||||
};
|
Loading…
Reference in New Issue
Block a user