11import gc
2+ import importlib .metadata
23import re
34import typing as t
45import uuid
5- import warnings
66import weakref
77from contextlib import nullcontext
88from 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)
15021505def 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
15361541def 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
0 commit comments