Skip to content

Commit 66068d9

Browse files
More descriptive error when joining a room on a bad namespace (Fixes #650)
1 parent 2f085b3 commit 66068d9

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

socketio/base_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def disconnect(self, sid, namespace):
103103

104104
def enter_room(self, sid, namespace, room, eio_sid=None):
105105
"""Add a client to a room."""
106+
if eio_sid is None and namespace not in self.rooms:
107+
raise ValueError('sid is not connected to requested namespace')
106108
if namespace not in self.rooms:
107109
self.rooms[namespace] = {}
108110
if room not in self.rooms[namespace]:

tests/common/test_base_manager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import unittest
22
from unittest import mock
33

4+
import pytest
5+
46
from socketio import base_manager
57

68

@@ -119,6 +121,11 @@ def test_disconnect_bad_namespace(self):
119121
self.bm.connect('123', '/foo')
120122
self.bm.disconnect('123', '/bar') # should not assert
121123

124+
def test_enter_room_bad_namespace(self):
125+
sid = self.bm.connect('123', '/')
126+
with pytest.raises(ValueError):
127+
self.bm.enter_room(sid, '/foo', 'bar')
128+
122129
def test_trigger_callback(self):
123130
sid1 = self.bm.connect('123', '/')
124131
sid2 = self.bm.connect('123', '/foo')

0 commit comments

Comments
 (0)