fix: restore all code deleted/truncated by d2217531 Jules SSRF commit

Commit d2217531 (google-labs-jules SSRF fix) catastrophically deleted
11,500+ lines across 100+ files while fixing an unrelated IMAP issue.

Restored from d2217531^ (pre-bad-commit state):

Deleted files (fully restored):
- app/api/{automation,classification_rules,comments,sharing}.py
- app/middleware/upload_rate_limit.py
- app/tasks/{automation_tasks,classify_document}.py
- app/utils/{automation_hooks,classification_rules}.py
- docs/AppleAppStoreCompliance.md
- frontend/input.css, package.json, package-lock.json, tailwind.config.js
- frontend/static/js/{annotations,claim,comments,sharing}.js
- frontend/templates/{admin_connections,file_annotations,file_summary}.html
- tests/{test_api_files_comprehensive,test_auth_extended,test_sharing,
         test_comments,test_connections,test_imap_profiles,test_api_sessions,
         test_automation,test_classification_rules,test_api_advanced_filters,
         test_api_classification_rules,test_upload_rate_limit,test_api_dropbox,
         test_classify_document,test_comments_ui,test_upload_to_icloud,
         test_api_onedrive_comprehensive,test_frontend_build,test_sentry,
         test_diagnostic,test_database,test_views_dropbox,test_local_auth}.py

Truncated files (content restored):
- app/{auth,config,main,models,celery_worker,database}.py
- app/api/{__init__,api_tokens,diagnostic,dropbox,files,google_drive,
           integrations,local_auth,mobile,onedrive,pipelines,qr_auth,
           settings,url_upload}.py
- app/middleware/upload_rate_limit.py
- app/tasks/upload_to_nextcloud.py
- app/utils/{allowed_types,settings_service,settings_sync,user_scope,webhook}.py
- app/views/{base,dropbox,files,google_drive,onedrive,settings}.py
- docs/{API,AuthenticationSetup,ConfigurationGuide,DatabaseConfiguration,
        DeploymentGuide,DropboxSetup,GoogleDriveSetup,KubernetesDeployment,
        MobileApp,OneDriveSetup,ProductionReadiness,SentrySetup,
        SocialLoginSetup,UserGuide}.md
- frontend/static/{js/upload.js,styles.css}
- frontend/templates/{api_tokens,base,devices,dropbox,dropbox_callback,
                      file_view,files,google_drive,onedrive,onedrive_callback,
                      signup}.html
- frontend/translations/en.json
- migrations/env.py
- tests/{conftest,test_api_integrations,test_api_mobile,test_api_settings,
         test_api_tokens,test_audit_logs,test_duplicates,test_imap_tasks,
         test_setup_wizard,test_views_files_comprehensive}.py

