fix(wpt): substitute the primary domain in fixture templates

Expand {{domains[]}} to the configured primary hostname in fixture content
and sidecar headers. This fixes credentialed CORS fixtures whose allow-origin
header previously retained the literal placeholder.

Cover cross-subdomain requests and default and non-default HTTP ports.

Move the full SRI fixture to passed-cases after both engines pass all 48
subtests; the four-case integrity selection passes 68/68 in both engines.
This commit is contained in:
ldm0
2026-09-27 06:43:23 +08:00
parent 0c3e358ef5
commit 817f22c2d5
4 changed files with 32 additions and 3 deletions
@@ -1371,6 +1371,7 @@ def _substitute_wpt_template_variables(
b"ws://" + primary_url_host_bytes + b":" + str(alternate_port).encode("ascii")
),
b"{{host}}": primary_hostname_bytes,
b"{{domains[]}}": primary_hostname_bytes,
b"{{location[scheme]}}": b"http",
b"{{location[server]}}": current_origin,
b"{{location[host]}}": request_host_bytes,
+30 -2
View File
@@ -5518,6 +5518,34 @@ test(() => {}, "ok");
],
)
def test_fixture_server_substitutes_primary_domain_in_cors_sidecar(self) -> None:
with tempfile.TemporaryDirectory() as root:
fixture = Path(root) / "style.css"
fixture.write_text("body {}", encoding="utf-8")
fixture.with_name("style.css.sub.headers").write_text(
"Access-Control-Allow-Origin: {{location[scheme]}}://{{domains[]}}{{GET[acao_port]}}\n"
"Access-Control-Allow-Credentials: true\n",
encoding="utf-8",
)
for port in (80, 12345):
with self.subTest(port=port):
suffix = "" if port == 80 else f":{port}"
query = "" if port == 80 else f"acao_port=%3A{port}"
self.assertEqual(
_static_response_headers(
fixture,
query,
port=port,
request_hostname="www.example.test",
primary_hostname="example.test",
),
[
("Access-Control-Allow-Origin", f"http://example.test{suffix}"),
("Access-Control-Allow-Credentials", "true"),
],
)
def test_fixture_server_substitution_preserves_non_utf8_bytes(self) -> None:
body = b"\xff{{host}}\xfe{{ports[http][0]}}"
@@ -5530,7 +5558,7 @@ test(() => {}, "ok");
self,
) -> None:
body = (
b"host={{host}} "
b"host={{host}} domain={{domains[]}} "
b"location={{location[hostname]}} "
b"HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + HTTP_PORT_ELIDED,"
)
@@ -5542,7 +5570,7 @@ test(() => {}, "ok");
request_hostname="www1.localhost",
primary_hostname="localhost",
),
b"host=localhost location=www1.localhost "
b"host=localhost domain=localhost location=www1.localhost "
b"HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + HTTP_PORT_ELIDED,",
)
@@ -3523,7 +3523,6 @@ streams/readable-streams/owning-type-video-frame.any.js?moli-wpt-any=window
streams/readable-streams/owning-type.any.js?moli-wpt-any=dedicatedworker
streams/readable-streams/owning-type.any.js?moli-wpt-any=window
subresource-integrity/signatures/tentative/inline.html
subresource-integrity/subresource-integrity.html
svg/coordinate-systems/outer-svg-intrinsic-size-001.html
svg/coordinate-systems/outer-svg-intrinsic-size-002.html
svg/extensibility/foreignObject/containing-block.html
@@ -8512,6 +8512,7 @@ streams/writable-streams/start.any.js?moli-wpt-any=dedicatedworker
streams/writable-streams/start.any.js?moli-wpt-any=window
streams/writable-streams/write.any.js?moli-wpt-any=dedicatedworker
streams/writable-streams/write.any.js?moli-wpt-any=window
subresource-integrity/subresource-integrity.html
svg/coordinate-systems/svgtransformlist-replaceitem.html
svg/coordinate-systems/transform-translate-single-parameter.html
svg/crashtests/chrome-bug-1172059.html