summaryrefslogtreecommitdiffhomepage
path: root/test/test_java_websockets.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_java_websockets.py')
-rw-r--r--test/test_java_websockets.py227
1 files changed, 96 insertions, 131 deletions
diff --git a/test/test_java_websockets.py b/test/test_java_websockets.py
index d78f7263..7e6d82e8 100644
--- a/test/test_java_websockets.py
+++ b/test/test_java_websockets.py
@@ -1,7 +1,10 @@
import struct
import time
-import unittest
+import pytest
+
+from conftest import option
+from conftest import skip_alert
from unit.applications.lang.java import TestApplicationJava
from unit.applications.websockets import TestApplicationWebsocket
@@ -11,23 +14,17 @@ class TestJavaWebsockets(TestApplicationJava):
ws = TestApplicationWebsocket()
- def setUp(self):
- super().setUp()
+ def setup_method(self):
+ super().setup_method()
- self.assertIn(
- 'success',
- self.conf(
- {'http': {'websocket': {'keepalive_interval': 0}}}, 'settings'
- ),
- 'clear keepalive_interval',
- )
+ assert 'success' in self.conf(
+ {'http': {'websocket': {'keepalive_interval': 0}}}, 'settings'
+ ), 'clear keepalive_interval'
- self.skip_alerts.extend(
- [r'socket close\(\d+\) failed']
- )
+ skip_alert(r'socket close\(\d+\) failed')
def close_connection(self, sock):
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
+ assert self.recvall(sock, read_timeout=0.1) == b'', 'empty soc'
self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
@@ -36,9 +33,9 @@ class TestJavaWebsockets(TestApplicationJava):
def check_close(self, sock, code=1000, no_close=False):
frame = self.ws.frame_read(sock)
- self.assertEqual(frame['fin'], True, 'close fin')
- self.assertEqual(frame['opcode'], self.ws.OP_CLOSE, 'close opcode')
- self.assertEqual(frame['code'], code, 'close code')
+ assert frame['fin'] == True, 'close fin'
+ assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode'
+ assert frame['code'] == code, 'close code'
if not no_close:
sock.close()
@@ -49,9 +46,9 @@ class TestJavaWebsockets(TestApplicationJava):
else:
data = frame['data'].decode('utf-8')
- self.assertEqual(frame['fin'], fin, 'fin')
- self.assertEqual(frame['opcode'], opcode, 'opcode')
- self.assertEqual(data, payload, 'payload')
+ assert frame['fin'] == fin, 'fin'
+ assert frame['opcode'] == opcode, 'opcode'
+ assert data == payload, 'payload'
def test_java_websockets_handshake(self):
self.load('websockets_mirror')
@@ -59,14 +56,12 @@ class TestJavaWebsockets(TestApplicationJava):
resp, sock, key = self.ws.upgrade()
sock.close()
- self.assertEqual(resp['status'], 101, 'status')
- self.assertEqual(resp['headers']['Upgrade'], 'websocket', 'upgrade')
- self.assertEqual(
- resp['headers']['Connection'], 'Upgrade', 'connection'
- )
- self.assertEqual(
- resp['headers']['Sec-WebSocket-Accept'], self.ws.accept(key), 'key'
- )
+ assert resp['status'] == 101, 'status'
+ assert resp['headers']['Upgrade'] == 'websocket', 'upgrade'
+ assert resp['headers']['Connection'] == 'Upgrade', 'connection'
+ assert resp['headers']['Sec-WebSocket-Accept'] == self.ws.accept(
+ key
+ ), 'key'
def test_java_websockets_mirror(self):
self.load('websockets_mirror')
@@ -78,12 +73,12 @@ class TestJavaWebsockets(TestApplicationJava):
self.ws.frame_write(sock, self.ws.OP_TEXT, message)
frame = self.ws.frame_read(sock)
- self.assertEqual(message, frame['data'].decode('utf-8'), 'mirror')
+ assert message == frame['data'].decode('utf-8'), 'mirror'
self.ws.frame_write(sock, self.ws.OP_TEXT, message)
frame = self.ws.frame_read(sock)
- self.assertEqual(message, frame['data'].decode('utf-8'), 'mirror 2')
+ assert message == frame['data'].decode('utf-8'), 'mirror 2'
sock.close()
@@ -98,8 +93,8 @@ class TestJavaWebsockets(TestApplicationJava):
frame = self.ws.frame_read(sock)
- self.assertEqual(frame['opcode'], self.ws.OP_CLOSE, 'no mask opcode')
- self.assertEqual(frame['code'], 1002, 'no mask close code')
+ assert frame['opcode'] == self.ws.OP_CLOSE, 'no mask opcode'
+ assert frame['code'] == 1002, 'no mask close code'
sock.close()
@@ -116,11 +111,9 @@ class TestJavaWebsockets(TestApplicationJava):
frame = self.ws.frame_read(sock)
- self.assertEqual(
- message + ' ' + message,
- frame['data'].decode('utf-8'),
- 'mirror framing',
- )
+ assert message + ' ' + message == frame['data'].decode(
+ 'utf-8'
+ ), 'mirror framing'
sock.close()
@@ -136,20 +129,16 @@ class TestJavaWebsockets(TestApplicationJava):
frame = self.ws.frame_read(sock)
frame.pop('data')
- self.assertDictEqual(
- frame,
- {
- 'fin': True,
- 'rsv1': False,
- 'rsv2': False,
- 'rsv3': False,
- 'opcode': self.ws.OP_CLOSE,
- 'mask': 0,
- 'code': 1002,
- 'reason': 'Fragmented control frame',
- },
- 'close frame',
- )
+ assert frame == {
+ 'fin': True,
+ 'rsv1': False,
+ 'rsv2': False,
+ 'rsv3': False,
+ 'opcode': self.ws.OP_CLOSE,
+ 'mask': 0,
+ 'code': 1002,
+ 'reason': 'Fragmented control frame',
+ }, 'close frame'
sock.close()
@@ -168,13 +157,13 @@ class TestJavaWebsockets(TestApplicationJava):
frame1 = self.ws.frame_read(sock1)
frame2 = self.ws.frame_read(sock2)
- self.assertEqual(message1, frame1['data'].decode('utf-8'), 'client 1')
- self.assertEqual(message2, frame2['data'].decode('utf-8'), 'client 2')
+ assert message1 == frame1['data'].decode('utf-8'), 'client 1'
+ assert message2 == frame2['data'].decode('utf-8'), 'client 2'
sock1.close()
sock2.close()
- @unittest.skip('not yet')
+ @pytest.mark.skip('not yet')
def test_java_websockets_handshake_upgrade_absent(
self
): # FAIL https://tools.ietf.org/html/rfc6455#section-4.2.1
@@ -190,7 +179,7 @@ class TestJavaWebsockets(TestApplicationJava):
},
)
- self.assertEqual(resp['status'], 400, 'upgrade absent')
+ assert resp['status'] == 400, 'upgrade absent'
def test_java_websockets_handshake_case_insensitive(self):
self.load('websockets_mirror')
@@ -207,9 +196,9 @@ class TestJavaWebsockets(TestApplicationJava):
)
sock.close()
- self.assertEqual(resp['status'], 101, 'status')
+ assert resp['status'] == 101, 'status'
- @unittest.skip('not yet')
+ @pytest.mark.skip('not yet')
def test_java_websockets_handshake_connection_absent(self): # FAIL
self.load('websockets_mirror')
@@ -223,7 +212,7 @@ class TestJavaWebsockets(TestApplicationJava):
},
)
- self.assertEqual(resp['status'], 400, 'status')
+ assert resp['status'] == 400, 'status'
def test_java_websockets_handshake_version_absent(self):
self.load('websockets_mirror')
@@ -238,9 +227,9 @@ class TestJavaWebsockets(TestApplicationJava):
},
)
- self.assertEqual(resp['status'], 426, 'status')
+ assert resp['status'] == 426, 'status'
- @unittest.skip('not yet')
+ @pytest.mark.skip('not yet')
def test_java_websockets_handshake_key_invalid(self):
self.load('websockets_mirror')
@@ -255,7 +244,7 @@ class TestJavaWebsockets(TestApplicationJava):
},
)
- self.assertEqual(resp['status'], 400, 'key length')
+ assert resp['status'] == 400, 'key length'
key = self.ws.key()
resp = self.get(
@@ -269,9 +258,7 @@ class TestJavaWebsockets(TestApplicationJava):
},
)
- self.assertEqual(
- resp['status'], 400, 'key double'
- ) # FAIL https://tools.ietf.org/html/rfc6455#section-11.3.1
+ assert resp['status'] == 400, 'key double' # FAIL https://tools.ietf.org/html/rfc6455#section-11.3.1
def test_java_websockets_handshake_method_invalid(self):
self.load('websockets_mirror')
@@ -287,7 +274,7 @@ class TestJavaWebsockets(TestApplicationJava):
},
)
- self.assertEqual(resp['status'], 400, 'status')
+ assert resp['status'] == 400, 'status'
def test_java_websockets_handshake_http_10(self):
self.load('websockets_mirror')
@@ -304,7 +291,7 @@ class TestJavaWebsockets(TestApplicationJava):
http_10=True,
)
- self.assertEqual(resp['status'], 400, 'status')
+ assert resp['status'] == 400, 'status'
def test_java_websockets_handshake_uri_invalid(self):
self.load('websockets_mirror')
@@ -321,7 +308,7 @@ class TestJavaWebsockets(TestApplicationJava):
url='!',
)
- self.assertEqual(resp['status'], 400, 'status')
+ assert resp['status'] == 400, 'status'
def test_java_websockets_protocol_absent(self):
self.load('websockets_mirror')
@@ -338,14 +325,12 @@ class TestJavaWebsockets(TestApplicationJava):
)
sock.close()
- self.assertEqual(resp['status'], 101, 'status')
- self.assertEqual(resp['headers']['Upgrade'], 'websocket', 'upgrade')
- self.assertEqual(
- resp['headers']['Connection'], 'Upgrade', 'connection'
- )
- self.assertEqual(
- resp['headers']['Sec-WebSocket-Accept'], self.ws.accept(key), 'key'
- )
+ assert resp['status'] == 101, 'status'
+ assert resp['headers']['Upgrade'] == 'websocket', 'upgrade'
+ assert resp['headers']['Connection'] == 'Upgrade', 'connection'
+ assert resp['headers']['Sec-WebSocket-Accept'] == self.ws.accept(
+ key
+ ), 'key'
# autobahn-testsuite
#
@@ -442,12 +427,12 @@ class TestJavaWebsockets(TestApplicationJava):
_, sock, _ = self.ws.upgrade()
self.ws.frame_write(sock, self.ws.OP_PONG, '')
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '2_7')
+ assert self.recvall(sock, read_timeout=0.1) == b'', '2_7'
# 2_8
self.ws.frame_write(sock, self.ws.OP_PONG, 'unsolicited pong payload')
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '2_8')
+ assert self.recvall(sock, read_timeout=0.1) == b'', '2_8'
# 2_9
@@ -487,7 +472,7 @@ class TestJavaWebsockets(TestApplicationJava):
self.close_connection(sock)
- @unittest.skip('not yet')
+ @pytest.mark.skip('not yet')
def test_java_websockets_3_1__3_7(self):
self.load('websockets_mirror')
@@ -513,7 +498,7 @@ class TestJavaWebsockets(TestApplicationJava):
self.check_close(sock, 1002, no_close=True)
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty 3_2')
+ assert self.recvall(sock, read_timeout=0.1) == b'', 'empty 3_2'
sock.close()
# 3_3
@@ -531,7 +516,7 @@ class TestJavaWebsockets(TestApplicationJava):
self.check_close(sock, 1002, no_close=True)
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty 3_3')
+ assert self.recvall(sock, read_timeout=0.1) == b'', 'empty 3_3'
sock.close()
# 3_4
@@ -549,7 +534,7 @@ class TestJavaWebsockets(TestApplicationJava):
self.check_close(sock, 1002, no_close=True)
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty 3_4')
+ assert self.recvall(sock, read_timeout=0.1) == b'', 'empty 3_4'
sock.close()
# 3_5
@@ -735,7 +720,7 @@ class TestJavaWebsockets(TestApplicationJava):
# 5_4
self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '5_4')
+ assert self.recvall(sock, read_timeout=0.1) == b'', '5_4'
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
frame = self.ws.frame_read(sock)
@@ -772,7 +757,7 @@ class TestJavaWebsockets(TestApplicationJava):
ping_payload = 'ping payload'
self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '5_7')
+ assert self.recvall(sock, read_timeout=0.1) == b'', '5_7'
self.ws.frame_write(sock, self.ws.OP_PING, ping_payload)
@@ -956,7 +941,7 @@ class TestJavaWebsockets(TestApplicationJava):
frame = self.ws.frame_read(sock)
self.check_frame(frame, True, self.ws.OP_PONG, 'pongme 2!')
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '5_20')
+ assert self.recvall(sock, read_timeout=0.1) == b'', '5_20'
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment5')
self.check_frame(
@@ -1089,7 +1074,7 @@ class TestJavaWebsockets(TestApplicationJava):
self.check_close(sock, no_close=True)
self.ws.frame_write(sock, self.ws.OP_PING, '')
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
+ assert self.recvall(sock, read_timeout=0.1) == b'', 'empty soc'
sock.close()
@@ -1101,7 +1086,7 @@ class TestJavaWebsockets(TestApplicationJava):
self.check_close(sock, no_close=True)
self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
+ assert self.recvall(sock, read_timeout=0.1) == b'', 'empty soc'
sock.close()
@@ -1114,7 +1099,7 @@ class TestJavaWebsockets(TestApplicationJava):
self.check_close(sock, no_close=True)
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2')
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
+ assert self.recvall(sock, read_timeout=0.1) == b'', 'empty soc'
sock.close()
@@ -1129,7 +1114,7 @@ class TestJavaWebsockets(TestApplicationJava):
self.recvall(sock, read_timeout=1)
self.ws.frame_write(sock, self.ws.OP_PING, '')
- self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
+ assert self.recvall(sock, read_timeout=0.1) == b'', 'empty soc'
sock.close()
@@ -1249,27 +1234,23 @@ class TestJavaWebsockets(TestApplicationJava):
self.ws.frame_write(sock, self.ws.OP_CLOSE, payload)
self.check_close(sock, 1002)
- def test_java_websockets_9_1_1__9_6_6(self):
- if not self.unsafe:
- self.skipTest("unsafe, long run")
+ def test_java_websockets_9_1_1__9_6_6(self, is_unsafe):
+ if not is_unsafe:
+ pytest.skip('unsafe, long run')
self.load('websockets_mirror')
- self.assertIn(
- 'success',
- self.conf(
- {
- 'http': {
- 'websocket': {
- 'max_frame_size': 33554432,
- 'keepalive_interval': 0,
- }
+ assert 'success' in self.conf(
+ {
+ 'http': {
+ 'websocket': {
+ 'max_frame_size': 33554432,
+ 'keepalive_interval': 0,
}
- },
- 'settings',
- ),
- 'increase max_frame_size and keepalive_interval',
- )
+ }
+ },
+ 'settings',
+ ), 'increase max_frame_size and keepalive_interval'
_, sock, _ = self.ws.upgrade()
@@ -1310,7 +1291,7 @@ class TestJavaWebsockets(TestApplicationJava):
check_payload(op_binary, 8 * 2 ** 20) # 9_2_5
check_payload(op_binary, 16 * 2 ** 20) # 9_2_6
- if self.system != 'Darwin' and self.system != 'FreeBSD':
+ if option.system != 'Darwin' and option.system != 'FreeBSD':
check_message(op_text, 64) # 9_3_1
check_message(op_text, 256) # 9_3_2
check_message(op_text, 2 ** 10) # 9_3_3
@@ -1366,13 +1347,9 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_max_frame_size(self):
self.load('websockets_mirror')
- self.assertIn(
- 'success',
- self.conf(
- {'http': {'websocket': {'max_frame_size': 100}}}, 'settings'
- ),
- 'configure max_frame_size',
- )
+ assert 'success' in self.conf(
+ {'http': {'websocket': {'max_frame_size': 100}}}, 'settings'
+ ), 'configure max_frame_size'
_, sock, _ = self.ws.upgrade()
@@ -1392,13 +1369,9 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_read_timeout(self):
self.load('websockets_mirror')
- self.assertIn(
- 'success',
- self.conf(
- {'http': {'websocket': {'read_timeout': 5}}}, 'settings'
- ),
- 'configure read_timeout',
- )
+ assert 'success' in self.conf(
+ {'http': {'websocket': {'read_timeout': 5}}}, 'settings'
+ ), 'configure read_timeout'
_, sock, _ = self.ws.upgrade()
@@ -1412,13 +1385,9 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_keepalive_interval(self):
self.load('websockets_mirror')
- self.assertIn(
- 'success',
- self.conf(
- {'http': {'websocket': {'keepalive_interval': 5}}}, 'settings'
- ),
- 'configure keepalive_interval',
- )
+ assert 'success' in self.conf(
+ {'http': {'websocket': {'keepalive_interval': 5}}}, 'settings'
+ ), 'configure keepalive_interval'
_, sock, _ = self.ws.upgrade()
@@ -1431,7 +1400,3 @@ class TestJavaWebsockets(TestApplicationJava):
self.check_frame(frame, True, self.ws.OP_PING, '') # PING frame
sock.close()
-
-
-if __name__ == '__main__':
- TestJavaWebsockets.main()