Files
learningcircuit--local-deep…/tests/security/test_security_init_deep_coverage.py
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

174 lines
5.4 KiB
Python

"""Deep coverage tests for security/__init__.py.
The __init__.py conditionally imports several optional components:
- PathValidator (requires werkzeug)
- FileUploadValidator (requires pdfplumber)
Tests cover:
- All required imports are present
- Conditional flag values
- __all__ completeness
- Individual security re-exports callable/usable
"""
MODULE = "local_deep_research.security"
class TestRequiredImportsAlwaysPresent:
"""These symbols must always be importable regardless of optional deps."""
def test_sanitize_data_present(self):
from local_deep_research.security import sanitize_data
assert callable(sanitize_data)
def test_redact_data_present(self):
from local_deep_research.security import redact_data
assert callable(redact_data)
def test_filter_research_metadata_present(self):
from local_deep_research.security import filter_research_metadata
assert callable(filter_research_metadata)
def test_safe_get_present(self):
from local_deep_research.security import safe_get
assert callable(safe_get)
def test_safe_post_present(self):
from local_deep_research.security import safe_post
assert callable(safe_post)
def test_validate_url_present(self):
from local_deep_research.security import validate_url
assert callable(validate_url)
def test_is_ip_blocked_present(self):
from local_deep_research.security import is_ip_blocked
assert callable(is_ip_blocked)
def test_get_account_lockout_manager_present(self):
from local_deep_research.security import get_account_lockout_manager
assert callable(get_account_lockout_manager)
def test_sanitize_for_log_present(self):
from local_deep_research.security import sanitize_for_log
assert callable(sanitize_for_log)
def test_strip_control_chars_present(self):
from local_deep_research.security import strip_control_chars
assert callable(strip_control_chars)
def test_get_safe_module_class_present(self):
from local_deep_research.security import get_safe_module_class
assert callable(get_safe_module_class)
def test_module_not_allowed_error_present(self):
from local_deep_research.security import ModuleNotAllowedError
assert issubclass(ModuleNotAllowedError, Exception)
def test_allowed_modules_present(self):
from local_deep_research.security import ALLOWED_MODULES
assert isinstance(ALLOWED_MODULES, (set, frozenset, dict, list))
def test_get_safe_url_present(self):
from local_deep_research.security import get_safe_url
assert callable(get_safe_url)
def test_strip_settings_snapshot_present(self):
from local_deep_research.security import strip_settings_snapshot
assert callable(strip_settings_snapshot)
def test_get_security_default_present(self):
from local_deep_research.security import get_security_default
assert callable(get_security_default)
def test_notification_url_validation_error_present(self):
from local_deep_research.security import NotificationURLValidationError
assert issubclass(NotificationURLValidationError, Exception)
class TestConditionalFlags:
def test_has_path_validator_flag_is_bool(self):
import local_deep_research.security as sec
assert isinstance(sec._has_path_validator, bool)
def test_has_file_upload_validator_flag_is_bool(self):
import local_deep_research.security as sec
assert isinstance(sec._has_file_upload_validator, bool)
def test_path_validator_is_class_or_none(self):
from local_deep_research.security import PathValidator
assert PathValidator is None or isinstance(PathValidator, type)
def test_file_upload_validator_is_class_or_none(self):
from local_deep_research.security import FileUploadValidator
assert FileUploadValidator is None or isinstance(
FileUploadValidator, type
)
def test_path_validator_flag_consistent_with_object(self):
import local_deep_research.security as sec
if sec._has_path_validator:
assert sec.PathValidator is not None
else:
assert sec.PathValidator is None
class TestDunderAll:
def test_all_is_list(self):
import local_deep_research.security as sec
assert isinstance(sec.__all__, list)
def test_all_contains_key_symbols(self):
import local_deep_research.security as sec
must_have = {
"DataSanitizer",
"sanitize_data",
"safe_get",
"safe_post",
"validate_url",
"PasswordValidator",
"AccountLockoutManager",
"sanitize_for_log",
"PathValidator",
"SecurityHeaders",
"URLValidator",
}
for sym in must_have:
assert sym in sec.__all__, f"{sym} missing from __all__"
def test_all_symbols_defined_as_attributes(self):
"""Every symbol in __all__ must be defined as an attribute (may be None)."""
import local_deep_research.security as sec
for name in sec.__all__:
assert hasattr(sec, name), f"{name} in __all__ but not defined"
def test_no_duplicates_in_all(self):
import local_deep_research.security as sec
assert len(sec.__all__) == len(set(sec.__all__))