Skip to content

Commit fc3a6af

Browse files
hyperairNgo The Trungauvipy
authored
Add test for frame spillover issue (#218, #230) (#220)
* Add test for frame spillover fix * Make test_websocket.test_spill_frame more readable --------- Signed-off-by: Asif Saif Uddin <[email protected]> Co-authored-by: Ngo The Trung <[email protected]> Co-authored-by: Asif Saif Uddin <[email protected]>
1 parent a4b059c commit fc3a6af

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ language: python
22

33
python:
44
- 2.7
5+
- 3.5
56
- 3.6
67
- 3.7
78
- 3.8
89
- 3.9
910

11+
1012
before_install:
1113
- sudo apt-get install python-dev libevent-dev
1214
- pip install Cython

test/test_websocket.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import struct
66

77
try:
8+
from io import BytesIO
89
from unittest.mock import MagicMock, call, patch
910
except ImportError:
11+
from StringIO import StringIO as BytesIO
1012
from mock import MagicMock, call, patch
1113

14+
1215
from ws4py.framing import Frame, \
1316
OPCODE_CONTINUATION, OPCODE_TEXT, \
1417
OPCODE_BINARY, OPCODE_CLOSE, OPCODE_PING, OPCODE_PONG
@@ -180,6 +183,25 @@ def test_sending_ping(self):
180183
ws.ping("hello")
181184
m.sendall.assert_called_once_with(tm)
182185

186+
def test_spill_frame(self):
187+
data = b"hello"
188+
buf = BytesIO(data + b"spillover")
189+
190+
sock = MagicMock()
191+
sock._ssl = object() # for WebSocket._is_secure logic
192+
sock.recv.side_effect = buf.read
193+
sock.pending.side_effect = lambda: buf.tell() < len(buf.getvalue())
194+
195+
ws = WebSocket(sock=sock)
196+
ws.stream = MagicMock()
197+
198+
self.assertTrue(ws._is_secure)
199+
200+
ws.reading_buffer_size = len(data)
201+
ws.once()
202+
203+
ws.stream.parser.send.assert_called_once_with(data)
204+
183205

184206
@patch("ws4py.websocket.Heartbeat")
185207
def test_run(self, mocker):

0 commit comments

Comments
 (0)