mirror of
https://github.com/lexmount/moli.git
synced 2026-10-30 08:07:38 +00:00
test(wpt): serve dynamic import redirects without CORS headers
This commit is contained in:
@@ -2300,6 +2300,29 @@ def _make_handler(
|
||||
)
|
||||
return
|
||||
|
||||
if path == (
|
||||
"/html/semantics/scripting-1/the-script-element/module/"
|
||||
"dynamic-import/beta/redirect.py"
|
||||
):
|
||||
params = parse_qs(parsed.query, keep_blank_values=True)
|
||||
try:
|
||||
status_code = int(params.get("status", ["302"])[0])
|
||||
except ValueError:
|
||||
status_code = 302
|
||||
location = params.get("location", [""])[0]
|
||||
if not 100 <= status_code <= 599 or any(
|
||||
character in location for character in "\r\n"
|
||||
):
|
||||
self.send_error(400)
|
||||
return
|
||||
self._send_bytes(
|
||||
"text/plain; charset=utf-8",
|
||||
b"",
|
||||
emit_body=emit_body,
|
||||
extra_headers=[("Location", location)],
|
||||
status_code=status_code,
|
||||
)
|
||||
return
|
||||
if path in {
|
||||
"/fetch/api/resources/redirect.py",
|
||||
"/common/redirect.py",
|
||||
|
||||
@@ -4453,6 +4453,47 @@ test(() => {}, "ok");
|
||||
],
|
||||
)
|
||||
|
||||
def test_fixture_server_models_dynamic_import_redirect_without_cors(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
root_path = Path(root)
|
||||
(root_path / "resources").mkdir()
|
||||
(root_path / "resources" / "testharness.js").write_text(
|
||||
"// testharness", encoding="utf-8"
|
||||
)
|
||||
with WptFixtureServer(root_path) as server:
|
||||
for method in ("GET", "HEAD"):
|
||||
for query, status, location in (
|
||||
("location=%2Ftarget", 302, "/target"),
|
||||
(
|
||||
"status=307&location=https%3A%2F%2Fexample.test%2Fx",
|
||||
307,
|
||||
"https://example.test/x",
|
||||
),
|
||||
("status=invalid&location=%2Ftarget", 302, "/target"),
|
||||
(
|
||||
"status=302&status=307&location=%2Fa&location=%2Fb",
|
||||
302,
|
||||
"/a",
|
||||
),
|
||||
):
|
||||
with self.subTest(method=method, query=query):
|
||||
connection = HTTPConnection("127.0.0.1", server.port, timeout=2)
|
||||
try:
|
||||
connection.request(
|
||||
method,
|
||||
"/html/semantics/scripting-1/the-script-element/module/"
|
||||
f"dynamic-import/beta/redirect.py?{query}",
|
||||
)
|
||||
response = connection.getresponse()
|
||||
self.assertEqual(response.status, status)
|
||||
self.assertEqual(response.headers.get("Location"), location)
|
||||
self.assertIsNone(
|
||||
response.headers.get("Access-Control-Allow-Origin")
|
||||
)
|
||||
self.assertEqual(response.read(), b"")
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
def test_fixture_server_models_common_redirect_opt_in_handler(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
root_path = Path(root)
|
||||
|
||||
Reference in New Issue
Block a user