mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Merge pull request #1688 from fdellabetta/server_side_namespace
client cannot connect to non-existing namespaces
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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(){
|
||||
|
||||
Reference in New Issue
Block a user