Files
backup-tool/tests/unit/test_restore_selection.py

35 lines
975 B
Python

from __future__ import annotations
import importlib
import pytest
snapshot = importlib.import_module("backup_tool.snapshot")
def entry(path: str, kind: str) -> dict[str, object]:
return {"path": path, "type": kind}
def test_restore_selection_includes_selected_descendants_and_ancestors() -> None:
entries = [
entry("top", "directory"),
entry("top/keep", "directory"),
entry("top/keep/file.txt", "file"),
entry("top/drop.txt", "file"),
]
selected = snapshot._select_restore_entries(entries, ["top/keep"])
assert [item["path"] for item in selected] == [
"top",
"top/keep",
"top/keep/file.txt",
]
@pytest.mark.parametrize("selection", [["../escape"], ["/absolute"], ["a\\b"], [""]])
def test_restore_selection_rejects_unsafe_paths(selection: list[str]) -> None:
with pytest.raises(snapshot.SnapshotError):
snapshot._select_restore_entries([entry("safe", "file")], selection)