Skip to content
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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: python

python:
- 2.7
- 3.3
- 3.5

before_install:
Expand Down
24 changes: 24 additions & 0 deletions test/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import socket
import struct

try:
from io import BytesIO
except ImportError:
from StringIO import StringIO as BytesIO

from mock import MagicMock, call, patch

from ws4py.framing import Frame, \
Expand Down Expand Up @@ -177,6 +182,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)


if __name__ == '__main__':
suite = unittest.TestSuite()
Expand Down