@@ -719,6 +719,20 @@ async def test_handle_event_binary_ack(self, eio):
719719 sid , 321 , ['my message' , 'a' , b'foo' ]
720720 )
721721
722+ async def test_handle_event_binary_from_unknown (self , eio ):
723+ eio .return_value .send = mock .AsyncMock ()
724+ s = async_server .AsyncServer (async_handlers = False )
725+ await s .manager .connect ('123' , '/' )
726+ handler = mock .MagicMock ()
727+ s .on ('my message' , handler )
728+ with pytest .raises (ValueError ):
729+ await s ._handle_eio_message (
730+ '999' ,
731+ '52-["my message","a",'
732+ '{"_placeholder":true,"num":1},'
733+ '{"_placeholder":true,"num":0}]' ,
734+ )
735+
722736 async def test_handle_event_with_ack (self , eio ):
723737 eio .return_value .send = mock .AsyncMock ()
724738 s = async_server .AsyncServer (async_handlers = False )
@@ -923,6 +937,24 @@ async def test_disconnect_twice_namespace(self, eio):
923937 await s .disconnect ('1' , namespace = '/foo' )
924938 assert calls == s .eio .send .await_count
925939
940+ async def test_disconnect_with_partial_binary_packet (self , eio ):
941+ eio .return_value .send = mock .AsyncMock ()
942+ eio .return_value .disconnect = mock .AsyncMock ()
943+ s = async_server .AsyncServer ()
944+ await s ._handle_eio_connect ('123' , 'environ' )
945+ await s ._handle_eio_message ('123' , '0' )
946+ await s ._handle_eio_message (
947+ '123' ,
948+ '52-["my message","a",'
949+ '{"_placeholder":true,"num":1},'
950+ '{"_placeholder":true,"num":0}]' ,
951+ )
952+ await s ._handle_eio_message ('123' , b'foo' )
953+ assert s ._binary_packet ['123' ] is not None
954+ await s .disconnect ('1' )
955+ s .eio .send .assert_any_await ('123' , '1' )
956+ assert '123' not in s ._binary_packet
957+
926958 async def test_namespace_handler (self , eio ):
927959 eio .return_value .send = mock .AsyncMock ()
928960 result = {}
0 commit comments