summaryrefslogtreecommitdiffhomepage
path: root/test
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
parent45d75ee2cb33d38f64ca2ac5d871fa0cc2f1bcde (diff)
downloadunit-5452ee458d2c764569213266362fb636114adbc2.tar.gz
unit-5452ee458d2c764569213266362fb636114adbc2.tar.bz2
Tests: fixed websocket tests.
Diffstat (limited to 'test')
-rw-r--r--test/test_java_websockets.py61
-rw-r--r--test/test_node_websockets.py43
-rw-r--r--test/unit/applications/websockets.py15
3 files changed, 38 insertions, 81 deletions
diff --git a/test/test_java_websockets.py b/test/test_java_websockets.py
index 33091705..d75ee3a6 100644
--- a/test/test_java_websockets.py
+++ b/test/test_java_websockets.py
@@ -179,18 +179,14 @@ class TestJavaWebsockets(TestApplicationJava):
): # FAIL https://tools.ietf.org/html/rfc6455#section-4.2.1
self.load('websockets_mirror')
- self.get()
-
- 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')
@@ -198,20 +194,17 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_handshake_case_insensitive(self):
self.load('websockets_mirror')
- self.get()
-
- 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')
@@ -219,18 +212,14 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_handshake_connection_absent(self): # FAIL
self.load('websockets_mirror')
- self.get()
-
- 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')
@@ -238,18 +227,14 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_handshake_version_absent(self):
self.load('websockets_mirror')
- self.get()
-
- 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')
@@ -258,8 +243,6 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_handshake_key_invalid(self):
self.load('websockets_mirror')
- self.get()
-
resp = self.get(
headers={
'Host': 'localhost',
@@ -269,7 +252,6 @@ class TestJavaWebsockets(TestApplicationJava):
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
- read_timeout=1,
)
self.assertEqual(resp['status'], 400, 'key length')
@@ -284,7 +266,6 @@ class TestJavaWebsockets(TestApplicationJava):
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
},
- read_timeout=1,
)
self.assertEqual(
@@ -294,19 +275,15 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_handshake_method_invalid(self):
self.load('websockets_mirror')
- self.get()
-
- 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')
@@ -314,20 +291,16 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_handshake_http_10(self):
self.load('websockets_mirror')
- self.get()
-
- 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')
@@ -335,20 +308,16 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_handshake_uri_invalid(self):
self.load('websockets_mirror')
- self.get()
-
- 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')
@@ -356,19 +325,17 @@ class TestJavaWebsockets(TestApplicationJava):
def test_java_websockets_protocol_absent(self):
self.load('websockets_mirror')
- self.get()
-
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')
@@ -1165,7 +1132,7 @@ class TestJavaWebsockets(TestApplicationJava):
sock.close()
- # 7_3_1 # FAIL
+ # 7_3_1
_, sock, _ = self.ws.upgrade()
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()
diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py
index 5f78498c..ef16f433 100644
--- a/test/unit/applications/websockets.py
+++ b/test/unit/applications/websockets.py
@@ -31,17 +31,22 @@ class TestApplicationWebsocket(TestApplicationProto):
sha1 = hashlib.sha1((key + GUID).encode()).digest()
return base64.b64encode(sha1).decode()
- def upgrade(self):
- key = self.key()
- _, sock = self.get(
- headers={
+ def upgrade(self, headers=None):
+ key = None
+
+ if headers is None:
+ key = self.key()
+ headers = {
'Host': 'localhost',
'Upgrade': 'websocket',
'Connection': 'Upgrade',
'Sec-WebSocket-Key': key,
'Sec-WebSocket-Protocol': 'chat',
'Sec-WebSocket-Version': 13,
- },
+ }
+
+ _, sock = self.get(
+ headers=headers,
no_recv=True,
start=True,
)