S3:CompleteMultipartUpload - error on empty part list

This commit is contained in:
Bert Blommers 2022-02-24 21:23:44 -01:00
parent 8ba4bb63c5
commit 142249fbdc
4 changed files with 35 additions and 8 deletions

View File

@ -365,6 +365,9 @@ class FakeMultipart(BaseModel):
last = part
count += 1
if count == 0:
raise MalformedXML
etag = hashlib.md5()
etag.update(bytes(md5s))
return total, "{0}-{1}".format(etag.hexdigest(), count)

View File

@ -8,5 +8,4 @@ TestAccAWSDefaultSecurityGroup_Classic_
TestAccDataSourceAwsNetworkInterface_CarrierIPAssociation
TestAccAWSRouteTable_IPv4_To_LocalGateway
TestAccAWSRouteTable_IPv4_To_VpcEndpoint
TestAccAWSRouteTable_VpcClassicLink
TestAccAWSS3BucketObject_updatesWithVersioningViaAccessPoint
TestAccAWSRouteTable_VpcClassicLink

View File

@ -120,9 +120,7 @@ TestAccAWSENI_Tags
TestAccAWSENI_basic
TestAccAWSENI_IPv6
TestAccAWSENI_disappears
TestAccAWSS3BucketObject
TestAccAWSS3BucketPolicy
TestAccAWSS3AccessPoint
TestAccAWSS3BucketPublicAccessBlock
TestAccAWSS3ObjectCopy
TestAccAWSIAMPolicy_

View File

@ -1,14 +1,14 @@
import boto3
import os
import pytest
import sure # noqa # pylint: disable=unused-import
from botocore.client import ClientError
from functools import wraps
from io import BytesIO
import boto3
from botocore.client import ClientError
from moto.s3.responses import DEFAULT_REGION_NAME
import sure # noqa # pylint: disable=unused-import
from moto import settings, mock_s3
import moto.s3.models as s3model
@ -839,3 +839,30 @@ def test_multipart_part_size():
for i in range(1, n_parts + 1):
obj = s3.head_object(Bucket="mybucket", Key="the-key", PartNumber=i)
assert obj["ContentLength"] == REDUCED_PART_SIZE + i
@mock_s3
def test_complete_multipart_with_empty_partlist():
"""
When completing a MultipartUpload with an empty part list, AWS responds with an InvalidXML-error
Verify that we send the same error, to duplicate boto3's behaviour
"""
bucket = "testbucketthatcompletesmultipartuploadwithoutparts"
key = "test-multi-empty"
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
client.create_bucket(Bucket=bucket)
response = client.create_multipart_upload(Bucket=bucket, Key=key,)
uid = response["UploadId"]
upload = boto3.resource("s3").MultipartUpload(bucket, key, uid)
with pytest.raises(ClientError) as exc:
upload.complete(MultipartUpload={"Parts": []})
err = exc.value.response["Error"]
err["Code"].should.equal("MalformedXML")
err["Message"].should.equal(
"The XML you provided was not well-formed or did not validate against our published schema"
)