diff --git a/e2e/platforms/qemu_windows/tests/test_runner.py b/e2e/platforms/qemu_windows/tests/test_runner.py index 588f4cbe..18c949ef 100644 --- a/e2e/platforms/qemu_windows/tests/test_runner.py +++ b/e2e/platforms/qemu_windows/tests/test_runner.py @@ -215,8 +215,12 @@ def test_a_temp_path_is_in_the_guest_and_a_bad_name_is_rejected() -> None: platform = WindowsPlatform(SimpleNamespace(), agent, Path(".")) assert platform.temp_path("e2e-resize.json") == "C:\\e2e\\tmp\\e2e-resize.json" - with pytest.raises(ValueError): - platform.temp_path("..\\x") + assert platform.temp_path("wallpapers/my pictures/cool.png") == ( + "C:\\e2e\\tmp\\wallpapers\\my pictures\\cool.png" + ) + for bad in ("..\\x", "a/../../x", "/abs", "C:\\x", ""): + with pytest.raises(ValueError): + platform.temp_path(bad) def test_acting_on_a_window_that_is_not_there_raises_a_clear_error() -> None: diff --git a/e2e/platforms/qemu_windows/windows_platform.py b/e2e/platforms/qemu_windows/windows_platform.py index 7c1e93ec..910d1685 100644 --- a/e2e/platforms/qemu_windows/windows_platform.py +++ b/e2e/platforms/qemu_windows/windows_platform.py @@ -231,10 +231,16 @@ class WindowsPlatform: self._agent.put_file(local, CONFIG_PATH) def temp_path(self, name: str) -> str: - if not re.fullmatch(r"[A-Za-z0-9_.-]+", name): + # a path under the temp folder, with folders in it, which may have a + # space: never one that leaves the folder + parts = name.replace("\\", "/").split("/") + if not all( + re.fullmatch(r"[A-Za-z0-9_.-][A-Za-z0-9 _.-]*", part) and part != ".." + for part in parts + ): raise ValueError(f"not a file name: {name!r}") self._agent.exec("cmd", "/c", f"mkdir {TEMP_DIR} 2>nul") - return f"{TEMP_DIR}\\{name}" + return TEMP_DIR + "\\" + "\\".join(parts) def put_file(self, path: str, data: bytes) -> None: parent = path.rsplit("\\", 1)[0]