Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3: Do not unquote the key two times on multipart upload complete #6287

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions moto/s3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1888,9 +1888,13 @@ def put_object(
return new_key

def put_object_acl(
self, bucket_name: str, key_name: str, acl: Optional[FakeAcl]
self,
bucket_name: str,
key_name: str,
acl: Optional[FakeAcl],
key_is_clean: bool = False,
) -> None:
key = self.get_object(bucket_name, key_name)
key = self.get_object(bucket_name, key_name, key_is_clean=key_is_clean)
# TODO: Support the XML-based ACL format
if key is not None:
key.set_acl(acl)
Expand Down
7 changes: 6 additions & 1 deletion moto/s3/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,12 @@ def _key_response_post(
)
key.set_metadata(multipart.metadata)
self.backend.set_key_tags(key, multipart.tags)
self.backend.put_object_acl(bucket_name, key.name, multipart.acl)
self.backend.put_object_acl(
bucket_name=bucket_name,
key_name=key.name,
acl=multipart.acl,
key_is_clean=True,
)

template = self.response_template(S3_MULTIPART_COMPLETE_RESPONSE)
headers: Dict[str, Any] = {}
Expand Down
13 changes: 7 additions & 6 deletions tests/test_s3/test_s3_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,34 +107,35 @@ def test_multipart_upload_too_small():
)


@pytest.mark.parametrize("key", ["the-key", "the%20key"])
@mock_s3
@reduced_min_part_size
def test_multipart_upload():
def test_multipart_upload(key: str):
s3 = boto3.resource("s3", region_name=DEFAULT_REGION_NAME)
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
s3.create_bucket(Bucket="foobar")

part1 = b"0" * REDUCED_PART_SIZE
part2 = b"1"
mp = client.create_multipart_upload(Bucket="foobar", Key="the-key")
mp = client.create_multipart_upload(Bucket="foobar", Key=key)
up1 = client.upload_part(
Body=BytesIO(part1),
PartNumber=1,
Bucket="foobar",
Key="the-key",
Key=key,
UploadId=mp["UploadId"],
)
up2 = client.upload_part(
Body=BytesIO(part2),
PartNumber=2,
Bucket="foobar",
Key="the-key",
Key=key,
UploadId=mp["UploadId"],
)

client.complete_multipart_upload(
Bucket="foobar",
Key="the-key",
Key=key,
MultipartUpload={
"Parts": [
{"ETag": up1["ETag"], "PartNumber": 1},
Expand All @@ -144,7 +145,7 @@ def test_multipart_upload():
UploadId=mp["UploadId"],
)
# we should get both parts as the key contents
response = client.get_object(Bucket="foobar", Key="the-key")
response = client.get_object(Bucket="foobar", Key=key)
response["Body"].read().should.equal(part1 + part2)


Expand Down