fixed all broken tests with socket.io 1.0, close #10
This commit is contained in:
parent
130357ff80
commit
3484a429ed
22
lib/index.js
22
lib/index.js
@ -6,6 +6,14 @@ function noQsMethod(options) {
|
||||
return function (socket) {
|
||||
var server = this;
|
||||
|
||||
if (!server.$emit) {
|
||||
//then is socket.io 1.0
|
||||
var Namespace = Object.getPrototypeOf(server.server.sockets).constructor;
|
||||
if (!~Namespace.events.indexOf('authenticated')) {
|
||||
Namespace.events.push('authenticated');
|
||||
}
|
||||
}
|
||||
|
||||
var auth_timeout = setTimeout(function () {
|
||||
socket.disconnect('unauthorized');
|
||||
}, options.timeout || 5000);
|
||||
@ -19,7 +27,11 @@ function noQsMethod(options) {
|
||||
|
||||
socket.decoded_token = decoded;
|
||||
socket.emit('authenticated');
|
||||
if (server.$emit) {
|
||||
server.$emit('authenticated', socket);
|
||||
} else {
|
||||
server.server.sockets.emit('authenticated', socket);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -37,7 +49,7 @@ function authorize(options, onConnection) {
|
||||
},
|
||||
fail: function(error, data, accept){
|
||||
if (data.request) {
|
||||
accept();
|
||||
accept(error);
|
||||
} else {
|
||||
accept(null, false);
|
||||
}
|
||||
@ -52,8 +64,8 @@ function authorize(options, onConnection) {
|
||||
|
||||
return function(data, accept){
|
||||
var token, error;
|
||||
|
||||
var authorization_header = ((data.request || data).headers || {}).authorization;
|
||||
var req = data.request || data;
|
||||
var authorization_header = (req.headers || {}).authorization;
|
||||
|
||||
if (authorization_header) {
|
||||
var parts = authorization_header.split(' ');
|
||||
@ -73,7 +85,9 @@ function authorize(options, onConnection) {
|
||||
}
|
||||
|
||||
//get the token from query string
|
||||
token = (data.request || data).query.token;
|
||||
if (req._query && req._query.token) {
|
||||
token = req._query.token;
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
error = new UnauthorizedError('credentials_required', {
|
||||
|
13
package.json
13
package.json
@ -26,14 +26,13 @@
|
||||
"xtend": "~2.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"connect": "~2.7.11",
|
||||
"express": "~3.1.2",
|
||||
"mocha": "~1.17.0",
|
||||
"passport-local": "~0.1.6",
|
||||
"request": "~2.19.0",
|
||||
"should": "~1.2.2",
|
||||
"mocha": "~1.17.0",
|
||||
"express": "~3.1.2",
|
||||
"socket.io": "~0.9.14",
|
||||
"passport-local": "~0.1.6",
|
||||
"xmlhttprequest": "~1.5.0",
|
||||
"socket.io-client": "git+https://github.com/jfromaniello/socket.io-client.git",
|
||||
"connect": "~2.7.11"
|
||||
"socket.io": "^1.0.4",
|
||||
"socket.io-client": "^1.0.4"
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,12 @@ describe('authorizer', function () {
|
||||
describe('when the user is not logged in', function () {
|
||||
|
||||
it('should emit error with unauthorized handshake', function (done){
|
||||
var socket = io.connect('http://localhost:9000', {
|
||||
'query': 'token=Booooooooooooooooooooo',
|
||||
'force new connection': true
|
||||
var socket = io.connect('http://localhost:9000?token=boooooo', {
|
||||
'forceNew': true
|
||||
});
|
||||
|
||||
socket.on('error', function(err){
|
||||
err.should.eql('handshake unauthorized');
|
||||
err.should.eql("Invalid token: no header in signature 'boooooo'");
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -39,7 +38,7 @@ describe('authorizer', function () {
|
||||
|
||||
it('should do the handshake and connect', function (done){
|
||||
var socket = io.connect('http://localhost:9000', {
|
||||
'force new connection':true,
|
||||
'forceNew':true,
|
||||
'query': 'token=' + this.token
|
||||
});
|
||||
socket.on('connect', function(){
|
||||
|
@ -24,7 +24,7 @@ describe('authorizer without querystring', function () {
|
||||
|
||||
it('should not respond echo', function (done){
|
||||
var socket = io.connect('http://localhost:9000', {
|
||||
'force new connection':true,
|
||||
'forceNew':true,
|
||||
});
|
||||
|
||||
socket.on('echo-response', function () {
|
||||
@ -51,7 +51,7 @@ describe('authorizer without querystring', function () {
|
||||
|
||||
it('should do the handshake and connect', function (done){
|
||||
var socket = io.connect('http://localhost:9000', {
|
||||
'force new connection':true,
|
||||
'forceNew':true,
|
||||
});
|
||||
var token = this.token;
|
||||
socket.on('connect', function(){
|
||||
|
@ -48,12 +48,11 @@ exports.start = function (options, callback) {
|
||||
|
||||
var sio = socketIo.listen(server);
|
||||
|
||||
sio.configure(function(){
|
||||
if (options.handshake) {
|
||||
this.set('authorization', socketio_jwt.authorize(options));
|
||||
// this.set('authorization', socketio_jwt.authorize(options));
|
||||
sio.use(socketio_jwt.authorize(options));
|
||||
}
|
||||
this.set('log level', 0);
|
||||
});
|
||||
sio.set('log level', 0);
|
||||
|
||||
if (options.handshake) {
|
||||
sio.sockets.on('echo', function (m) {
|
||||
|
Reference in New Issue
Block a user