Merge pull request #1688 from fdellabetta/server_side_namespace

client cannot connect to non-existing namespaces
This commit is contained in:
Guillermo Rauch
2014-08-01 13:45:32 +01:00
2 changed files with 18 additions and 0 deletions

View File

@@ -57,6 +57,10 @@ Client.prototype.setup = function(){
Client.prototype.connect = function(name){
debug('connecting to namespace %s', name);
if (!this.server.nsps[name]) {
this.packet({ type: parser.ERROR, nsp: name, data : 'Invalid namespace'});
return;
}
var nsp = this.server.of(name);
if ('/' != name && !this.nsps['/']) {
this.connectBuffer.push(name);

View File

@@ -377,6 +377,8 @@ describe('socket.io', function(){
var srv = http();
var sio = io(srv);
srv.listen(function(){
sio.of('/chat');
sio.of('/news');
var chat = client(srv, '/chat');
var news = client(srv, '/news');
var total = 2;
@@ -491,6 +493,18 @@ describe('socket.io', function(){
});
});
});
it('should return error connecting to non-existent namespace', function(done){
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv,'/doesnotexist');
socket.on('error', function(err) {
expect(err).to.be('Invalid namespace');
done();
});
});
});
});
describe('socket', function(){