|
| 1 | +import boto3 |
| 2 | +import pytest |
| 3 | +import requests |
| 4 | + |
| 5 | +from moto import settings |
| 6 | +from moto.s3.responses import DEFAULT_REGION_NAME |
| 7 | +from tests import allow_aws_request |
| 8 | + |
| 9 | +from . import s3_aws_verified |
| 10 | +from .test_s3 import add_proxy_details |
| 11 | + |
| 12 | + |
| 13 | +@s3_aws_verified |
| 14 | +@pytest.mark.aws_verified |
| 15 | +def test_presigned_url_generates_content_response_headers(bucket_name=None): |
| 16 | + client = boto3.client("s3", DEFAULT_REGION_NAME) |
| 17 | + s3_resource = boto3.resource("s3", region_name=DEFAULT_REGION_NAME) |
| 18 | + bucket = s3_resource.Bucket(bucket_name) |
| 19 | + bucket.put_object(Body=b"ABCD", Key="file.txt") |
| 20 | + |
| 21 | + params = { |
| 22 | + "Bucket": bucket.name, |
| 23 | + "Key": "file.txt", |
| 24 | + "ResponseCacheControl": "max-age=74", |
| 25 | + "ResponseContentDisposition": 'attachment; filename="foo.jpg"', |
| 26 | + "ResponseContentEncoding": "identity", |
| 27 | + "ResponseContentLanguage": "de-DE", |
| 28 | + "ResponseContentType": "image/jpeg", |
| 29 | + "ResponseExpires": "Wed, 21 Oct 2015 07:28:00 GMT", |
| 30 | + } |
| 31 | + presigned_url = client.generate_presigned_url("get_object", params, ExpiresIn=900) |
| 32 | + get_kwargs = {} |
| 33 | + if not allow_aws_request() and settings.is_test_proxy_mode(): |
| 34 | + add_proxy_details(get_kwargs) |
| 35 | + response = requests.get(presigned_url, **get_kwargs) |
| 36 | + |
| 37 | + assert response.content == b"ABCD" |
| 38 | + |
| 39 | + assert response.headers.get("Cache-Control") == "max-age=74" |
| 40 | + assert ( |
| 41 | + response.headers.get("Content-Disposition") == 'attachment; filename="foo.jpg"' |
| 42 | + ) |
| 43 | + assert response.headers.get("Content-Encoding") == "identity" |
| 44 | + assert response.headers.get("Content-Language") == "de-DE" |
| 45 | + assert response.headers.get("Content-Type") == "image/jpeg" |
| 46 | + assert response.headers.get("Content-Length") == "4" |
| 47 | + assert response.headers.get("Expires") == "Wed, 21 Oct 2015 07:28:00 GMT" |
0 commit comments