S3 - Allow for keyname that is just an empty space (#4244)

This commit is contained in:
Bert Blommers 2021-10-09 10:12:26 +00:00 committed by GitHub
parent acf34a685f
commit 773e9a9f79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -964,7 +964,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
def _bucket_response_delete_keys(self, request, body, bucket_name):
template = self.response_template(S3_DELETE_KEYS_RESPONSE)
body_dict = xmltodict.parse(body)
body_dict = xmltodict.parse(body, strip_whitespace=False)
objects = body_dict["Delete"].get("Object", [])
if not isinstance(objects, list):

View File

@ -6587,3 +6587,22 @@ def test_create_bucket_duplicate():
"Your previous request to create the named bucket succeeded and you already own it."
)
err["BucketName"].should.equal(bucket_name)
@mock_s3
def test_delete_objects_with_empty_keyname():
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
resource = boto3.resource("s3", region_name=DEFAULT_REGION_NAME)
bucket_name = "testbucket-4077"
bucket = resource.create_bucket(Bucket=bucket_name)
key_name = " "
bucket.put_object(Key=key_name, Body=b"")
client.list_objects(Bucket=bucket_name).should.have.key("Contents").length_of(1)
bucket.delete_objects(Delete={"Objects": [{"Key": key_name}]})
client.list_objects(Bucket=bucket_name).shouldnt.have.key("Contents")
bucket.put_object(Key=key_name, Body=b"")
client.delete_object(Bucket=bucket_name, Key=key_name)
client.list_objects(Bucket=bucket_name).shouldnt.have.key("Contents")