Security fixes kept from post-d2217531 commits:
- app/utils/network.py: DNS SSRF fail-secure fix (06b0fced)
- app/utils/file_operations.py: path traversal fix (1018ea17)
- tests/test_imap_tasks.py: re-applied 4 is_private_ip mock patches

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
Agent-Logs-Url: https://github.com/christianlouis/DocuElevate/sessions/51133dd8-9bec-41ab-aa10-3de753634187
This commit is contained in:
copilot-swe-agent[bot]
2026-03-23 23:52:39 +00:00
parent 11a49eb7fd
commit c7d3ec57c3
115 changed files with 23532 additions and 1043 deletions
+135
View File
@@ -210,6 +210,141 @@ class TestGetAppVersion:
assert _get_app_version() is None
@pytest.mark.unit
class TestSentryJsTemplateContext:
"""Test that Sentry Browser SDK config is injected into the template context."""
def test_sentry_dsn_exposed_when_configured(self, mocker):
"""sentry_dsn is set in the template context when SENTRY_DSN is configured."""
mock_settings = mocker.patch("app.views.base.settings")
mock_settings.sentry_dsn = "https://key@o1.ingest.sentry.io/1"
mock_settings.sentry_environment = "production"
mock_settings.sentry_js_traces_sample_rate = 0.1
mock_settings.sentry_js_replay_session_sample_rate = 0.0
mock_settings.sentry_js_replay_on_error_sample_rate = 0.1
from app.views.base import _inject_global_context
ctx: dict = {}
_inject_global_context(ctx)
assert ctx["sentry_dsn"] == "https://key@o1.ingest.sentry.io/1"
def test_sentry_dsn_none_when_not_configured(self, mocker):
"""sentry_dsn is None in the template context when SENTRY_DSN is unset."""
mock_settings = mocker.patch("app.views.base.settings")
mock_settings.sentry_dsn = None
mock_settings.sentry_environment = "production"
mock_settings.sentry_js_traces_sample_rate = 0.0
mock_settings.sentry_js_replay_session_sample_rate = 0.0
mock_settings.sentry_js_replay_on_error_sample_rate = 0.1
from app.views.base import _inject_global_context
ctx: dict = {}
_inject_global_context(ctx)
assert ctx["sentry_dsn"] is None
def test_sentry_dsn_empty_string_becomes_none(self, mocker):
"""An empty-string SENTRY_DSN is normalised to None in the template context."""
mock_settings = mocker.patch("app.views.base.settings")
mock_settings.sentry_dsn = ""
mock_settings.sentry_environment = "production"
mock_settings.sentry_js_traces_sample_rate = 0.0
mock_settings.sentry_js_replay_session_sample_rate = 0.0
mock_settings.sentry_js_replay_on_error_sample_rate = 0.1
from app.views.base import _inject_global_context
ctx: dict = {}
_inject_global_context(ctx)
assert ctx["sentry_dsn"] is None
def test_js_sample_rates_exposed_in_context(self, mocker):
"""Browser SDK sample rates are passed through to the template context."""
mock_settings = mocker.patch("app.views.base.settings")
mock_settings.sentry_dsn = "https://key@o1.ingest.sentry.io/1"
mock_settings.sentry_environment = "staging"
mock_settings.sentry_js_traces_sample_rate = 0.5
mock_settings.sentry_js_replay_session_sample_rate = 0.2
mock_settings.sentry_js_replay_on_error_sample_rate = 0.8
from app.views.base import _inject_global_context
ctx: dict = {}
_inject_global_context(ctx)
assert ctx["sentry_environment"] == "staging"
assert ctx["sentry_js_traces_sample_rate"] == 0.5
assert ctx["sentry_js_replay_session_sample_rate"] == 0.2
assert ctx["sentry_js_replay_on_error_sample_rate"] == 0.8
def test_js_sample_rates_default_values(self, mocker):
"""Browser SDK sample rates fall back to safe defaults when attrs are absent."""
mock_settings = mocker.patch("app.views.base.settings")
# Simulate settings object without the new JS attributes
del mock_settings.sentry_js_traces_sample_rate
del mock_settings.sentry_js_replay_session_sample_rate
del mock_settings.sentry_js_replay_on_error_sample_rate
mock_settings.sentry_dsn = None
mock_settings.sentry_environment = "production"
from app.views.base import _inject_global_context
ctx: dict = {}
_inject_global_context(ctx)
assert ctx["sentry_js_traces_sample_rate"] == 0.0
assert ctx["sentry_js_replay_session_sample_rate"] == 0.0
assert ctx["sentry_js_replay_on_error_sample_rate"] == 0.1
_MINIMAL_SETTINGS_KWARGS = {
"database_url": "sqlite:///./test.db",
"redis_url": "redis://localhost:6379",
"openai_api_key": "test",
"azure_ai_key": "test",
"azure_region": "test",
"azure_endpoint": "https://test.example.com",
"gotenberg_url": "http://localhost:3000",
"workdir": "/tmp",
"auth_enabled": False,
"session_secret": "a-test-secret-that-is-at-least-32-chars-long!",
}
@pytest.mark.unit
class TestSentryJsConfig:
"""Test the new JS-specific Settings fields."""
def test_js_traces_sample_rate_default(self):
"""SENTRY_JS_TRACES_SAMPLE_RATE defaults to 0.0."""
from app.config import settings
assert settings.sentry_js_traces_sample_rate == 0.0
def test_js_replay_session_sample_rate_default(self):
"""SENTRY_JS_REPLAY_SESSION_SAMPLE_RATE defaults to 0.0."""
from app.config import settings
assert settings.sentry_js_replay_session_sample_rate == 0.0
def test_js_replay_on_error_sample_rate_default(self):
"""SENTRY_JS_REPLAY_ON_ERROR_SAMPLE_RATE defaults to 0.1."""
from app.config import settings
assert settings.sentry_js_replay_on_error_sample_rate == 0.1
def test_js_traces_sample_rate_can_be_set(self):
"""SENTRY_JS_TRACES_SAMPLE_RATE can be set directly via constructor."""
from app.config import Settings
s = Settings(**_MINIMAL_SETTINGS_KWARGS, sentry_js_traces_sample_rate=0.5)
assert s.sentry_js_traces_sample_rate == 0.5
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------