mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-28 11:22:47 +01:00
fix(e2e): a temp path may have folders in it and a space in a name
temp_path takes wallpapers/my pictures/cool.png, as the wallpaper scenario asks for; a name that leaves the folder is still refused.
This commit is contained in:
1 parent
a007996f6a
commit
fe95747267
2 files changed
+14
-4
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user