- Add format validation and inspection for PDF, DOCX, Markdown, Text, HTML, and images - Implement secure decompression defenses (zip bombs, ratio checks) and image dimension limits - Implement FileStore with content-addressable storage and intake repositories - Add unit and integration tests for document intake, format sniffing, and storage roots - Include sample acceptance document fixtures in data/documents/
51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
"""Canonical namespace separation without storage mutation."""
|
|
import os
|
|
from pathlib import Path
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
from app.modules.documents.settings import IngestionSettings
|
|
|
|
|
|
def configure(settings, original, extraction):
|
|
return IngestionSettings(_env_file=None, **(settings.model_dump() | {
|
|
"original_directory": original, "extraction_directory": extraction}))
|
|
|
|
|
|
@pytest.mark.parametrize("case", ["equal", "child", "parent", "relative_alias", "dot_alias", "case_alias", "extended_alias"])
|
|
def test_overlapping_roots_rejected_without_creating_storage(settings, tmp_path, monkeypatch, case):
|
|
original = tmp_path / "originals"
|
|
extraction = original
|
|
if case == "child": extraction = original / "artifacts"
|
|
if case == "parent": extraction = tmp_path
|
|
if case == "relative_alias":
|
|
monkeypatch.chdir(tmp_path)
|
|
original = Path("originals")
|
|
extraction = tmp_path / "originals"
|
|
if case == "dot_alias": extraction = original / ".." / "originals"
|
|
if case in ("case_alias", "extended_alias"):
|
|
if os.name != "nt": pytest.skip("Windows path alias semantics")
|
|
extraction = Path(str(original).swapcase()) if case == "case_alias" else Path("\\\\?\\" + str(original))
|
|
before = list(tmp_path.iterdir())
|
|
with pytest.raises(ValidationError): configure(settings, original, extraction)
|
|
assert list(tmp_path.iterdir()) == before and not original.exists()
|
|
|
|
|
|
def test_sibling_roots_with_shared_prefix_are_valid(settings, tmp_path):
|
|
original, extraction = tmp_path / "files", tmp_path / "files-derived"
|
|
configure(settings, original, extraction)
|
|
assert list(tmp_path.iterdir()) == []
|
|
|
|
|
|
@pytest.mark.parametrize("nested", [False, True])
|
|
def test_symlink_root_alias_rejected(settings, tmp_path, nested):
|
|
original = tmp_path / "originals"
|
|
original.mkdir()
|
|
alias = tmp_path / "alias"
|
|
try:
|
|
alias.symlink_to(original, target_is_directory=True)
|
|
except OSError:
|
|
pytest.skip("Host does not grant directory symlink creation")
|
|
before = list(tmp_path.iterdir())
|
|
with pytest.raises(ValidationError): configure(settings, original, alias / "child" if nested else alias)
|
|
assert list(tmp_path.iterdir()) == before
|