FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

TST: Fix test_websocket_rejects_cross_origin on latest tornado by QuLogic · Pull Request #32516 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
32 changes: 15 additions & 17 deletions lib/matplotlib/tests/test_backend_webagg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,23 @@ def test_toolbar_button_dispatch_allowlist():
assert canvas.toolbar.method_calls == []


@pytest.mark.parametrize("host, origin, allowed", [
("localhost:8988", "http://localhost:8988", True),
("localhost:8988", "http://evil.com", False),
("localhost:8988", "http://127.0.0.1:8988", False),
("localhost:8988", "http://[::1]:8988", False),
("127.0.0.1:8988", "http://127.0.0.1:8988", True),
("127.0.0.1:8988", "http://localhost:8988", False),
("127.0.0.1:8988", "http://[::1]:8988", False),
("[::1]:8988", "http://[::1]:8988", True),
("[::1]:8988", "http://[::2]:8988", False),
("[::1]:8988", "http://localhost:8988", False),
("[::1]:8988", "http://evil.com", False),
@pytest.mark.parametrize("host, origin", [
("localhost:8988", "http://example.com"),
("localhost:8988", "http://127.0.0.1:8988"),
("localhost:8988", "http://[::1]:8988"),
("127.0.0.1:8988", "http://localhost:8988"),
("127.0.0.1:8988", "http://[::1]:8988"),
("[::1]:8988", "http://[::2]:8988"),
("[::1]:8988", "http://localhost:8988"),
("[::1]:8988", "http://example.com"),
])
def test_websocket_rejects_cross_origin(host, origin, allowed):
def test_websocket_rejects_cross_origin(host, origin):
"""Verify Tornado's default check_origin rejects cross-origin requests."""
pytest.importorskip("tornado")
from matplotlib.backends.backend_webagg import WebAggApplication

ws = WebAggApplication.WebSocket.__new__(WebAggApplication.WebSocket)
ws.request = MagicMock()
ws.request.headers = {"Host": host}
assert ws.check_origin(origin) is allowed
app = WebAggApplication()
request = MagicMock()
request.headers = {"Host": host}
ws = WebAggApplication.WebSocket(app, request)
assert not ws.check_origin(origin) # Not allowed.
Loading

Back | FazBrowse Home | New Git URL