feat(file-summary): 实现文件处理技能链路
This commit is contained in:
25
tests/test_file_summary_archive.py
Normal file
25
tests/test_file_summary_archive.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from zipfile import ZipFile
|
||||
import pytest
|
||||
|
||||
from review_agent.file_summary.services.archive import extract_archive
|
||||
|
||||
|
||||
def test_extract_zip_preserves_safe_paths(tmp_path):
|
||||
archive_path = tmp_path / "safe.zip"
|
||||
with ZipFile(archive_path, "w") as archive:
|
||||
archive.writestr("dir/a.txt", "content")
|
||||
|
||||
target = tmp_path / "out"
|
||||
extracted = extract_archive(archive_path, target)
|
||||
|
||||
assert extracted == [target / "dir" / "a.txt"]
|
||||
assert (target / "dir" / "a.txt").read_text(encoding="utf-8") == "content"
|
||||
|
||||
|
||||
def test_extract_zip_rejects_path_traversal(tmp_path):
|
||||
archive_path = tmp_path / "evil.zip"
|
||||
with ZipFile(archive_path, "w") as archive:
|
||||
archive.writestr("../evil.txt", "bad")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
extract_archive(archive_path, tmp_path / "out")
|
||||
Reference in New Issue
Block a user