Skip to content

Commit 0d2e246

Browse files
committed
Various fixes for the compliance test suite.
1 parent 8315d3c commit 0d2e246

File tree

7 files changed

+54
-25
lines changed

7 files changed

+54
-25
lines changed

compliance/README.rst

+12-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ To test the servers:
3838
crossbario/autobahn-testsuite \
3939
wstest --mode fuzzingclient --spec /config/fuzzingclient.json
4040
41-
$ open reports/servers/index.html
41+
$ open compliance/reports/servers/index.html
4242
4343
To test the clients:
4444

@@ -54,7 +54,7 @@ To test the clients:
5454
$ PYTHONPATH=src python compliance/asyncio/client.py
5555
$ PYTHONPATH=src python compliance/sync/client.py
5656
57-
$ open reports/clients/index.html
57+
$ open compliance/reports/clients/index.html
5858
5959
Conformance notes
6060
-----------------
@@ -67,6 +67,13 @@ In 3.2, 3.3, 4.1.3, 4.1.4, 4.2.3, 4.2.4, and 5.15 websockets notices the
6767
protocol error and closes the connection at the library level before the
6868
application gets a chance to echo the previous frame.
6969

70-
In 6.4.3 and 6.4.4, even though it uses an incremental decoder, websockets
71-
doesn't notice the invalid utf-8 fast enough to get a "Strict" pass. These tests
72-
are more strict than the RFC.
70+
In 6.4.1, 6.4.2, 6.4.3, and 6.4.4, even though it uses an incremental decoder,
71+
websockets doesn't notice the invalid utf-8 fast enough to get a "Strict" pass.
72+
These tests are more strict than the RFC.
73+
74+
Test case 7.1.5 fails because websockets treats closing the connection in the
75+
middle of a fragmented message as a protocol error. As a consequence, it sends
76+
a close frame with code 1002. The test suite expects a close frame with code
77+
1000, echoing the close code that it sent. This isn't required. RFC 6455 states
78+
that "the endpoint typically echos the status code it received", which leaves
79+
the possibility to send a close frame with a different status code.

compliance/asyncio/client.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
logging.basicConfig(level=logging.WARNING)
1010

11-
SERVER = "ws://127.0.0.1:9001"
11+
SERVER = "ws://localhost:9001"
12+
13+
AGENT = "websockets.asyncio"
1214

1315

1416
async def get_case_count():
@@ -18,16 +20,21 @@ async def get_case_count():
1820

1921
async def run_case(case):
2022
async with connect(
21-
f"{SERVER}/runCase?case={case}",
22-
user_agent_header="websockets.asyncio",
23+
f"{SERVER}/runCase?case={case}&agent={AGENT}",
2324
max_size=2**25,
2425
) as ws:
25-
async for msg in ws:
26-
await ws.send(msg)
26+
try:
27+
async for msg in ws:
28+
await ws.send(msg)
29+
except WebSocketException:
30+
pass
2731

2832

2933
async def update_reports():
30-
async with connect(f"{SERVER}/updateReports", open_timeout=60):
34+
async with connect(
35+
f"{SERVER}/updateReports?agent={AGENT}",
36+
open_timeout=60,
37+
):
3138
pass
3239

3340

@@ -43,7 +50,7 @@ async def main():
4350
print(f"FAIL: {type(exc).__name__}: {exc}")
4451
else:
4552
print("OK")
46-
print("Ran {cases} test cases")
53+
print(f"Ran {cases} test cases")
4754
await update_reports()
4855
print("Updated reports")
4956

compliance/asyncio/server.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from websockets.asyncio.server import serve
5+
from websockets.exceptions import WebSocketException
56

67

78
logging.basicConfig(level=logging.WARNING)
@@ -10,8 +11,11 @@
1011

1112

1213
async def echo(ws):
13-
async for msg in ws:
14-
await ws.send(msg)
14+
try:
15+
async for msg in ws:
16+
await ws.send(msg)
17+
except WebSocketException:
18+
pass
1519

1620

1721
async def main():

compliance/config/fuzzingclient.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}, {
66
"url": "ws://host.docker.internal:9003"
77
}],
8-
"outdir": "./reports/servers",
8+
"outdir": "/reports/servers",
99
"cases": ["*"],
1010
"exclude-cases": []
1111
}

compliance/config/fuzzingserver.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{
33
"url": "ws://localhost:9001",
4-
"outdir": "./reports/clients",
4+
"outdir": "/reports/clients",
55
"cases": ["*"],
66
"exclude-cases": []
77
}

compliance/sync/client.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
logging.basicConfig(level=logging.WARNING)
99

10-
SERVER = "ws://127.0.0.1:9001"
10+
SERVER = "ws://localhost:9001"
11+
12+
AGENT = "websockets.sync"
1113

1214

1315
def get_case_count():
@@ -17,16 +19,21 @@ def get_case_count():
1719

1820
def run_case(case):
1921
with connect(
20-
f"{SERVER}/runCase?case={case}",
21-
user_agent_header="websockets.sync",
22+
f"{SERVER}/runCase?case={case}&agent={AGENT}",
2223
max_size=2**25,
2324
) as ws:
24-
for msg in ws:
25-
ws.send(msg)
25+
try:
26+
for msg in ws:
27+
ws.send(msg)
28+
except WebSocketException:
29+
pass
2630

2731

2832
def update_reports():
29-
with connect(f"{SERVER}/updateReports", open_timeout=60):
33+
with connect(
34+
f"{SERVER}/updateReports?agent={AGENT}",
35+
open_timeout=60,
36+
):
3037
pass
3138

3239

@@ -42,7 +49,7 @@ def main():
4249
print(f"FAIL: {type(exc).__name__}: {exc}")
4350
else:
4451
print("OK")
45-
print("Ran {cases} test cases")
52+
print(f"Ran {cases} test cases")
4653
update_reports()
4754
print("Updated reports")
4855

compliance/sync/server.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from websockets.exceptions import WebSocketException
34
from websockets.sync.server import serve
45

56

@@ -9,8 +10,11 @@
910

1011

1112
def echo(ws):
12-
for msg in ws:
13-
ws.send(msg)
13+
try:
14+
for msg in ws:
15+
ws.send(msg)
16+
except WebSocketException:
17+
pass
1418

1519

1620
def main():

0 commit comments

Comments
 (0)