Skip to content
Myr

update domain matching tests for Werkzeug 3.2

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 798e006 · Browse files · 3 files+69 added−28 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+69 added−28 removed

  • tests:+27 added−22 removed
  • other:+42 added−6 removed

3 files+69 added−28 removed

modified:tests/test_basic.py+27 added-22 removed
1import gc2import importlib.metadata3import re4import typing as t5import uuid5import warnings6import weakref7from contextlib import nullcontext8from datetime import datetime9from datetime import timezone
1480 unmodified lines
1490 assert repr(flask.g) == "<LocalProxy unbound>"1491 assert not flask.g149214931494werkzeug_3_2 = importlib.metadata.version("werkzeug") >= "3.2."149514961497@pytest.mark.parametrize(1495 ("subdomain_matching", "host_matching", "expect_base", "expect_abc", "expect_xyz"),1498 ("subdomain_matching", "host_matching", "expect_subdomain", "expect_host"),1499 [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"),1503 ],1504)1505def test_server_name_matching(1506 subdomain_matching: bool,1507 host_matching: bool,1505 expect_base: str,1506 expect_abc: str,1507 expect_xyz: str,1508 expect_subdomain: str,1509 expect_host: str,1510) -> None:1511 app = flask.Flask(1512 __name__,1513 subdomain_matching=subdomain_matching,
9 unmodified lines
15231524 client = app.test_client()15251526 r = client.get(base_url="http://example.test")1525 assert r.text == expect_base1527 assert r.text == "default"15281529 r = client.get(base_url="http://abc.example.test")1528 assert r.text == expect_abc1530 assert r.text == expect_subdomain15311532 with pytest.warns() if subdomain_matching else nullcontext():1533 r = client.get(base_url="http://xyz.other.test")15341535 if werkzeug_3_2:1536 assert r.text == "default"1537 else:1533 assert r.text == expect_xyz1538 assert r.text == expect_host153915401541def test_server_name_subdomain():1542 app = flask.Flask(__name__, subdomain_matching=True)
27 unmodified lines
1570 app.config["SERVER_NAME"] = "dev.local"1571 rv = client.get("/", "https://dev.local")1572 assert rv.data == b"default"15731569 # suppress Werkzeug 0.15 warning about name mismatch1570 with warnings.catch_warnings():1571 warnings.filterwarnings(1572 "ignore", "Current server name", UserWarning, "flask.app"1573 )1574 with pytest.warns(match="Current server name"):1575 rv = client.get("/", "http://foo.localhost")15761577 if werkzeug_3_2:1578 assert rv.status_code == 2001579 else:1580 assert rv.status_code == 40415811582 rv = client.get("/", "http://foo.dev.local")1583 assert rv.data == b"subdomain"
227 unmodified lines
1811 @app.route("/")1812 def index():1813 return "", 20418141810 # suppress Werkzeug 0.15 warning about name mismatch1811 with warnings.catch_warnings():1812 warnings.filterwarnings(1813 "ignore", "Current server name", UserWarning, "flask.app"1814 )1815 # ip address can't match name1815 with pytest.warns(match="Current server name") if matching else nullcontext():1816 # ip address can't match name, but will fall back to default1817 rv = client.get("/", "http://127.0.0.1:3000/")18181819 if werkzeug_3_2:1820 assert rv.status_code == 2041821 else:1822 assert rv.status_code == 404 if matching else 20418231824 # allow all subdomains if matching is disabled1825 rv = client.get("/", "http://www.localhost.localdomain:3000/")
124 unmodified lines
modified:pyproject.toml+3 added
102 unmodified lines
103104[tool.uv]105default-groups = ["dev", "pre-commit", "tests", "typing"]106107[tool.uv.sources]108werkzeug = { path = "../werkzeug" }109110[tool.pytest.ini_options]111testpaths = ["tests"]112filterwarnings = [113 "error",
168 unmodified lines
modified:uv.lock+39 added-6 removed
461 unmodified lines
462 { name = "itsdangerous", specifier = ">=2.2.0" },463 { name = "jinja2", specifier = ">=3.1.2" },464 { name = "markupsafe", specifier = ">=2.1.1" },465 { name = "python-dotenv", marker = "extra == 'dotenv'" },466 { name = "werkzeug", specifier = ">=3.1.0" },466 { name = "werkzeug", directory = "../werkzeug" },467]468provides-extras = ["async", "dotenv"]469470[package.metadata.requires-dev]
1272 unmodified lines
1743]17441745[[package]]1746name = "werkzeug"1747version = "3.1.5"1748source = { registry = "https://pypi.org/simple" }1747version = "3.2.0.dev0"1748source = { directory = "../werkzeug" }1749dependencies = [1750 { name = "markupsafe" },1751]1752sdist = { url = "https://files.pythonhosted.org/packages/5a/70/1469ef1d3542ae7c2c7b72bd5e3a4e6ee69d7978fa8a3af05a38eca5becf/werkzeug-3.1.5.tar.gz", hash = "sha256:6a548b0e88955dd07ccb25539d7d0cc97417ee9e179677d22c7041c8f078ce67", size = 864754, upload-time = "2026-01-08T17:49:23.247Z" }1753wheels = [1754 { url = "https://files.pythonhosted.org/packages/ad/e4/8d97cca767bcc1be76d16fb76951608305561c6e056811587f36cb1316a8/werkzeug-3.1.5-py3-none-any.whl", hash = "sha256:5111e36e91086ece91f93268bb39b4a35c1e6f1feac762c9c822ded0a4e322dc", size = 225025, upload-time = "2026-01-08T17:49:21.859Z" },17521753[package.metadata]1754requires-dist = [1755 { name = "markupsafe", specifier = ">=2.1.1" },1756 { name = "watchdog", marker = "extra == 'watchdog'", specifier = ">=2.3" },1757]1758provides-extras = ["watchdog"]17591760[package.metadata.requires-dev]1761dev = [1762 { name = "ruff" },1763 { name = "tox" },1764 { name = "tox-uv" },1765]1766docs = [1767 { name = "pallets-sphinx-themes" },1768 { name = "sphinx", specifier = "<9" },1769 { name = "sphinxcontrib-log-cabinet" },1770]1771docs-auto = [{ name = "sphinx-autobuild" }]1772gha-update = [{ name = "gha-update", marker = "python_full_version >= '3.12'" }]1773pre-commit = [1774 { name = "pre-commit" },1775 { name = "pre-commit-uv" },1776]1777tests = [1778 { name = "cffi" },1779 { name = "cryptography" },1780 { name = "ephemeral-port-reserve" },1781 { name = "pytest" },1782 { name = "pytest-timeout" },1783 { name = "watchdog" },1784]1785typing = [1786 { name = "mypy" },1787 { name = "pyright" },1788]