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
+144 -2
View File
@@ -1,5 +1,7 @@
"""Tests for the per-user integrations API (app/api/integrations.py)."""
import unittest.mock
import pytest
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
@@ -887,9 +889,9 @@ class TestConnectionTestEndpoint:
def test_test_unsupported_type(self, int_client):
"""Unsupported integration types return a helpful non-error message."""
payload = {
"integration_type": "DROPBOX",
"integration_type": "FTP",
"config": {},
"credentials": {"token": "abc"},
"credentials": {"username": "user", "password": "pass"},
}
resp = int_client.post("/api/integrations/test", json=payload)
assert resp.status_code == 200
@@ -897,6 +899,83 @@ class TestConnectionTestEndpoint:
assert data["success"] is False
assert "not yet supported" in data["message"]
def test_test_dropbox_missing_refresh_token(self, int_client):
"""Dropbox test with missing refresh_token returns failure."""
payload = {
"integration_type": "DROPBOX",
"config": {},
"credentials": {"app_key": "key", "app_secret": "secret"},
}
resp = int_client.post("/api/integrations/test", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["success"] is False
assert "refresh_token" in data["message"].lower()
def test_test_dropbox_missing_app_key(self, int_client):
"""Dropbox test with missing app_key/app_secret returns failure."""
payload = {
"integration_type": "DROPBOX",
"config": {},
"credentials": {"refresh_token": "rtoken"},
}
resp = int_client.post("/api/integrations/test", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["success"] is False
assert "app_key" in data["message"].lower()
def test_test_dropbox_invalid_credentials(self, int_client):
"""Dropbox test with bad credentials returns an auth failure."""
from unittest.mock import MagicMock, patch
import dropbox.exceptions as dbx_exc
with patch("app.api.integrations.dbx_lib") as mock_dbx:
mock_instance = MagicMock()
mock_dbx.Dropbox.return_value = mock_instance
mock_instance.users_get_current_account.side_effect = dbx_exc.AuthError("req_id", MagicMock())
payload = {
"integration_type": "DROPBOX",
"config": {},
"credentials": {
"app_key": "bad_key",
"app_secret": "bad_secret",
"refresh_token": "bad_token",
},
}
resp = int_client.post("/api/integrations/test", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["success"] is False
assert "authentication failed" in data["message"].lower()
def test_test_dropbox_success(self, int_client):
"""Dropbox test with valid (mocked) credentials returns success."""
from unittest.mock import MagicMock, patch
with patch("app.api.integrations.dbx_lib") as mock_dbx:
mock_instance = MagicMock()
mock_dbx.Dropbox.return_value = mock_instance
mock_account = MagicMock()
mock_account.name.display_name = "Test User"
mock_instance.users_get_current_account.return_value = mock_account
payload = {
"integration_type": "DROPBOX",
"config": {},
"credentials": {
"app_key": "valid_key",
"app_secret": "valid_secret",
"refresh_token": "valid_token",
},
}
resp = int_client.post("/api/integrations/test", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["success"] is True
assert "dropbox connection successful" in data["message"].lower()
def test_test_invalid_type_returns_400(self, int_client):
"""Invalid integration_type returns 400."""
payload = {
@@ -984,6 +1063,69 @@ class TestConnectionTestEndpoint:
assert data["success"] is False
assert "scheme" in data["message"].lower()
@unittest.mock.patch("httpx.request")
def test_test_webdav_success(self, mock_request, int_client):
"""WebDAV test succeeds with valid credentials and a valid status code."""
mock_response = unittest.mock.MagicMock()
mock_response.status_code = 207 # Typical WebDAV success for PROPFIND
mock_request.return_value = mock_response
payload = {
"integration_type": "WEBDAV",
"config": {"url": "https://example.com/webdav"},
"credentials": {"username": "user1", "password": "password123"},
}
resp = int_client.post("/api/integrations/test", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["success"] is True
mock_request.assert_called_once_with(
"PROPFIND",
"https://example.com/webdav",
auth=("user1", "password123"),
headers={"Depth": "0"},
timeout=10.0,
follow_redirects=False,
)
@unittest.mock.patch("httpx.request")
def test_test_webdav_failure_status(self, mock_request, int_client):
"""WebDAV test fails if the server returns a 4xx or 5xx status code."""
mock_response = unittest.mock.MagicMock()
mock_response.status_code = 401
mock_request.return_value = mock_response
payload = {
"integration_type": "WEBDAV",
"config": {"url": "https://example.com/webdav"},
"credentials": {"username": "user1", "password": "wrong"},
}
resp = int_client.post("/api/integrations/test", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["success"] is False
assert "401" in data["message"]
@unittest.mock.patch("httpx.request")
def test_test_webdav_exception(self, mock_request, int_client):
"""WebDAV test fails gracefully if an exception occurs during the request."""
mock_request.side_effect = Exception("Connection error")
payload = {
"integration_type": "WEBDAV",
"config": {"url": "https://example.com/webdav"},
"credentials": {},
}
resp = int_client.post("/api/integrations/test", json=payload)
assert resp.status_code == 200
data = resp.json()
assert data["success"] is False
assert "failed" in data["message"].lower()
# ---------------------------------------------------------------------------
# Quota endpoint tests