(
subdomain_matching: bool,
host_matching: bool,
expect_base: str,
expect_abc: str,
expect_xyz: str,
)
| 1493 | ], |
| 1494 | ) |
| 1495 | def test_server_name_matching( |
| 1496 | subdomain_matching: bool, |
| 1497 | host_matching: bool, |
| 1498 | expect_base: str, |
| 1499 | expect_abc: str, |
| 1500 | expect_xyz: str, |
| 1501 | ) -> None: |
| 1502 | app = flask.Flask( |
| 1503 | __name__, |
| 1504 | subdomain_matching=subdomain_matching, |
| 1505 | host_matching=host_matching, |
| 1506 | static_host="example.test" if host_matching else None, |
| 1507 | ) |
| 1508 | app.config["SERVER_NAME"] = "example.test" |
| 1509 | |
| 1510 | @app.route("/", defaults={"name": "default"}, host="<name>") |
| 1511 | @app.route("/", subdomain="<name>", host="<name>.example.test") |
| 1512 | def index(name: str) -> str: |
| 1513 | return name |
| 1514 | |
| 1515 | client = app.test_client() |
| 1516 | |
| 1517 | r = client.get(base_url="http://example.test") |
| 1518 | assert r.text == expect_base |
| 1519 | |
| 1520 | r = client.get(base_url="http://abc.example.test") |
| 1521 | assert r.text == expect_abc |
| 1522 | |
| 1523 | with pytest.warns() if subdomain_matching else nullcontext(): |
| 1524 | r = client.get(base_url="http://xyz.other.test") |
| 1525 | |
| 1526 | assert r.text == expect_xyz |
| 1527 | |
| 1528 | |
| 1529 | def test_server_name_subdomain(): |
nothing calls this directly
no test coverage detected