forked from orbit-oss/flask
update domain matching tests for Werkzeug 3.2
This commit is contained in:
parent
798e006f43
commit
5e621a2801
3 changed files with 69 additions and 28 deletions
|
|
@ -104,6 +104,9 @@ exclude = [
|
||||||
[tool.uv]
|
[tool.uv]
|
||||||
default-groups = ["dev", "pre-commit", "tests", "typing"]
|
default-groups = ["dev", "pre-commit", "tests", "typing"]
|
||||||
|
|
||||||
|
[tool.uv.sources]
|
||||||
|
werkzeug = { path = "../werkzeug" }
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
testpaths = ["tests"]
|
testpaths = ["tests"]
|
||||||
filterwarnings = [
|
filterwarnings = [
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import gc
|
import gc
|
||||||
|
import importlib.metadata
|
||||||
import re
|
import re
|
||||||
import typing as t
|
import typing as t
|
||||||
import uuid
|
import uuid
|
||||||
import warnings
|
|
||||||
import weakref
|
import weakref
|
||||||
from contextlib import nullcontext
|
from contextlib import nullcontext
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
@ -1491,20 +1491,22 @@ def test_request_locals():
|
||||||
assert not flask.g
|
assert not flask.g
|
||||||
|
|
||||||
|
|
||||||
|
werkzeug_3_2 = importlib.metadata.version("werkzeug") >= "3.2."
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("subdomain_matching", "host_matching", "expect_base", "expect_abc", "expect_xyz"),
|
("subdomain_matching", "host_matching", "expect_subdomain", "expect_host"),
|
||||||
[
|
[
|
||||||
(False, False, "default", "default", "default"),
|
(False, False, "default", "default"),
|
||||||
(True, False, "default", "abc", "<invalid>"),
|
(True, False, "abc", "<invalid>"),
|
||||||
(False, True, "default", "abc", "default"),
|
(False, True, "abc", "default"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_server_name_matching(
|
def test_server_name_matching(
|
||||||
subdomain_matching: bool,
|
subdomain_matching: bool,
|
||||||
host_matching: bool,
|
host_matching: bool,
|
||||||
expect_base: str,
|
expect_subdomain: str,
|
||||||
expect_abc: str,
|
expect_host: str,
|
||||||
expect_xyz: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
app = flask.Flask(
|
app = flask.Flask(
|
||||||
__name__,
|
__name__,
|
||||||
|
|
@ -1522,15 +1524,18 @@ def test_server_name_matching(
|
||||||
client = app.test_client()
|
client = app.test_client()
|
||||||
|
|
||||||
r = client.get(base_url="http://example.test")
|
r = client.get(base_url="http://example.test")
|
||||||
assert r.text == expect_base
|
assert r.text == "default"
|
||||||
|
|
||||||
r = client.get(base_url="http://abc.example.test")
|
r = client.get(base_url="http://abc.example.test")
|
||||||
assert r.text == expect_abc
|
assert r.text == expect_subdomain
|
||||||
|
|
||||||
with pytest.warns() if subdomain_matching else nullcontext():
|
with pytest.warns() if subdomain_matching else nullcontext():
|
||||||
r = client.get(base_url="http://xyz.other.test")
|
r = client.get(base_url="http://xyz.other.test")
|
||||||
|
|
||||||
assert r.text == expect_xyz
|
if werkzeug_3_2:
|
||||||
|
assert r.text == "default"
|
||||||
|
else:
|
||||||
|
assert r.text == expect_host
|
||||||
|
|
||||||
|
|
||||||
def test_server_name_subdomain():
|
def test_server_name_subdomain():
|
||||||
|
|
@ -1566,12 +1571,12 @@ def test_server_name_subdomain():
|
||||||
rv = client.get("/", "https://dev.local")
|
rv = client.get("/", "https://dev.local")
|
||||||
assert rv.data == b"default"
|
assert rv.data == b"default"
|
||||||
|
|
||||||
# suppress Werkzeug 0.15 warning about name mismatch
|
with pytest.warns(match="Current server name"):
|
||||||
with warnings.catch_warnings():
|
|
||||||
warnings.filterwarnings(
|
|
||||||
"ignore", "Current server name", UserWarning, "flask.app"
|
|
||||||
)
|
|
||||||
rv = client.get("/", "http://foo.localhost")
|
rv = client.get("/", "http://foo.localhost")
|
||||||
|
|
||||||
|
if werkzeug_3_2:
|
||||||
|
assert rv.status_code == 200
|
||||||
|
else:
|
||||||
assert rv.status_code == 404
|
assert rv.status_code == 404
|
||||||
|
|
||||||
rv = client.get("/", "http://foo.dev.local")
|
rv = client.get("/", "http://foo.dev.local")
|
||||||
|
|
@ -1807,13 +1812,13 @@ def test_subdomain_matching_other_name(matching):
|
||||||
def index():
|
def index():
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
# suppress Werkzeug 0.15 warning about name mismatch
|
with pytest.warns(match="Current server name") if matching else nullcontext():
|
||||||
with warnings.catch_warnings():
|
# ip address can't match name, but will fall back to default
|
||||||
warnings.filterwarnings(
|
|
||||||
"ignore", "Current server name", UserWarning, "flask.app"
|
|
||||||
)
|
|
||||||
# ip address can't match name
|
|
||||||
rv = client.get("/", "http://127.0.0.1:3000/")
|
rv = client.get("/", "http://127.0.0.1:3000/")
|
||||||
|
|
||||||
|
if werkzeug_3_2:
|
||||||
|
assert rv.status_code == 204
|
||||||
|
else:
|
||||||
assert rv.status_code == 404 if matching else 204
|
assert rv.status_code == 404 if matching else 204
|
||||||
|
|
||||||
# allow all subdomains if matching is disabled
|
# allow all subdomains if matching is disabled
|
||||||
|
|
|
||||||
45
uv.lock
generated
45
uv.lock
generated
|
|
@ -463,7 +463,7 @@ requires-dist = [
|
||||||
{ name = "jinja2", specifier = ">=3.1.2" },
|
{ name = "jinja2", specifier = ">=3.1.2" },
|
||||||
{ name = "markupsafe", specifier = ">=2.1.1" },
|
{ name = "markupsafe", specifier = ">=2.1.1" },
|
||||||
{ name = "python-dotenv", marker = "extra == 'dotenv'" },
|
{ name = "python-dotenv", marker = "extra == 'dotenv'" },
|
||||||
{ name = "werkzeug", specifier = ">=3.1.0" },
|
{ name = "werkzeug", directory = "../werkzeug" },
|
||||||
]
|
]
|
||||||
provides-extras = ["async", "dotenv"]
|
provides-extras = ["async", "dotenv"]
|
||||||
|
|
||||||
|
|
@ -1744,12 +1744,45 @@ wheels = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "werkzeug"
|
name = "werkzeug"
|
||||||
version = "3.1.5"
|
version = "3.2.0.dev0"
|
||||||
source = { registry = "https://pypi.org/simple" }
|
source = { directory = "../werkzeug" }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "markupsafe" },
|
{ name = "markupsafe" },
|
||||||
]
|
]
|
||||||
sdist = { 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" }
|
|
||||||
wheels = [
|
[package.metadata]
|
||||||
{ 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" },
|
requires-dist = [
|
||||||
|
{ name = "markupsafe", specifier = ">=2.1.1" },
|
||||||
|
{ name = "watchdog", marker = "extra == 'watchdog'", specifier = ">=2.3" },
|
||||||
|
]
|
||||||
|
provides-extras = ["watchdog"]
|
||||||
|
|
||||||
|
[package.metadata.requires-dev]
|
||||||
|
dev = [
|
||||||
|
{ name = "ruff" },
|
||||||
|
{ name = "tox" },
|
||||||
|
{ name = "tox-uv" },
|
||||||
|
]
|
||||||
|
docs = [
|
||||||
|
{ name = "pallets-sphinx-themes" },
|
||||||
|
{ name = "sphinx", specifier = "<9" },
|
||||||
|
{ name = "sphinxcontrib-log-cabinet" },
|
||||||
|
]
|
||||||
|
docs-auto = [{ name = "sphinx-autobuild" }]
|
||||||
|
gha-update = [{ name = "gha-update", marker = "python_full_version >= '3.12'" }]
|
||||||
|
pre-commit = [
|
||||||
|
{ name = "pre-commit" },
|
||||||
|
{ name = "pre-commit-uv" },
|
||||||
|
]
|
||||||
|
tests = [
|
||||||
|
{ name = "cffi" },
|
||||||
|
{ name = "cryptography" },
|
||||||
|
{ name = "ephemeral-port-reserve" },
|
||||||
|
{ name = "pytest" },
|
||||||
|
{ name = "pytest-timeout" },
|
||||||
|
{ name = "watchdog" },
|
||||||
|
]
|
||||||
|
typing = [
|
||||||
|
{ name = "mypy" },
|
||||||
|
{ name = "pyright" },
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue