From 817f22c2d573de7eb601bda4df4fb11bc7e4cf71 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Mon, 14 Sep 2026 10:52:22 +0800 Subject: [PATCH] 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. --- .../moli_benchmark/wpt_cross/server.py | 1 + moli-benchmark/tests/test_wpt_cross.py | 32 +++++++++++++++++-- .../wpt-cross-current/failed-cases.txt | 1 - .../wpt-cross-current/passed-cases.txt | 1 + 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/moli-benchmark/moli_benchmark/wpt_cross/server.py b/moli-benchmark/moli_benchmark/wpt_cross/server.py index 8f7b34f36..c7c11358c 100644 --- a/moli-benchmark/moli_benchmark/wpt_cross/server.py +++ b/moli-benchmark/moli_benchmark/wpt_cross/server.py @@ -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, diff --git a/moli-benchmark/tests/test_wpt_cross.py b/moli-benchmark/tests/test_wpt_cross.py index e1442e433..fc6799cdc 100644 --- a/moli-benchmark/tests/test_wpt_cross.py +++ b/moli-benchmark/tests/test_wpt_cross.py @@ -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,", ) diff --git a/moli-benchmark/wpt-cross-current/failed-cases.txt b/moli-benchmark/wpt-cross-current/failed-cases.txt index 00aece726..58cdc07d9 100644 --- a/moli-benchmark/wpt-cross-current/failed-cases.txt +++ b/moli-benchmark/wpt-cross-current/failed-cases.txt @@ -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 diff --git a/moli-benchmark/wpt-cross-current/passed-cases.txt b/moli-benchmark/wpt-cross-current/passed-cases.txt index 3976a2be7..2f7f25f70 100644 --- a/moli-benchmark/wpt-cross-current/passed-cases.txt +++ b/moli-benchmark/wpt-cross-current/passed-cases.txt @@ -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