Fix:s3 Presign Post with object acl (#3246)

* Fix:s3 Presign Post with object acl

* Added import in tests

Co-authored-by: usmankb <usman@krazybee.com>
This commit is contained in:
usmangani1 2020-09-02 23:05:53 +05:30 committed by GitHub
parent 3fb7cf75d4
commit d2e16ecc2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -860,6 +860,10 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
new_key = self.backend.set_object(bucket_name, key, f) new_key = self.backend.set_object(bucket_name, key, f)
if form.get("acl"):
acl = get_canned_acl(form.get("acl"))
new_key.set_acl(acl)
# Metadata # Metadata
metadata = metadata_from_headers(form) metadata = metadata_from_headers(form)
new_key.set_metadata(metadata) new_key.set_metadata(metadata)

View File

@ -2800,6 +2800,39 @@ def test_put_bucket_acl_body():
assert not result.get("Grants") assert not result.get("Grants")
@mock_s3
def test_object_acl_with_presigned_post():
s3 = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
bucket_name = "imageS3Bucket"
object_name = "text.txt"
fields = {"acl": "public-read"}
file = open("text.txt", "w")
file.write("test")
file.close()
s3.create_bucket(Bucket=bucket_name)
response = s3.generate_presigned_post(
bucket_name, object_name, Fields=fields, ExpiresIn=60000
)
with open(object_name, "rb") as f:
files = {"file": (object_name, f)}
requests.post(response["url"], data=response["fields"], files=files)
response = s3.get_object_acl(Bucket=bucket_name, Key=object_name)
assert "Grants" in response
assert len(response["Grants"]) == 2
assert response["Grants"][1]["Permission"] == "READ"
response = s3.get_object(Bucket=bucket_name, Key=object_name)
assert "ETag" in response
assert "Body" in response
os.remove("text.txt")
@mock_s3 @mock_s3
def test_put_bucket_notification(): def test_put_bucket_notification():
s3 = boto3.client("s3", region_name=DEFAULT_REGION_NAME) s3 = boto3.client("s3", region_name=DEFAULT_REGION_NAME)