Skip to content

Commit 3bd2920

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR matplotlib#32516: TST: Fix test_websocket_rejects_cross_origin on latest tornado
1 parent 4d47326 commit 3bd2920

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

‎lib/matplotlib/tests/test_backend_webagg.py‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,23 @@ def test_toolbar_button_dispatch_allowlist():
5656
assert canvas.toolbar.method_calls == []
5757

5858

59-
@pytest.mark.parametrize("host, origin, allowed", [
60-
("localhost:8988", "http://localhost:8988", True),
61-
("localhost:8988", "http://evil.com", False),
62-
("localhost:8988", "http://127.0.0.1:8988", False),
63-
("localhost:8988", "http://[::1]:8988", False),
64-
("127.0.0.1:8988", "http://127.0.0.1:8988", True),
65-
("127.0.0.1:8988", "http://localhost:8988", False),
66-
("127.0.0.1:8988", "http://[::1]:8988", False),
67-
("[::1]:8988", "http://[::1]:8988", True),
68-
("[::1]:8988", "http://[::2]:8988", False),
69-
("[::1]:8988", "http://localhost:8988", False),
70-
("[::1]:8988", "http://evil.com", False),
59+
@pytest.mark.parametrize("host, origin", [
60+
("localhost:8988", "http://example.com"),
61+
("localhost:8988", "http://127.0.0.1:8988"),
62+
("localhost:8988", "http://[::1]:8988"),
63+
("127.0.0.1:8988", "http://localhost:8988"),
64+
("127.0.0.1:8988", "http://[::1]:8988"),
65+
("[::1]:8988", "http://[::2]:8988"),
66+
("[::1]:8988", "http://localhost:8988"),
67+
("[::1]:8988", "http://example.com"),
7168
])
72-
def test_websocket_rejects_cross_origin(host, origin, allowed):
69+
def test_websocket_rejects_cross_origin(host, origin):
7370
"""Verify Tornado's default check_origin rejects cross-origin requests."""
7471
pytest.importorskip("tornado")
7572
from matplotlib.backends.backend_webagg import WebAggApplication
7673

77-
ws = WebAggApplication.WebSocket.__new__(WebAggApplication.WebSocket)
78-
ws.request = MagicMock()
79-
ws.request.headers = {"Host": host}
80-
assert ws.check_origin(origin) is allowed
74+
app = WebAggApplication()
75+
request = MagicMock()
76+
request.headers = {"Host": host}
77+
ws = WebAggApplication.WebSocket(app, request)
78+
assert not ws.check_origin(origin) # Not allowed.

0 commit comments

Comments
 (0)