Browse Source

More descriptive error when joining a room on a bad namespace (Fixes #650)

pull/683/head
Miguel Grinberg 4 years ago
parent
commit
66068d9e96
No known key found for this signature in database GPG Key ID: 36848B262DF5F06C
  1. 2
      socketio/base_manager.py
  2. 7
      tests/common/test_base_manager.py

2
socketio/base_manager.py

@ -103,6 +103,8 @@ class BaseManager(object):
def enter_room(self, sid, namespace, room, eio_sid=None): def enter_room(self, sid, namespace, room, eio_sid=None):
"""Add a client to a room.""" """Add a client to a room."""
if eio_sid is None and namespace not in self.rooms:
raise ValueError('sid is not connected to requested namespace')
if namespace not in self.rooms: if namespace not in self.rooms:
self.rooms[namespace] = {} self.rooms[namespace] = {}
if room not in self.rooms[namespace]: if room not in self.rooms[namespace]:

7
tests/common/test_base_manager.py

@ -1,6 +1,8 @@
import unittest import unittest
from unittest import mock from unittest import mock
import pytest
from socketio import base_manager from socketio import base_manager
@ -119,6 +121,11 @@ class TestBaseManager(unittest.TestCase):
self.bm.connect('123', '/foo') self.bm.connect('123', '/foo')
self.bm.disconnect('123', '/bar') # should not assert self.bm.disconnect('123', '/bar') # should not assert
def test_enter_room_bad_namespace(self):
sid = self.bm.connect('123', '/')
with pytest.raises(ValueError):
self.bm.enter_room(sid, '/foo', 'bar')
def test_trigger_callback(self): def test_trigger_callback(self):
sid1 = self.bm.connect('123', '/') sid1 = self.bm.connect('123', '/')
sid2 = self.bm.connect('123', '/foo') sid2 = self.bm.connect('123', '/foo')

Loading…
Cancel
Save