Permalink
Browse files

Invalid session id test

Potenital fix for timeout assertion uncaught exception
  • Loading branch information...
1 parent 1046e72 commit 85ad36e4dcd65e9bdb1a66ba2381fa29081575b7 @rauchg rauchg committed Oct 27, 2010
Showing with 25 additions and 6 deletions.
  1. +1 −1 lib/socket.io/listener.js
  2. +5 −3 lib/socket.io/transports/websocket.js
  3. +19 −2 tests/listener.js
@@ -165,7 +165,7 @@ Listener.prototype._onClientDisconnect = function(client){
Listener.prototype._onConnection = function(transport, req, res, httpUpgrade, head){
if (this.options.transports.indexOf(transport) === -1 || (httpUpgrade && !transports[transport].httpUpgrade)){
- httpUpgrade ? res.destroy() : req.connection.destroy();
+ req.connection.end();
return this.options.log('Illegal transport "'+ transport +'"');
}
this.options.log('Initializing client with transport "'+ transport +'"');
@@ -22,11 +22,13 @@ WebSocket.prototype._onConnect = function(req, socket){
this.connection.destroy();
return false;
}
-
- this.connection.setTimeout(0);
+
+ // this seems to solve a weird problem with timeouts: connections not being closed and hanging
+ // and an assertion failing in timeouts.
+ this.connection.setTimeout(100000000000);
this.connection.setEncoding('utf8');
this.connection.setNoDelay(true);
-
+
if ('sec-websocket-key1' in this.request.headers){
this.draft = 76;
}
View
@@ -22,8 +22,9 @@ function listen(s, callback){
return s;
};
-function client(server){
- return new WebSocket('ws://localhost:' + server._port + '/socket.io/websocket', 'borf');
+function client(server, sessid){
+ sessid = sessid ? '/' + sessid : '';
+ return new WebSocket('ws://localhost:' + server._port + '/socket.io/websocket' + sessid, 'borf');
};
module.exports = {
@@ -110,6 +111,22 @@ module.exports = {
}
};
})
+ },
+
+ 'test connecting with an invalid sessionid': function(assert){
+ var _server = server()
+ , _socket = socket(_server);
+ listen(_server, function(){
+ var _client = client(_server, 'fake-session-id')
+ , gotMessage = false;
+ _client.onmessage = function(){
+ gotMessage = true;
+ };
+ setTimeout(function(){
+ assert.ok(!gotMessage);
+ _server.close();
+ }, 200);
+ });
}
};

0 comments on commit 85ad36e

Please sign in to comment.