fixed all broken tests with socket.io 1.0, close #10

This commit is contained in:
José F. Romaniello
2014-06-05 15:45:41 -03:00
parent 130357ff80
commit 3484a429ed
5 changed files with 36 additions and 25 deletions

View File

@ -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');
server.$emit('authenticated', socket);
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', {