aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_websockets.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-17 14:29:20 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-17 14:29:20 +1200
commit7defb5be862a4251da9d7c530593f7e9be3e739e (patch)
tree3a97090f07410a9457a8eba64764a9af986f9999 /test/test_websockets.py
parent488c25d812a321f5a03253b62ab33b61ecc13de1 (diff)
downloadmitmproxy-7defb5be862a4251da9d7c530593f7e9be3e739e.tar.gz
mitmproxy-7defb5be862a4251da9d7c530593f7e9be3e739e.tar.bz2
mitmproxy-7defb5be862a4251da9d7c530593f7e9be3e739e.zip
websockets: more whitespace, WebSocketFrame -> Frame
Diffstat (limited to 'test/test_websockets.py')
-rw-r--r--test/test_websockets.py45
1 files changed, 26 insertions, 19 deletions
diff --git a/test/test_websockets.py b/test/test_websockets.py
index 951aa41f..d1753638 100644
--- a/test/test_websockets.py
+++ b/test/test_websockets.py
@@ -5,6 +5,7 @@ from netlib.websockets import websockets as ws
import os
from nose.tools import raises
+
class TestWebSockets(test.ServerTestBase):
handler = impl.WebSocketsEchoHandler
@@ -22,9 +23,12 @@ class TestWebSockets(test.ServerTestBase):
self.echo("hello I'm the client")
def test_frame_sizes(self):
- small_msg = self.random_bytes(100) # length can fit in the the 7 bit payload length
- medium_msg = self.random_bytes(50000) # 50kb, sligthly larger than can fit in a 7 bit int
- large_msg = self.random_bytes(150000) # 150kb, slightly larger than can fit in a 16 bit int
+ # length can fit in the the 7 bit payload length
+ small_msg = self.random_bytes(100)
+ # 50kb, sligthly larger than can fit in a 7 bit int
+ medium_msg = self.random_bytes(50000)
+ # 150kb, slightly larger than can fit in a 16 bit int
+ large_msg = self.random_bytes(150000)
self.echo(small_msg)
self.echo(medium_msg)
@@ -33,51 +37,54 @@ class TestWebSockets(test.ServerTestBase):
def test_default_builder(self):
"""
default builder should always generate valid frames
- """
+ """
msg = self.random_bytes()
- client_frame = ws.WebSocketsFrame.default(msg, from_client = True)
+ client_frame = ws.Frame.default(msg, from_client = True)
assert client_frame.is_valid()
- server_frame = ws.WebSocketsFrame.default(msg, from_client = False)
+ server_frame = ws.Frame.default(msg, from_client = False)
assert server_frame.is_valid()
def test_serialization_bijection(self):
"""
- Ensure that various frame types can be serialized/deserialized back and forth
- between to_bytes() and from_bytes()
- """
+ Ensure that various frame types can be serialized/deserialized back
+ and forth between to_bytes() and from_bytes()
+ """
for is_client in [True, False]:
- for num_bytes in [100, 50000, 150000]:
- frame = ws.WebSocketsFrame.default(self.random_bytes(num_bytes), is_client)
- assert frame == ws.WebSocketsFrame.from_bytes(frame.to_bytes())
+ for num_bytes in [100, 50000, 150000]:
+ frame = ws.Frame.default(
+ self.random_bytes(num_bytes), is_client
+ )
+ assert frame == ws.Frame.from_bytes(frame.to_bytes())
bytes = b'\x81\x11cba'
- assert ws.WebSocketsFrame.from_bytes(bytes).to_bytes() == bytes
+ assert ws.Frame.from_bytes(bytes).to_bytes() == bytes
@raises(ws.WebSocketFrameValidationException)
def test_safe_to_bytes(self):
- frame = ws.WebSocketsFrame.default(self.random_bytes(8))
- frame.actual_payload_length = 1 #corrupt the frame
+ frame = ws.Frame.default(self.random_bytes(8))
+ frame.actual_payload_length = 1 # corrupt the frame
frame.safe_to_bytes()
class BadHandshakeHandler(impl.WebSocketsEchoHandler):
def handshake(self):
client_hs = ws.read_handshake(self.rfile.read, 1)
- key = ws.process_handshake_from_client(client_hs)
- response = ws.create_server_handshake("malformed_key")
+ ws.process_handshake_from_client(client_hs)
+ response = ws.create_server_handshake("malformed_key")
self.wfile.write(response)
self.wfile.flush()
self.handshake_done = True
+
class TestBadHandshake(test.ServerTestBase):
"""
Ensure that the client disconnects if the server handshake is malformed
- """
+ """
handler = BadHandshakeHandler
@raises(tcp.NetLibDisconnect)
def test(self):
client = impl.WebSocketsClient(("127.0.0.1", self.port))
client.connect()
- client.send_message("hello") \ No newline at end of file
+ client.send_message("hello")