""" P1 FB-08: Path-Traversal-Sanitization + Response-Size-Cap Tests. Tests for _sanitize_file_path_component and download_file security fixes. """ from __future__ import annotations import sys import unittest from pathlib import Path from unittest.mock import MagicMock, patch sys.path.insert(0, str(Path(__file__).resolve().parents[3])) class TestSanitizeFilePathComponent(unittest.TestCase): """P1 FB-08: _sanitize_file_path_component strips dangerous characters.""" def test_normal_filename_passes(self): """Normal filenames pass through unchanged.""" from plugin.adapter import _sanitize_file_path_component assert _sanitize_file_path_component("report.pdf") == "report.pdf" assert _sanitize_file_path_component("my-file_2024.txt") == "my-file_2024.txt" assert _sanitize_file_path_component("abc123") == "abc123" def test_path_traversal_stripped(self): """Path traversal characters are removed.""" from plugin.adapter import _sanitize_file_path_component assert _sanitize_file_path_component("../etc/passwd") == "..etcpasswd" assert _sanitize_file_path_component("..\\windows\\system32") == "..windowssystem32" def test_special_chars_stripped(self): """Special characters are removed.""" from plugin.adapter import _sanitize_file_path_component assert _sanitize_file_path_component("file name.txt") == "filename.txt" assert _sanitize_file_path_component("file