Skip to content

Commit 5e621a2

Browse files
committed
update domain matching tests for Werkzeug 3.2
1 parent 798e006 commit 5e621a2

3 files changed

Lines changed: 69 additions & 28 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ exclude = [
104104
[tool.uv]
105105
default-groups = ["dev", "pre-commit", "tests", "typing"]
106106

107+
[tool.uv.sources]
108+
werkzeug = { path = "../werkzeug" }
109+
107110
[tool.pytest.ini_options]
108111
testpaths = ["tests"]
109112
filterwarnings = [

tests/test_basic.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import gc
2+
import importlib.metadata
23
import re
34
import typing as t
45
import uuid
5-
import warnings
66
import weakref
77
from contextlib import nullcontext
88
from datetime import datetime
@@ -1491,20 +1491,22 @@ def test_request_locals():
14911491
assert not flask.g
14921492

14931493

1494+
werkzeug_3_2 = importlib.metadata.version("werkzeug") >= "3.2."
1495+
1496+
14941497
@pytest.mark.parametrize(
1495-
("subdomain_matching", "host_matching", "expect_base", "expect_abc", "expect_xyz"),
1498+
("subdomain_matching", "host_matching", "expect_subdomain", "expect_host"),
14961499
[
1497-
(False, False, "default", "default", "default"),
1498-
(True, False, "default", "abc", "<invalid>"),
1499-
(False, True, "default", "abc", "default"),
1500+
(False, False, "default", "default"),
1501+
(True, False, "abc", "<invalid>"),
1502+
(False, True, "abc", "default"),
15001503
],
15011504
)
15021505
def test_server_name_matching(
15031506
subdomain_matching: bool,
15041507
host_matching: bool,
1505-
expect_base: str,
1506-
expect_abc: str,
1507-
expect_xyz: str,
1508+
expect_subdomain: str,
1509+
expect_host: str,
15081510
) -> None:
15091511
app = flask.Flask(
15101512
__name__,
@@ -1522,15 +1524,18 @@ def index(name: str) -> str:
15221524
client = app.test_client()
15231525

15241526
r = client.get(base_url="http://example.test")
1525-
assert r.text == expect_base
1527+
assert r.text == "default"
15261528

15271529
r = client.get(base_url="http://abc.example.test")
1528-
assert r.text == expect_abc
1530+
assert r.text == expect_subdomain
15291531

15301532
with pytest.warns() if subdomain_matching else nullcontext():
15311533
r = client.get(base_url="http://xyz.other.test")
15321534

1533-
assert r.text == expect_xyz
1535+
if werkzeug_3_2:
1536+
assert r.text == "default"
1537+
else:
1538+
assert r.text == expect_host
15341539

15351540

15361541
def test_server_name_subdomain():
@@ -1566,12 +1571,12 @@ def subdomain():
15661571
rv = client.get("/", "https://dev.local")
15671572
assert rv.data == b"default"
15681573

1569-
# suppress Werkzeug 0.15 warning about name mismatch
1570-
with warnings.catch_warnings():
1571-
warnings.filterwarnings(
1572-
"ignore", "Current server name", UserWarning, "flask.app"
1573-
)
1574+
with pytest.warns(match="Current server name"):
15741575
rv = client.get("/", "http://foo.localhost")
1576+
1577+
if werkzeug_3_2:
1578+
assert rv.status_code == 200
1579+
else:
15751580
assert rv.status_code == 404
15761581

15771582
rv = client.get("/", "http://foo.dev.local")
@@ -1807,13 +1812,13 @@ def test_subdomain_matching_other_name(matching):
18071812
def index():
18081813
return "", 204
18091814

1810-
# suppress Werkzeug 0.15 warning about name mismatch
1811-
with warnings.catch_warnings():
1812-
warnings.filterwarnings(
1813-
"ignore", "Current server name", UserWarning, "flask.app"
1814-
)
1815-
# ip address can't match name
1815+
with pytest.warns(match="Current server name") if matching else nullcontext():
1816+
# ip address can't match name, but will fall back to default
18161817
rv = client.get("/", "http://127.0.0.1:3000/")
1818+
1819+
if werkzeug_3_2:
1820+
assert rv.status_code == 204
1821+
else:
18171822
assert rv.status_code == 404 if matching else 204
18181823

18191824
# allow all subdomains if matching is disabled

uv.lock

Lines changed: 39 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)