File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99from ws4py .messaging import CloseControlMessage
1010
1111class WSStreamTest (unittest .TestCase ):
12- def test_close_message_received (self ):
12+ def test_empty_close_message (self ):
1313 f = Frame (opcode = OPCODE_CLOSE , body = '' , fin = 1 ).build ()
1414 s = Stream ()
1515 self .assertEqual (s .closing , None )
1616 s .parser .send (f )
1717 self .assertEqual (type (s .closing ), CloseControlMessage )
1818
19+ def test_too_large_close_message (self ):
20+ f = Frame (opcode = OPCODE_CLOSE , body = '*' * 330 , fin = 1 ).build ()
21+ s = Stream ()
22+ self .assertEqual (s .closing , None )
23+ s .parser .send (f )
24+ self .assertEqual (s .closing , None )
25+ self .assertEqual (len (s .errors ), 1 )
26+ self .assertEqual (type (s .errors [0 ]), CloseControlMessage )
27+ self .assertEqual (s .errors [0 ].code , 1002 )
28+
1929 def test_ping_message_received (self ):
2030 msg = 'ping me'
2131 f = Frame (opcode = OPCODE_PING , body = msg , fin = 1 ).build ()
Original file line number Diff line number Diff line change @@ -215,9 +215,9 @@ def receiver(self):
215215 elif frame .opcode == OPCODE_CLOSE :
216216 code = 1000
217217 reason = ""
218- if len ( bytes ) == 0 :
218+ if frame . payload_length == 0 :
219219 self .closing = CloseControlMessage (code = 1000 )
220- elif 1 < len ( bytes ) < 126 :
220+ elif 1 < frame . payload_length < 126 :
221221 code = struct .unpack ("!H" , str (bytes [0 :2 ]))[0 ]
222222 try :
223223 code = int (code )
@@ -239,8 +239,6 @@ def receiver(self):
239239 code = 1007
240240 reason = ''
241241 self .closing = CloseControlMessage (code = code , reason = reason )
242- else :
243- self .errors .append (CloseControlMessage (code = 1002 ))
244242
245243 elif frame .opcode == OPCODE_PING :
246244 self .pings .append (PingControlMessage (bytes ))
You can’t perform that action at this time.
0 commit comments