Make put-object-acl return 404 if the key does not exist (#3777)

Co-authored-by: Tibor Djurica Potpara <tibor.djurica@reddit.com>
This commit is contained in:
Tibor Djurica Potpara 2021-03-16 22:24:41 +00:00 committed by GitHub
parent b9f83c200f
commit b06e77b604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -1305,8 +1305,11 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
if "acl" in query:
key = self.backend.get_object(bucket_name, key_name)
# TODO: Support the XML-based ACL format
key.set_acl(acl)
return 200, response_headers, ""
if key is not None:
key.set_acl(acl)
return 200, response_headers, ""
else:
raise MissingKey(key_name)
if "tagging" in query:
if "versionId" in query:

View File

@ -979,6 +979,17 @@ def test_acl_switching():
), grants
@mock_s3
def test_acl_switching_nonexistent_key():
s3 = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
s3.create_bucket(Bucket="mybucket")
with pytest.raises(ClientError) as e:
s3.put_object_acl(Bucket="mybucket", Key="nonexistent", ACL="private")
e.value.response["Error"]["Code"].should.equal("NoSuchKey")
@mock_s3_deprecated
def test_bucket_acl_setting():
conn = boto.connect_s3()