mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-14 20:16:48 +00:00
Pg 4 (#2390)
* feat: postgres tests * feat: mongo cutoff * feat: mongo cutoff * feat: adjust docs and compose files * fix: mini code mongo removals * fix: tests and k8s mongo stuff * feat: test fixes * fix: ruff * fix: vale * Potential fix for pull request finding 'CodeQL / Clear-text logging of sensitive information' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix: mini suggestions * vale lint fix 2 * fix: codeql columns thing * fix: test mongo * fix: tests coverage * feat: better tests 4 * feat: more tests * feat: decent coverage * fix: ruff fixes * fix: remove mongo mock * feat: enhance workflow engine and API routes; add document retrieval and source handling * feat: e2e tests * fix: mcp, mongo and more * fix: mini codeql warning * fix: agent chunk view * fix: mini issues * fix: more pg fixes * feat: postgres prep on start * feat: qa tests * fix: mini improvements * fix: tests --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Siddhant Rai <siddhant.rai.5686@gmail.com>
This commit is contained in:
312 files changed
+763725
-25159
No files matched your search
@@ -126,13 +126,17 @@ class TestInitClient:
|
||||
|
||||
def test_init_client_with_custom_endpoint(self, s3_loader, mock_boto3):
|
||||
"""Should configure path-style addressing for custom endpoints."""
|
||||
s3_loader._init_client(
|
||||
aws_access_key_id="test-key",
|
||||
aws_secret_access_key="test-secret",
|
||||
region_name="us-east-1",
|
||||
endpoint_url="https://nyc3.digitaloceanspaces.com",
|
||||
bucket="my-bucket",
|
||||
)
|
||||
with patch(
|
||||
"application.parser.remote.s3_loader.validate_url",
|
||||
side_effect=lambda u: u,
|
||||
):
|
||||
s3_loader._init_client(
|
||||
aws_access_key_id="test-key",
|
||||
aws_secret_access_key="test-secret",
|
||||
region_name="us-east-1",
|
||||
endpoint_url="https://nyc3.digitaloceanspaces.com",
|
||||
bucket="my-bucket",
|
||||
)
|
||||
|
||||
call_kwargs = mock_boto3.client.call_args[1]
|
||||
assert call_kwargs["endpoint_url"] == "https://nyc3.digitaloceanspaces.com"
|
||||
@@ -140,13 +144,17 @@ class TestInitClient:
|
||||
|
||||
def test_init_client_normalizes_do_endpoint(self, s3_loader, mock_boto3):
|
||||
"""Should normalize DigitalOcean Spaces bucket-prefixed URLs."""
|
||||
corrected_bucket = s3_loader._init_client(
|
||||
aws_access_key_id="test-key",
|
||||
aws_secret_access_key="test-secret",
|
||||
region_name="us-east-1",
|
||||
endpoint_url="https://mybucket.nyc3.digitaloceanspaces.com",
|
||||
bucket="",
|
||||
)
|
||||
with patch(
|
||||
"application.parser.remote.s3_loader.validate_url",
|
||||
side_effect=lambda u: u,
|
||||
):
|
||||
corrected_bucket = s3_loader._init_client(
|
||||
aws_access_key_id="test-key",
|
||||
aws_secret_access_key="test-secret",
|
||||
region_name="us-east-1",
|
||||
endpoint_url="https://mybucket.nyc3.digitaloceanspaces.com",
|
||||
bucket="",
|
||||
)
|
||||
|
||||
assert corrected_bucket == "mybucket"
|
||||
call_kwargs = mock_boto3.client.call_args[1]
|
||||
@@ -555,7 +563,11 @@ class TestLoadData:
|
||||
"endpoint_url": "https://nyc3.digitaloceanspaces.com",
|
||||
}
|
||||
|
||||
s3_loader.load_data(input_data)
|
||||
with patch(
|
||||
"application.parser.remote.s3_loader.validate_url",
|
||||
side_effect=lambda u: u,
|
||||
):
|
||||
s3_loader.load_data(input_data)
|
||||
|
||||
call_kwargs = mock_boto3.client.call_args[1]
|
||||
assert call_kwargs["endpoint_url"] == "https://nyc3.digitaloceanspaces.com"
|
||||
@@ -631,7 +643,11 @@ class TestLoadData:
|
||||
"endpoint_url": "https://mybucket.nyc3.digitaloceanspaces.com",
|
||||
}
|
||||
|
||||
docs = s3_loader.load_data(input_data)
|
||||
with patch(
|
||||
"application.parser.remote.s3_loader.validate_url",
|
||||
side_effect=lambda u: u,
|
||||
):
|
||||
docs = s3_loader.load_data(input_data)
|
||||
|
||||
# Verify bucket name was corrected
|
||||
paginator.paginate.assert_called_once_with(Bucket="mybucket", Prefix="")
|
||||
@@ -835,3 +851,55 @@ class TestProcessDocumentAdditional:
|
||||
)
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
class TestSSRFValidation:
|
||||
"""Ensure user-supplied endpoint_url values cannot target internal networks."""
|
||||
|
||||
def test_init_client_rejects_loopback_endpoint(self, s3_loader, mock_boto3):
|
||||
"""Should refuse to initialize boto3 when endpoint points at localhost."""
|
||||
with pytest.raises(ValueError, match="Invalid S3 endpoint_url"):
|
||||
s3_loader._init_client(
|
||||
aws_access_key_id="k",
|
||||
aws_secret_access_key="s",
|
||||
region_name="us-east-1",
|
||||
endpoint_url="http://127.0.0.1:9000",
|
||||
bucket="b",
|
||||
)
|
||||
mock_boto3.client.assert_not_called()
|
||||
|
||||
def test_init_client_rejects_metadata_ip(self, s3_loader, mock_boto3):
|
||||
"""Should refuse to initialize boto3 when endpoint targets cloud metadata."""
|
||||
with pytest.raises(ValueError, match="Invalid S3 endpoint_url"):
|
||||
s3_loader._init_client(
|
||||
aws_access_key_id="k",
|
||||
aws_secret_access_key="s",
|
||||
region_name="us-east-1",
|
||||
endpoint_url="http://169.254.169.254/",
|
||||
bucket="b",
|
||||
)
|
||||
mock_boto3.client.assert_not_called()
|
||||
|
||||
def test_init_client_rejects_private_ip(self, s3_loader, mock_boto3):
|
||||
"""Should refuse to initialize boto3 when endpoint targets an RFC1918 host."""
|
||||
with pytest.raises(ValueError, match="Invalid S3 endpoint_url"):
|
||||
s3_loader._init_client(
|
||||
aws_access_key_id="k",
|
||||
aws_secret_access_key="s",
|
||||
region_name="us-east-1",
|
||||
endpoint_url="http://10.0.0.5:9000",
|
||||
bucket="b",
|
||||
)
|
||||
mock_boto3.client.assert_not_called()
|
||||
|
||||
def test_load_data_rejects_ssrf_endpoint(self, s3_loader, mock_boto3):
|
||||
"""load_data should surface a ValueError without hitting boto3 for blocked endpoints."""
|
||||
input_data = {
|
||||
"aws_access_key_id": "k",
|
||||
"aws_secret_access_key": "s",
|
||||
"bucket": "b",
|
||||
"endpoint_url": "http://localhost:9000",
|
||||
}
|
||||
with pytest.raises(ValueError, match="Invalid S3 endpoint_url"):
|
||||
s3_loader.load_data(input_data)
|
||||
mock_boto3.client.assert_not_called()
|
||||
Reference in new issue
Block a user