repospace / backend /tests /test_paths.py
2Btainment's picture
Initial RepoSpace MVP: FastAPI + constrained sandbox + React UI
3c07134 verified
Raw History Blame Contribute Delete
540 Bytes
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")