From 0febc6948c9fac7d666b35f1199672608956fa05 Mon Sep 17 00:00:00 2001 From: Ngo The Trung Date: Tue, 6 Jun 2017 11:36:07 +0800 Subject: [PATCH 1/3] Add test for frame spillover fix --- test/test_websocket.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test_websocket.py b/test/test_websocket.py index 96fb384..9f22242 100644 --- a/test/test_websocket.py +++ b/test/test_websocket.py @@ -177,6 +177,26 @@ def test_sending_ping(self): ws.ping("hello") m.sendall.assert_called_once_with(tm) + def test_spill_frame(self): + s = MagicMock() + m = MagicMock() + c = MagicMock() + recv = lambda size: b'a' * size + + with patch.multiple(m, recv=recv): + ws = WebSocket(sock=m) + sz = 20 + spill = 10 + proc = MagicMock(return_value=('a' * sz)) + pend = lambda: b'a' * spill + + with patch.multiple(ws, close=c, process=proc, _get_from_pending=pend): + ws.stream = s + ws.reading_buffer_size = sz + ws.once() + proc.assert_called_once_with(b'a' * sz) + self.assertEqual(len(ws.buf), spill) + if __name__ == '__main__': suite = unittest.TestSuite() From 2bf4d51c86b8d42d9cb2e605b13ffcd2ada66932 Mon Sep 17 00:00:00 2001 From: Chow Loong Jin Date: Tue, 6 Jun 2017 17:45:15 +0800 Subject: [PATCH 2/3] Make test_websocket.test_spill_frame more readable --- test/test_websocket.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/test/test_websocket.py b/test/test_websocket.py index 9f22242..501218d 100644 --- a/test/test_websocket.py +++ b/test/test_websocket.py @@ -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, \ @@ -178,24 +183,23 @@ def test_sending_ping(self): m.sendall.assert_called_once_with(tm) def test_spill_frame(self): - s = MagicMock() - m = MagicMock() - c = MagicMock() - recv = lambda size: b'a' * size - - with patch.multiple(m, recv=recv): - ws = WebSocket(sock=m) - sz = 20 - spill = 10 - proc = MagicMock(return_value=('a' * sz)) - pend = lambda: b'a' * spill - - with patch.multiple(ws, close=c, process=proc, _get_from_pending=pend): - ws.stream = s - ws.reading_buffer_size = sz - ws.once() - proc.assert_called_once_with(b'a' * sz) - self.assertEqual(len(ws.buf), spill) + 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__': From ad542c4f990a7cbff202b1b1c0e809fb471ca003 Mon Sep 17 00:00:00 2001 From: Chow Loong Jin Date: Wed, 21 Aug 2019 10:24:03 +0800 Subject: [PATCH 3/3] Drop python 3.3 from .travis.yml Travis has dropped support for Python 3.3, so drop it from .travis.yml so that builds succeed. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d345f1d..33b6e93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: python python: - 2.7 - - 3.3 - 3.5 before_install: