summaryrefslogtreecommitdiffhomepage
path: root/test/test_node_websockets.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2019-11-13 18:11:24 +0300
committerAndrei Zeliankou <zelenkov@nginx.com>2019-11-13 18:11:24 +0300
commit5452ee458d2c764569213266362fb636114adbc2 (patch)
treea3fa05f63f141b94e40a43e9c93061c4dd7afe70 /test/test_node_websockets.py
parent45d75ee2cb33d38f64ca2ac5d871fa0cc2f1bcde (diff)
downloadunit-5452ee458d2c764569213266362fb636114adbc2.tar.gz
unit-5452ee458d2c764569213266362fb636114adbc2.tar.bz2
Tests: fixed websocket tests.
Diffstat (limited to '')
-rw-r--r--test/test_node_websockets.py43
1 files changed, 14 insertions, 29 deletions
diff --git a/test/test_node_websockets.py b/test/test_node_websockets.py
index b24bee75..bb189552 100644
--- a/test/test_node_websockets.py
+++ b/test/test_node_websockets.py
@@ -198,16 +198,14 @@ class TestNodeWebsockets(TestApplicationNode):
): # FAIL https://tools.ietf.org/html/rfc6455#section-4.2.1
self.load('websockets/mirror')
- key = self.ws.key()
resp = self.get(
headers={
'Host': 'localhost',
'Connection': 'Upgrade',
- 'Sec-WebSocket-Key': key,
+ 'Sec-WebSocket-Key': self.ws.key(),
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
- read_timeout=1,
)
self.assertEqual(resp['status'], 400, 'upgrade absent')
@@ -215,18 +213,17 @@ class TestNodeWebsockets(TestApplicationNode):
def test_node_websockets_handshake_case_insensitive(self):
self.load('websockets/mirror')
- key = self.ws.key()
- resp = self.get(
+ resp, sock, _ = self.ws.upgrade(
headers={
'Host': 'localhost',
'Upgrade': 'WEBSOCKET',
'Connection': 'UPGRADE',
- 'Sec-WebSocket-Key': key,
+ 'Sec-WebSocket-Key': self.ws.key(),
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
- },
- read_timeout=1,
+ }
)
+ sock.close()
self.assertEqual(resp['status'], 101, 'status')
@@ -234,16 +231,14 @@ class TestNodeWebsockets(TestApplicationNode):
def test_node_websockets_handshake_connection_absent(self): # FAIL
self.load('websockets/mirror')
- key = self.ws.key()
resp = self.get(
headers={
'Host': 'localhost',
'Upgrade': 'websocket',
- 'Sec-WebSocket-Key': key,
+ 'Sec-WebSocket-Key': self.ws.key(),
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
- read_timeout=1,
)
self.assertEqual(resp['status'], 400, 'status')
@@ -251,16 +246,14 @@ class TestNodeWebsockets(TestApplicationNode):
def test_node_websockets_handshake_version_absent(self):
self.load('websockets/mirror')
- key = self.ws.key()
resp = self.get(
headers={
'Host': 'localhost',
'Upgrade': 'websocket',
'Connection': 'Upgrade',
- 'Sec-WebSocket-Key': key,
+ 'Sec-WebSocket-Key': self.ws.key(),
'Sec-WebSocket-Protocol': 'chat',
},
- read_timeout=1,
)
self.assertEqual(resp['status'], 426, 'status')
@@ -278,7 +271,6 @@ class TestNodeWebsockets(TestApplicationNode):
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
- read_timeout=1,
)
self.assertEqual(resp['status'], 400, 'key length')
@@ -293,7 +285,6 @@ class TestNodeWebsockets(TestApplicationNode):
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
- read_timeout=1,
)
self.assertEqual(
@@ -303,17 +294,15 @@ class TestNodeWebsockets(TestApplicationNode):
def test_node_websockets_handshake_method_invalid(self):
self.load('websockets/mirror')
- key = self.ws.key()
resp = self.post(
headers={
'Host': 'localhost',
'Upgrade': 'websocket',
'Connection': 'Upgrade',
- 'Sec-WebSocket-Key': key,
+ 'Sec-WebSocket-Key': self.ws.key(),
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
- read_timeout=1,
)
self.assertEqual(resp['status'], 400, 'status')
@@ -321,18 +310,16 @@ class TestNodeWebsockets(TestApplicationNode):
def test_node_websockets_handshake_http_10(self):
self.load('websockets/mirror')
- key = self.ws.key()
resp = self.get(
headers={
'Host': 'localhost',
'Upgrade': 'websocket',
'Connection': 'Upgrade',
- 'Sec-WebSocket-Key': key,
+ 'Sec-WebSocket-Key': self.ws.key(),
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
http_10=True,
- read_timeout=1,
)
self.assertEqual(resp['status'], 400, 'status')
@@ -340,18 +327,16 @@ class TestNodeWebsockets(TestApplicationNode):
def test_node_websockets_handshake_uri_invalid(self):
self.load('websockets/mirror')
- key = self.ws.key()
resp = self.get(
headers={
'Host': 'localhost',
'Upgrade': 'websocket',
'Connection': 'Upgrade',
- 'Sec-WebSocket-Key': key,
+ 'Sec-WebSocket-Key': self.ws.key(),
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
url='!',
- read_timeout=1,
)
self.assertEqual(resp['status'], 400, 'status')
@@ -360,16 +345,16 @@ class TestNodeWebsockets(TestApplicationNode):
self.load('websockets/mirror')
key = self.ws.key()
- resp = self.get(
+ resp, sock, _ = self.ws.upgrade(
headers={
'Host': 'localhost',
'Upgrade': 'websocket',
'Connection': 'Upgrade',
'Sec-WebSocket-Key': key,
'Sec-WebSocket-Version': 13,
- },
- read_timeout=1,
+ }
)
+ sock.close()
self.assertEqual(resp['status'], 101, 'status')
self.assertEqual(resp['headers']['Upgrade'], 'websocket', 'upgrade')
@@ -1166,7 +1151,7 @@ class TestNodeWebsockets(TestApplicationNode):
sock.close()
- # 7_3_1 # FAIL
+ # 7_3_1
_, sock, _ = self.ws.upgrade()