diff --git a/socketio/base_manager.py b/socketio/base_manager.py index 795bb93..936101a 100644 --- a/socketio/base_manager.py +++ b/socketio/base_manager.py @@ -103,6 +103,8 @@ class BaseManager(object): def enter_room(self, sid, namespace, room, eio_sid=None): """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: self.rooms[namespace] = {} if room not in self.rooms[namespace]: diff --git a/tests/common/test_base_manager.py b/tests/common/test_base_manager.py index af949ce..a695fed 100644 --- a/tests/common/test_base_manager.py +++ b/tests/common/test_base_manager.py @@ -1,6 +1,8 @@ import unittest from unittest import mock +import pytest + from socketio import base_manager @@ -119,6 +121,11 @@ class TestBaseManager(unittest.TestCase): self.bm.connect('123', '/foo') 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): sid1 = self.bm.connect('123', '/') sid2 = self.bm.connect('123', '/foo')