From 3ae013b90e1915a99abe8ca0b7ed8611cc4203d2 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 29 May 2017 23:24:26 -0700 Subject: [PATCH] validate namespace in disconnect call Fixes https://github.com/miguelgrinberg/Flask-SocketIO/issues/427 --- socketio/base_manager.py | 2 ++ tests/test_base_manager.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/socketio/base_manager.py b/socketio/base_manager.py index 283db13..09bef7c 100644 --- a/socketio/base_manager.py +++ b/socketio/base_manager.py @@ -64,6 +64,8 @@ class BaseManager(object): def disconnect(self, sid, namespace): """Register a client disconnect from a namespace.""" + if namespace not in self.rooms: + return rooms = [] for room_name, room in six.iteritems(self.rooms[namespace]): if sid in room: diff --git a/tests/test_base_manager.py b/tests/test_base_manager.py index 55141d4..d4291f9 100644 --- a/tests/test_base_manager.py +++ b/tests/test_base_manager.py @@ -99,6 +99,11 @@ class TestBaseManager(unittest.TestCase): self.bm.disconnect('123', '/') self.assertNotIn('123', self.bm.callbacks) + def test_disconnect_bad_namespace(self): + self.bm.connect('123', '/') + self.bm.connect('123', '/foo') + self.bm.disconnect('123', '/bar') # should not assert + def test_trigger_callback(self): self.bm.connect('123', '/') self.bm.connect('123', '/foo')