Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

refactor: path traversal protection cleanup — sentinel constants, symlink checks, bug fixes (#2615)

LearningCircuit997c3d220e4c
diff --git a/src/local_deep_research/constants.py b/src/local_deep_research/constants.py
index 73a289874c..30811819c5 100644
--- a/src/local_deep_research/constants.py
+++ b/src/local_deep_research/constants.py
@@ -65,6 +65,16 @@ class ResearchStatus(StrEnum):
RATE_LIMIT_WINDOW_SECONDS = 60
DEFAULT_RATE_LIMIT = 60 # requests per window
+# --- Research library file_path sentinel values ---
+FILE_PATH_METADATA_ONLY = "metadata_only"
+FILE_PATH_TEXT_ONLY = "text_only_not_stored"
+FILE_PATH_BLOB_DELETED = "blob_deleted"
+FILE_PATH_SENTINELS = (
+ FILE_PATH_METADATA_ONLY,
+ FILE_PATH_TEXT_ONLY,
+ FILE_PATH_BLOB_DELETED,
+)
+
# --- Snippet / truncation lengths ---
SNIPPET_LENGTH_SHORT = 250
SNIPPET_LENGTH_LONG = 500
diff --git a/src/local_deep_research/research_library/deletion/services/document_deletion.py b/src/local_deep_research/research_library/deletion/services/document_deletion.py
index d218a8575b..1d649f1025 100644
--- a/src/local_deep_research/research_library/deletion/services/document_deletion.py
+++ b/src/local_deep_research/research_library/deletion/services/document_deletion.py
@@ -11,6 +11,7 @@ from typing import Dict, Any
from loguru import logger
+from ....constants import FILE_PATH_BLOB_DELETED
from ....database.models.library import (
Document,
DocumentChunk,
@@ -221,7 +222,7 @@ class DocumentDeletionService:
# Update document to indicate blob is deleted
document.storage_mode = "none"
- document.file_path = "blob_deleted"
+ document.file_path = FILE_PATH_BLOB_DELETED
result["storage_mode_updated"] = True
session.commit()
diff --git a/src/local_deep_research/research_library/deletion/utils/cascade_helper.py b/src/local_deep_research/research_library/deletion/utils/cascade_helper.py
index 05bf4d7dc2..3bc981f6b2 100644
--- a/src/local_deep_research/research_library/deletion/utils/cascade_helper.py
+++ b/src/local_deep_research/research_library/deletion/utils/cascade_helper.py
@@ -13,6 +13,7 @@ from typing import Dict, List, Optional, Any
from loguru import logger
from sqlalchemy.orm import Session
+from ....constants import FILE_PATH_SENTINELS
from ....database.models.library import (
Document,
DocumentBlob,
@@ -151,11 +152,7 @@ class CascadeHelper:
return False
# Skip special path markers
- if file_path in (
- "metadata_only",
- "text_only_not_stored",
- "blob_deleted",
- ):
+ if file_path in FILE_PATH_SENTINELS:
return False
try:
diff --git a/src/local_deep_research/research_library/routes/rag_routes.py b/src/local_deep_research/research_library/routes/rag_routes.py
index aa447a6498..076ab26854 100644
--- a/src/local_deep_research/research_library/routes/rag_routes.py
+++ b/src/local_deep_research/research_library/routes/rag_routes.py
@@ -30,6 +30,7 @@ from datetime import datetime, UTC
from pathlib import Path
from typing import Optional
+from ...constants import FILE_PATH_SENTINELS, FILE_PATH_TEXT_ONLY
from ...security.decorators import require_json_body
from ...web.auth.decorators import login_required
from ...utilities.db_utils import get_settings_manager
@@ -1505,7 +1506,7 @@ def upload_to_collection(collection_id):
"research_library.storage_path",
str(get_library_directory()),
)
- library_root = str(Path(library_root).expanduser())
+ library_root = str(Path(library_root).expanduser().resolve())
pdf_storage_manager = PDFStorageManager(
library_root=Path(library_root), storage_mode="database"
)
@@ -1692,7 +1693,7 @@ def upload_to_collection(collection_id):
text_content=extracted_text, # Always store extracted text
file_path=None
if store_pdf_in_db
- else "text_only_not_stored",
+ else FILE_PATH_TEXT_ONLY,
storage_mode="database"
if store_pdf_in_db
else "none",
@@ -1821,9 +1822,7 @@ def get_collection_documents(collection_id):
for link, doc in doc_links:
# Check if PDF file is stored
has_pdf = bool(
- doc.file_path
- and doc.file_path != "metadata_only"
- and doc.file_path != "text_only_not_stored"
+ doc.file_path and doc.file_path not in FILE_PATH_SENTINELS
)
has_text_db = bool(doc.text_content)
diff --git a/src/local_deep_research/research_library/services/download_service.py b/src/local_deep_research/research_library/services/download_service.py
index b3d2824738..dfb1670dce 100644
--- a/src/local_deep_research/research_library/services/download_service.py
+++ b/src/local_deep_research/research_library/services/download_service.py
@@ -23,6 +23,7 @@ from sqlalchemy.orm import Session
import pdfplumber
from pypdf import PdfReader
+from ...constants import FILE_PATH_TEXT_ONLY
from ...database.models.download_tracker import (
DownloadAttempt,
DownloadTracker,
@@ -98,7 +99,9 @@ class DownloadService:
)
raise ValueError("Storage path setting cannot be None")
- self.library_root = str(Path(storage_path_setting).expanduser())
+ self.library_root = str(
+ Path(storage_path_setting).expanduser().resolve()
+ )
logger.warning(
f"[DOWNLOAD_SERVICE_INIT] Library root resolved to: {self.library_root}"
)
@@ -1609,7 +1612,7 @@ class DownloadService:
research_id=resource.research_id,
document_hash=text_hash,
original_url=resource.url,
- file_path="text_only_not_stored",
+ file_path=FILE_PATH_TEXT_ONLY,
file_size=character_count, # Use character count as file size for text-only
file_type="text",
mime_type="text/plain",
diff --git a/src/local_deep_research/research_library/services/library_service.py b/src/local_deep_research/research_library/services/library_service.py
index d66d0a1bdd..2bebae94de 100644
--- a/src/local_deep_research/research_library/services/library_service.py
+++ b/src/local_deep_research/research_library/services/library_service.py
@@ -15,6 +15,7 @@ from urllib.parse import urlparse
from loguru import logger
from sqlalchemy import and_, or_, func, case
+from ...constants import FILE_PATH_SENTINELS
from ...database.models.download_tracker import DownloadTracker
from ...database.models.library import (
Collection,
@@ -61,10 +62,7 @@ class LibraryService:
Returns:
Absolute path as string, or None if path is invalid/unsafe
"""
- if not file_path or file_path in (
- "metadata_only",
- "text_only_not_stored",
- ):
+ if not file_path or file_path in FILE_PATH_SENTINELS:
return None
abs_path = get_absolute_path_from_settings(file_path)
return str(abs_path) if abs_path else None
@@ -299,11 +297,7 @@ class LibraryService:
for doc, resource, research, doc_collection in results:
# Determine availability flags - use Document.file_path directly
file_absolute_path = None
- if (
- doc.file_path
- and doc.file_path != "metadata_only"
- and doc.file_path != "text_only_not_stored"
- ):
+ if doc.file_path and doc.file_path not in FILE_PATH_SENTINELS:
abs_path = get_absolute_path_from_settings(doc.file_path)
if abs_path:
file_absolute_path = str(abs_path)
@@ -339,8 +333,9 @@ class LibraryService:
"file_path": doc.file_path,
"file_absolute_path": file_absolute_path,
"file_name": Path(doc.file_path).name
- if doc.file_path and doc.file_path != "metadata_only"
- else "metadata_only",
+ if doc.file_path
+ and doc.file_path not in FILE_PATH_SENTINELS
+ else doc.filename,
"file_size": doc.file_size,
"file_type": doc.file_type,
# URLs
@@ -620,9 +615,7 @@ class LibraryService:
# Check if PDF is available (database OR filesystem)
has_pdf = bool(
- doc.file_path
- and doc.file_path != "metadata_only"
- and doc.file_path != "text_only_not_stored"
+ doc.file_path and doc.file_path not in FILE_PATH_SENTINELS
)
if not has_pdf and doc.storage_mode == "database":
has_pdf = self._has_blob_in_db(session, doc.id)
@@ -641,8 +634,7 @@ class LibraryService:
),
"file_name": Path(doc.file_path).name
if doc.file_path
- and doc.file_path
- not in ("metadata_only", "text_only_not_stored")
+ and doc.file_path not in FILE_PATH_SENTINELS
else doc.filename,
"file_size": doc.file_size,
"file_type": doc.file_type,
diff --git a/src/local_deep_research/research_library/services/pdf_storage_manager.py b/src/local_deep_research/research_library/services/pdf_storage_manager.py
index 5bbfb90a0f..47382058a5 100644
--- a/src/local_deep_research/research_library/services/pdf_storage_manager.py
+++ b/src/local_deep_research/research_library/services/pdf_storage_manager.py
@@ -17,6 +17,7 @@ from urllib.parse import urlparse
from loguru import logger
from sqlalchemy.orm import Session
+from ...constants import FILE_PATH_SENTINELS
from ...database.models.library import Document, DocumentBlob
from ...security.path_validator import PathValidator
@@ -58,10 +59,7 @@ class PDFStorageManager:
Returns:
Validated absolute Path or None if path is invalid/unsafe
"""
- if not relative_path or relative_path in (
- "metadata_only",
- "text_only_not_stored",
- ):
+ if not relative_path or relative_path in FILE_PATH_SENTINELS:
return None
try:
@@ -199,7 +197,7 @@ class PDFStorageManager:
# Check filesystem (with path traversal protection)
file_path = self._get_safe_file_path(document.file_path)
- if file_path and file_path.exists():
+ if file_path and file_path.is_file():
return True
return False
@@ -212,11 +210,8 @@ class PDFStorageManager:
# If there's a blob, it's database storage
if hasattr(document, "blob") and document.blob:
return "database"
- # If there's a file_path (and not 'metadata_only'), it's filesystem
- if document.file_path and document.file_path not in (
- "metadata_only",
- "text_only_not_stored",
- ):
+ # If there's a file_path (and not a sentinel), it's filesystem
+ if document.file_path and document.file_path not in FILE_PATH_SENTINELS:
return "filesystem"
# Otherwise no storage
return "none"
@@ -303,7 +298,7 @@ class PDFStorageManager:
if not file_path:
return None
- if not file_path.exists():
+ if not file_path.is_file():
logger.warning(f"PDF file not found: {file_path}")
return None
@@ -376,7 +371,7 @@ class PDFStorageManager:
if storage_mode == "filesystem":
# Use safe path resolution to prevent path traversal attacks
file_path = self._get_safe_file_path(document.file_path)
- if file_path and file_path.exists():
+ if file_path and file_path.is_file():
file_path.unlink()
logger.info(f"Deleted PDF file: {file_path}")
document.file_path = None
diff --git a/src/local_deep_research/research_library/utils/__init__.py b/src/local_deep_research/research_library/utils/__init__.py
index 4e69aa0fe1..4ce19dd063 100644
--- a/src/local_deep_research/research_library/utils/__init__.py
+++ b/src/local_deep_research/research_library/utils/__init__.py
@@ -169,12 +169,16 @@ def get_library_storage_path(username: str) -> Path:
settings = get_settings_manager()
# Get the base path from settings (uses centralized path, respects LDR_DATA_DIR)
- base_path = Path(
- settings.get_setting(
- "research_library.storage_path",
- str(get_library_directory()),
+ base_path = (
+ Path(
+ settings.get_setting(
+ "research_library.storage_path",
+ str(get_library_directory()),
+ )
)
- ).expanduser()
+ .expanduser()
+ .resolve()
+ )
# Check if shared library mode is enabled
shared_library = settings.get_setting(
@@ -271,7 +275,11 @@ def get_absolute_library_path(
safe_path = PathValidator.validate_safe_path(
relative_path, str(library_root)
)
- return Path(safe_path)
+ result = Path(safe_path)
+ if result.is_symlink():
+ logger.warning(f"Symlink blocked: {relative_path}")
+ return None
+ return result
except ValueError as e:
logger.warning(f"Path traversal blocked: {relative_path} - {e}")
return None
@@ -292,12 +300,16 @@ def get_absolute_path_from_settings(relative_path: str) -> Optional[Path]:
from ...utilities.db_utils import get_settings_manager
settings = get_settings_manager()
- library_root = Path(
- settings.get_setting(
- "research_library.storage_path",
- str(get_library_directory()),
+ library_root = (
+ Path(
+ settings.get_setting(
+ "research_library.storage_path",
+ str(get_library_directory()),
+ )
)
- ).expanduser()
+ .expanduser()
+ .resolve()
+ )
if not relative_path:
return library_root
@@ -307,7 +319,11 @@ def get_absolute_path_from_settings(relative_path: str) -> Optional[Path]:
safe_path = PathValidator.validate_safe_path(
relative_path, str(library_root)
)
- return Path(safe_path)
+ result = Path(safe_path)
+ if result.is_symlink():
+ logger.warning(f"Symlink blocked: {relative_path}")
+ return None
+ return result
except ValueError as e:
logger.warning(f"Path traversal blocked: {relative_path} - {e}")
return None
diff --git a/tests/deletion/test_document_deletion.py b/tests/deletion/test_document_deletion.py
index dabf8b76ac..d7f8c0caf2 100644
--- a/tests/deletion/test_document_deletion.py
+++ b/tests/deletion/test_document_deletion.py
@@ -21,6 +21,9 @@ from local_deep_research.database.models.library import (
Collection,
SourceType,
)
+from local_deep_research.constants import (
+ FILE_PATH_BLOB_DELETED,
+)
from local_deep_research.database.models.base import Base
@@ -284,13 +287,13 @@ class TestBlobDeletion:
doc = test_session.query(Document).get(doc_id)
doc.storage_mode = "none"
- doc.file_path = "blob_deleted"
+ doc.file_path = FILE_PATH_BLOB_DELETED
test_session.commit()
# Verify update
doc_after = test_session.query(Document).get(doc_id)
assert doc_after.storage_mode == "none"
- assert doc_after.file_path == "blob_deleted"
+ assert doc_after.file_path == FILE_PATH_BLOB_DELETED
def test_delete_blob_frees_bytes(self, test_session, test_document):
"""Verify bytes freed calculation is correct."""
diff --git a/tests/research_library/deletion/utils/test_cascade_helper.py b/tests/research_library/deletion/utils/test_cascade_helper.py
index fb84e31bda..0c5321a3e6 100644
--- a/tests/research_library/deletion/utils/test_cascade_helper.py
+++ b/tests/research_library/deletion/utils/test_cascade_helper.py
@@ -3,6 +3,9 @@
from unittest.mock import MagicMock, patch
+from local_deep_research.constants import (
+ FILE_PATH_SENTINELS,
+)
from local_deep_research.research_library.deletion.utils.cascade_helper import (
CascadeHelper,
)
@@ -149,7 +152,7 @@ class TestCascadeHelperDeleteFilesystemFile:
def test_skips_special_path_markers(self):
"""Should skip special path markers."""
- for marker in ("metadata_only", "text_only_not_stored", "blob_deleted"):
+ for marker in FILE_PATH_SENTINELS:
result = CascadeHelper.delete_filesystem_file(marker)
assert result is False
diff --git a/tests/research_library/deletion/utils/test_cascade_helper_edge_cases.py b/tests/research_library/deletion/utils/test_cascade_helper_edge_cases.py
index ec307cc56c..1343f5835e 100644
--- a/tests/research_library/deletion/utils/test_cascade_helper_edge_cases.py
+++ b/tests/research_library/deletion/utils/test_cascade_helper_edge_cases.py
@@ -7,6 +7,11 @@ zero-count returns, delete_document_completely ordering.
import pytest
from unittest.mock import MagicMock, patch
+from local_deep_research.constants import (
+ FILE_PATH_METADATA_ONLY,
+ FILE_PATH_TEXT_ONLY,
+ FILE_PATH_BLOB_DELETED,
+)
from local_deep_research.research_library.deletion.utils.cascade_helper import (
CascadeHelper,
)
@@ -21,7 +26,7 @@ class TestDeleteFilesystemFile:
@pytest.mark.parametrize(
"marker",
- ["metadata_only", "text_only_not_stored", "blob_deleted"],
+ [FILE_PATH_METADATA_ONLY, FILE_PATH_TEXT_ONLY, FILE_PATH_BLOB_DELETED],
)
def test_returns_false_for_each_special_marker(self, marker):
"""Each special marker individually returns False."""
diff --git a/tests/research_library/services/test_pdf_storage_manager.py b/tests/research_library/services/test_pdf_storage_manager.py
index 71db8313dd..9158a1af27 100644
--- a/tests/research_library/services/test_pdf_storage_manager.py
+++ b/tests/research_library/services/test_pdf_storage_manager.py
@@ -3,6 +3,9 @@
from unittest.mock import MagicMock, patch
+from local_deep_research.constants import (
+ FILE_PATH_METADATA_ONLY,
+)
from local_deep_research.research_library.services.pdf_storage_manager import (
PDFStorageManager,
)
@@ -416,7 +419,7 @@ class TestPDFStorageManagerInferStorageMode:
"""Should infer none mode for metadata_only documents."""
manager = PDFStorageManager(tmp_path, "database")
mock_doc = MagicMock(spec=["file_path"])
- mock_doc.file_path = "metadata_only"
+ mock_doc.file_path = FILE_PATH_METADATA_ONLY
result = manager._infer_storage_mode(mock_doc)
diff --git a/tests/research_library/services/test_pdf_storage_manager_edge_cases.py b/tests/research_library/services/test_pdf_storage_manager_edge_cases.py
index 1dc73c6bd7..c289122193 100644
--- a/tests/research_library/services/test_pdf_storage_manager_edge_cases.py
+++ b/tests/research_library/services/test_pdf_storage_manager_edge_cases.py
@@ -4,6 +4,11 @@ import hashlib
from pathlib import Path
from unittest.mock import MagicMock, Mock, patch
+from local_deep_research.constants import (
+ FILE_PATH_TEXT_ONLY,
+ FILE_PATH_BLOB_DELETED,
+)
+
def _make_manager(storage_mode="database", library_root="/tmp/test_lib"):
"""Create a PDFStorageManager for testing."""
@@ -95,8 +100,7 @@ class TestHasPdfSentinel:
source = inspect.getsource(PDFStorageManager._get_safe_file_path)
# Verify the sentinel value appears in the source code's exclusion check
- assert "text_only_not_stored" in source
- assert "metadata_only" in source
+ assert "FILE_PATH_SENTINELS" in source
class TestInferStorageMode:
@@ -106,7 +110,17 @@ class TestInferStorageMode:
"""'text_only_not_stored' sentinel is correctly treated as no storage."""
manager = _make_manager()
document = Mock()
- document.file_path = "text_only_not_stored"
+ document.file_path = FILE_PATH_TEXT_ONLY
+ document.blob = None
+
+ result = manager._infer_storage_mode(document)
+ assert result == "none"
+
+ def test_infer_storage_mode_blob_deleted(self):
+ """'blob_deleted' sentinel is correctly treated as no storage."""
+ manager = _make_manager()
+ document = Mock()
+ document.file_path = FILE_PATH_BLOB_DELETED
document.blob = None
result = manager._infer_storage_mode(document)
diff --git a/tests/research_library/test_utils.py b/tests/research_library/test_utils.py
index f38ff15a01..fb2d2768fe 100644
--- a/tests/research_library/test_utils.py
+++ b/tests/research_library/test_utils.py
@@ -7,6 +7,12 @@ Tests path traversal protection and utility functions.
from pathlib import Path
from unittest.mock import patch, Mock
+from local_deep_research.constants import (
+ FILE_PATH_METADATA_ONLY,
+ FILE_PATH_TEXT_ONLY,
+ FILE_PATH_BLOB_DELETED,
+)
+
class TestGetAbsoluteLibraryPath:
"""Tests for get_absolute_library_path function."""
@@ -114,6 +120,29 @@ class TestGetAbsoluteLibraryPath:
assert result is not None
assert result == tmp_path / "pdfs/2024/01/document.pdf"
+ def test_symlink_blocked(self, tmp_path):
+ """Symlinks should be blocked in get_absolute_library_path."""
+ import pytest
+
+ from local_deep_research.research_library.utils import (
+ get_absolute_library_path,
+ )
+
+ # Create a symlink inside library root pointing outside
+ link_path = tmp_path / "evil_link"
+ try:
+ link_path.symlink_to("/etc/passwd")
+ except OSError:
+ pytest.skip("Cannot create symlinks in this environment")
+
+ with patch(
+ "local_deep_research.research_library.utils.get_library_storage_path"
+ ) as mock_storage:
+ mock_storage.return_value = tmp_path
+
+ result = get_absolute_library_path("evil_link", "testuser")
+ assert result is None
+
class TestGetAbsolutePathFromSettings:
"""Tests for get_absolute_path_from_settings function."""
@@ -176,6 +205,31 @@ class TestGetAbsolutePathFromSettings:
result = get_absolute_path_from_settings(path)
assert result is None, f"Path '{path}' should have been blocked"
+ def test_symlink_blocked(self, tmp_path):
+ """Symlinks should be blocked in get_absolute_path_from_settings."""
+ import pytest
+
+ from local_deep_research.research_library.utils import (
+ get_absolute_path_from_settings,
+ )
+
+ # Create a symlink inside library root pointing outside
+ link_path = tmp_path / "evil_link"
+ try:
+ link_path.symlink_to("/etc/passwd")
+ except OSError:
+ pytest.skip("Cannot create symlinks in this environment")
+
+ mock_settings = Mock()
+ mock_settings.get_setting.return_value = str(tmp_path)
+
+ with patch(
+ "local_deep_research.utilities.db_utils.get_settings_manager",
+ return_value=mock_settings,
+ ):
+ result = get_absolute_path_from_settings("evil_link")
+ assert result is None
+
class TestLibraryServiceSafeAbsolutePath:
"""Tests for LibraryService._get_safe_absolute_path method."""
@@ -188,7 +242,7 @@ class TestLibraryServiceSafeAbsolutePath:
service = LibraryService("testuser")
- result = service._get_safe_absolute_path("metadata_only")
+ result = service._get_safe_absolute_path(FILE_PATH_METADATA_ONLY)
assert result is None
@@ -200,7 +254,7 @@ class TestLibraryServiceSafeAbsolutePath:
service = LibraryService("testuser")
- result = service._get_safe_absolute_path("text_only_not_stored")
+ result = service._get_safe_absolute_path(FILE_PATH_TEXT_ONLY)
assert result is None
@@ -931,7 +985,11 @@ class TestCascadeHelperPathSafety:
CascadeHelper,
)
- markers = ["metadata_only", "text_only_not_stored", "blob_deleted"]
+ markers = [
+ FILE_PATH_METADATA_ONLY,
+ FILE_PATH_TEXT_ONLY,
+ FILE_PATH_BLOB_DELETED,
+ ]
for marker in markers:
result = CascadeHelper.delete_filesystem_file(marker)
assert result is False, f"Marker '{marker}' should be rejected"
diff --git a/tests/security/test_pdf_path_traversal.py b/tests/security/test_pdf_path_traversal.py
index 5fa1794a44..8678735342 100644
--- a/tests/security/test_pdf_path_traversal.py
+++ b/tests/security/test_pdf_path_traversal.py
@@ -7,9 +7,13 @@ Verifies:
"""
import pytest
-from pathlib import Path
from unittest.mock import MagicMock, patch
+from local_deep_research.constants import (
+ FILE_PATH_METADATA_ONLY,
+ FILE_PATH_TEXT_ONLY,
+ FILE_PATH_BLOB_DELETED,
+)
from local_deep_research.research_library.services.pdf_storage_manager import (
PDFStorageManager,
)
@@ -18,43 +22,62 @@ from local_deep_research.research_library.services.pdf_storage_manager import (
class TestValidateFilesystemPath:
"""Test _get_safe_file_path blocks unsafe paths."""
- def setup_method(self):
- self.tmp = Path("/tmp/test_pdf_library")
- self.tmp.mkdir(exist_ok=True)
- self.manager = PDFStorageManager(
- library_root=str(self.tmp), storage_mode="filesystem"
- )
-
- def test_traversal_blocked(self):
+ def test_traversal_blocked(self, tmp_path):
"""Path with .. escaping library root returns None."""
- result = self.manager._get_safe_file_path("../../etc/passwd")
+ manager = PDFStorageManager(
+ library_root=str(tmp_path), storage_mode="filesystem"
+ )
+ result = manager._get_safe_file_path("../../etc/passwd")
assert result is None
- def test_valid_relative_path(self):
+ def test_valid_relative_path(self, tmp_path):
"""Valid relative path inside library root returns resolved Path."""
- sub = self.tmp / "docs"
+ sub = tmp_path / "docs"
sub.mkdir(exist_ok=True)
test_file = sub / "paper.pdf"
test_file.write_text("pdf content")
- result = self.manager._get_safe_file_path("docs/paper.pdf")
+ manager = PDFStorageManager(
+ library_root=str(tmp_path), storage_mode="filesystem"
+ )
+ result = manager._get_safe_file_path("docs/paper.pdf")
assert result is not None
- assert result.is_relative_to(self.tmp)
+ assert result.is_relative_to(tmp_path)
+
+ def test_metadata_only_returns_none(self, tmp_path):
+ manager = PDFStorageManager(
+ library_root=str(tmp_path), storage_mode="filesystem"
+ )
+ result = manager._get_safe_file_path(FILE_PATH_METADATA_ONLY)
+ assert result is None
- def test_metadata_only_returns_none(self):
- result = self.manager._get_safe_file_path("metadata_only")
+ def test_text_only_returns_none(self, tmp_path):
+ manager = PDFStorageManager(
+ library_root=str(tmp_path), storage_mode="filesystem"
+ )
+ result = manager._get_safe_file_path(FILE_PATH_TEXT_ONLY)
assert result is None
- def test_text_only_returns_none(self):
- result = self.manager._get_safe_file_path("text_only_not_stored")
+ def test_blob_deleted_returns_none(self, tmp_path):
+ """blob_deleted sentinel should return None (not construct a path)."""
+ manager = PDFStorageManager(
+ library_root=str(tmp_path), storage_mode="filesystem"
+ )
+ result = manager._get_safe_file_path(FILE_PATH_BLOB_DELETED)
assert result is None
- def test_empty_string_returns_none(self):
- result = self.manager._get_safe_file_path("")
+ def test_empty_string_returns_none(self, tmp_path):
+ manager = PDFStorageManager(
+ library_root=str(tmp_path), storage_mode="filesystem"
+ )
+ result = manager._get_safe_file_path("")
assert result is None
- def test_none_returns_none(self):
- result = self.manager._get_safe_file_path(None)
+ def test_none_returns_none(self, tmp_path):
+ manager = PDFStorageManager(
+ library_root=str(tmp_path), storage_mode="filesystem"
+ )
+ result = manager._get_safe_file_path(None)
assert result is None
def test_symlink_blocked(self, tmp_path):