Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test connecting to non-default namespace #1681

Closed
fdellabetta opened this issue Jul 16, 2014 · 11 comments
Closed

Failing test connecting to non-default namespace #1681

fdellabetta opened this issue Jul 16, 2014 · 11 comments

Comments

@fdellabetta
Copy link
Contributor

Test is failing with Error: timeout of 2000ms exceeded
Ubuntu 14.04 x64, node.js 0.10.29, socket.io 1.0.6

it('should pass errors when connecting to non-default namespace', function(done){
  var srv = http();
  var sio = io(srv);
  sio.use(function(socket, next){
    next(new Error('Authentication error'))
  });
  srv.listen(function(){
    var socket = client(srv,'/ns');
    socket.on('error', function(err){
      expect(err).to.be('Authentication error');
      done();
    });
  });
});
@rauchg
Copy link
Contributor

rauchg commented Jul 16, 2014

That first use call applies to the default / namespace. You have to prefix it with .of('/ns') in that case.

@rauchg rauchg closed this as completed Jul 16, 2014
@fdellabetta
Copy link
Contributor Author

With 0.9.17 works...(with set authorization instead of use of course)
What is the expected behavior in this case ?

@rauchg rauchg reopened this Jul 16, 2014
@rauchg
Copy link
Contributor

rauchg commented Jul 16, 2014

Good point… Since now io.on('connection') captures the connections not for all namespaces but for the / namespace, I think .use should only apply to /

@fdellabetta
Copy link
Contributor Author

What I'm trying to do actually is to allow a client only to connect to specific (dynamic) namespaces and reject the connection to other namespaces (thus checking namespace in the first use callback and reject with an Error if namespace doesn't match)
By the way, is possible to read the namespace from the socket in use callback ?
It would be very useful... (instead of doing like this http://stackoverflow.com/questions/13143945/dynamic-namespaces-socket-io)

@evanlucas
Copy link

@fdellabetta for getting the namespace, try socket.nsp.name

@fdellabetta
Copy link
Contributor Author

I have already tried, but seems that socket.nsp.name returns always '/' in
io.use(...), not the one you are using to connect with the client

On Thu, Jul 17, 2014 at 4:29 AM, Evan Lucas notifications@github.com
wrote:

@fdellabetta /~https://github.com/fdellabetta for getting the namespace,
try socket.nsp.name


Reply to this email directly or view it on GitHub
#1681 (comment)
.

@evanlucas
Copy link

Have you tried io.of('<namespace>').use(...?

@fdellabetta
Copy link
Contributor Author

No, but that's not what I wanted to do...
If you log socket.nsp.name inside of io.of('').use(... you
always get ...

On Thu, Jul 17, 2014 at 10:24 AM, Evan Lucas notifications@github.com
wrote:

Are you using io.of('').use(...?


Reply to this email directly or view it on GitHub
#1681 (comment)
.

@fdellabetta
Copy link
Contributor Author

@guille, @evanlucas For my and @smaffer understanding, when a client connect to a namespace, if the namespace does't exist on server, it's automatically created.

What about checking something like

  if (!this.server.nsps[name]) {
    debug('namespace %s does not exist', name);
    //send error
    //close connection
    return;
  }

before line

  var nsp = this.server.of(name);

of Client.prototype.connect function that creates Namespace object ?

@ofirzh
Copy link

ofirzh commented Nov 16, 2014

still the issue exists.

@rase-
Copy link
Contributor

rase- commented Jan 12, 2015

It seems like there is general agreement for

Good point… Since now io.on('connection') captures the connections not for all namespaces but for the / namespace, I think .use should only apply to /

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@rauchg @evanlucas @rase- @fdellabetta @ofirzh and others