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]
|
||||
default-groups = ["dev", "pre-commit", "tests", "typing"]
|
||||
|
||||
[tool.uv.sources]
|
||||
werkzeug = { path = "../werkzeug" }
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
filterwarnings = [
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import gc
|
||||
import importlib.metadata
|
||||
import re
|
||||
import typing as t
|
||||
import uuid
|
||||
import warnings
|
||||
import weakref
|
||||
from contextlib import nullcontext
|
||||
from datetime import datetime
|
||||
|
|
@ -1491,20 +1491,22 @@ def test_request_locals():
|
|||
assert not flask.g
|
||||
|
||||
|
||||
werkzeug_3_2 = importlib.metadata.version("werkzeug") >= "3.2."
|
||||
|
||||
|
||||
@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"),
|
||||
(True, False, "default", "abc", "<invalid>"),
|
||||
(False, True, "default", "abc", "default"),
|
||||
(False, False, "default", "default"),
|
||||
(True, False, "abc", "<invalid>"),
|
||||
(False, True, "abc", "default"),
|
||||
],
|
||||
)
|
||||
def test_server_name_matching(
|
||||
subdomain_matching: bool,
|
||||
host_matching: bool,
|
||||
expect_base: str,
|
||||
expect_abc: str,
|
||||
expect_xyz: str,
|
||||
expect_subdomain: str,
|
||||
expect_host: str,
|
||||
) -> None:
|
||||
app = flask.Flask(
|
||||
__name__,
|
||||
|
|
@ -1522,15 +1524,18 @@ def test_server_name_matching(
|
|||
client = app.test_client()
|
||||
|
||||
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")
|
||||
assert r.text == expect_abc
|
||||
assert r.text == expect_subdomain
|
||||
|
||||
with pytest.warns() if subdomain_matching else nullcontext():
|
||||
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():
|
||||
|
|
@ -1566,12 +1571,12 @@ def test_server_name_subdomain():
|
|||
rv = client.get("/", "https://dev.local")
|
||||
assert rv.data == b"default"
|
||||
|
||||
# suppress Werkzeug 0.15 warning about name mismatch
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings(
|
||||
"ignore", "Current server name", UserWarning, "flask.app"
|
||||
)
|
||||
with pytest.warns(match="Current server name"):
|
||||
rv = client.get("/", "http://foo.localhost")
|
||||
|
||||
if werkzeug_3_2:
|
||||
assert rv.status_code == 200
|
||||
else:
|
||||
assert rv.status_code == 404
|
||||
|
||||
rv = client.get("/", "http://foo.dev.local")
|
||||
|
|
@ -1807,13 +1812,13 @@ def test_subdomain_matching_other_name(matching):
|
|||
def index():
|
||||
return "", 204
|
||||
|
||||
# suppress Werkzeug 0.15 warning about name mismatch
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings(
|
||||
"ignore", "Current server name", UserWarning, "flask.app"
|
||||
)
|
||||
# ip address can't match name
|
||||
with pytest.warns(match="Current server name") if matching else nullcontext():
|
||||
# ip address can't match name, but will fall back to default
|
||||
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
|
||||
|
||||
# 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 = "markupsafe", specifier = ">=2.1.1" },
|
||||
{ name = "python-dotenv", marker = "extra == 'dotenv'" },
|
||||
{ name = "werkzeug", specifier = ">=3.1.0" },
|
||||
{ name = "werkzeug", directory = "../werkzeug" },
|
||||
]
|
||||
provides-extras = ["async", "dotenv"]
|
||||
|
||||
|
|
@ -1744,12 +1744,45 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "werkzeug"
|
||||
version = "3.1.5"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
version = "3.2.0.dev0"
|
||||
source = { directory = "../werkzeug" }
|
||||
dependencies = [
|
||||
{ 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 = [
|
||||
{ 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" },
|
||||
|
||||
[package.metadata]
|
||||
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