Skip to content

Add test for frame spillover issue (#218, #230) #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ language: python

python:
- 2.7
- 3.5
- 3.6
- 3.7
- 3.8
- 3.9


before_install:
- sudo apt-get install python-dev libevent-dev
- pip install Cython
Expand Down
22 changes: 22 additions & 0 deletions test/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import struct

try:
from io import BytesIO
from unittest.mock import MagicMock, call, patch
except ImportError:
from StringIO import StringIO as BytesIO
from mock import MagicMock, call, patch


from ws4py.framing import Frame, \
OPCODE_CONTINUATION, OPCODE_TEXT, \
OPCODE_BINARY, OPCODE_CLOSE, OPCODE_PING, OPCODE_PONG
Expand Down Expand Up @@ -180,6 +183,25 @@ def test_sending_ping(self):
ws.ping("hello")
m.sendall.assert_called_once_with(tm)

def test_spill_frame(self):
data = b"hello"
buf = BytesIO(data + b"spillover")

sock = MagicMock()
sock._ssl = object() # for WebSocket._is_secure logic
sock.recv.side_effect = buf.read
sock.pending.side_effect = lambda: buf.tell() < len(buf.getvalue())

ws = WebSocket(sock=sock)
ws.stream = MagicMock()

self.assertTrue(ws._is_secure)

ws.reading_buffer_size = len(data)
ws.once()

ws.stream.parser.send.assert_called_once_with(data)


@patch("ws4py.websocket.Heartbeat")
def test_run(self, mocker):
Expand Down