from pathlib import Path import pytest from backend.app.security.paths import is_within_directory, safe_join def test_within(tmp_path: Path): base = tmp_path / "base" base.mkdir() child = base / "a" / "b" child.mkdir(parents=True) assert is_within_directory(base, child) assert not is_within_directory(base, tmp_path / "other") def test_safe_join_blocks_traversal(tmp_path: Path): base = tmp_path / "base" base.mkdir() with pytest.raises(ValueError): safe_join(base, "..", "etc", "passwd")