|
| 1 | +import re |
| 2 | +import tempfile |
| 3 | +from unittest.mock import AsyncMock, patch |
| 4 | + |
1 | 5 | import boto3 |
2 | 6 | from botocore.config import Config |
3 | 7 | from botocore.exceptions import ClientError |
4 | 8 | from fastapi import HTTPException |
5 | | -from unittest.mock import AsyncMock, patch |
6 | 9 | import pytest |
7 | | -import tempfile |
8 | 10 |
|
9 | 11 | from conftest import MOCKED_S3_RESPONSE_DICT, TEST_USER_ID, TEST_USER_TOKEN |
10 | 12 | from gen3workflow.config import config |
@@ -207,6 +209,21 @@ def test_s3_endpoint_wrong_bucket(s3_client, access_token_patcher, bucket_name): |
207 | 209 | s3_client.list_objects(Bucket=bucket_name) |
208 | 210 |
|
209 | 211 |
|
| 212 | +@pytest.mark.parametrize("client", [{"get_url": True}], indirect=True) |
| 213 | +def test_s3_endpoint_list_buckets(s3_client): |
| 214 | + """ |
| 215 | + Listing all the buckets the user can access is not supported, since users can only access |
| 216 | + their own bucket. |
| 217 | + """ |
| 218 | + with pytest.raises( |
| 219 | + ClientError, |
| 220 | + match=re.escape( |
| 221 | + "An error occurred (400) when calling the ListBuckets operation: Bad Request" |
| 222 | + ), |
| 223 | + ): |
| 224 | + s3_client.list_buckets() |
| 225 | + |
| 226 | + |
210 | 227 | @pytest.mark.asyncio |
211 | 228 | @pytest.mark.parametrize("path", ["s3", ""], ids=["s3 path", "root path"]) |
212 | 229 | async def test_s3_endpoint_with_bearer_token(client, path): |
@@ -331,7 +348,7 @@ async def test_set_access_token_and_get_user_id_invalid_auth(): |
331 | 348 | def test_s3_upload_file(s3_client, access_token_patcher, multipart): |
332 | 349 | """ |
333 | 350 | Test that the boto3 `upload_file` function works with the `/s3` endpoint, both for a small |
334 | | - file uploaded in 1 chunk and for a large file uploaded in multiple chunks. |
| 351 | + file uploaded in 1 part and for a large file uploaded in multiple parts. |
335 | 352 | """ |
336 | 353 | with patch( |
337 | 354 | "gen3workflow.aws_utils.get_existing_kms_key_for_bucket", |
|
0 commit comments