Skip to content
Browse files

control frame size is discovered at frame parsing and is handled as a…

…n error
  • Loading branch information...
1 parent 17810cd commit 9571b655f3e6d25e594292e652447784a7373613 @Lawouach committed Apr 10, 2012
Showing with 11 additions and 6 deletions.
  1. +8 −3 test/test_stream.py
  2. +3 −3 ws4py/streaming.py
View
11 test/test_stream.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import unittest
import os
+import struct
from ws4py.framing import Frame, \
OPCODE_CONTINUATION, OPCODE_TEXT, \
@@ -17,13 +18,17 @@ def test_empty_close_message(self):
self.assertEqual(type(s.closing), CloseControlMessage)
def test_too_large_close_message(self):
- f = Frame(opcode=OPCODE_CLOSE, body='*' * 330, fin=1, masking_key=os.urandom(4)).build()
+ payload = struct.pack("!H", 1000) + '*' * 330
+ f = Frame(opcode=OPCODE_CLOSE, body=payload, fin=1, masking_key=os.urandom(4)).build()
s = Stream()
+ self.assertEqual(len(s.errors), 0)
self.assertEqual(s.closing, None)
s.parser.send(f)
+ self.assertEqual(s.closing, None)
- self.assertEqual(type(s.closing), CloseControlMessage)
- self.assertEqual(s.closing.code, 1002)
+ self.assertEqual(len(s.errors), 1)
+ self.assertEqual(type(s.errors[0]), CloseControlMessage)
+ self.assertEqual(s.errors[0].code, 1002)
def test_ping_message_received(self):
msg = 'ping me'
View
6 ws4py/streaming.py
@@ -239,8 +239,6 @@ def receiver(self):
self.closing = CloseControlMessage(code=1000)
elif frame.payload_length == 1:
self.closing = CloseControlMessage(code=1002, reason='Payload has invalid length')
- elif frame.payload_length > 125:
- self.closing = CloseControlMessage(code=1002, reason='Payload was too large')
else:
try:
code = int(struct.unpack("!H", str(bytes[0:2]))[0])
@@ -276,8 +274,10 @@ def receiver(self):
except ProtocolException:
self.errors.append(CloseControlMessage(code=1002))
+ break
except FrameTooLargeException:
- self.errors.append(CloseControlMessage(code=1002))
+ self.errors.append(CloseControlMessage(code=1002, reason="Frame was too large"))
+ break
except StreamClosed:
running = False
break

0 comments on commit 9571b65

Please sign in to comment.
Something went wrong with that request. Please try again.