S3: fix copy in place when requesting checksum (#6308)

This commit is contained in:
Ben Simon Hartung 2023-05-10 17:59:55 +03:00 committed by GitHub
parent ebe48e7443
commit 417561cec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -1627,7 +1627,7 @@ class S3Response(BaseResponse):
checksum_algorithm = request.headers.get("x-amz-checksum-algorithm")
if checksum_algorithm:
checksum_value = compute_checksum(
key_to_copy.value, algorithm=checksum_algorithm
new_key.value, algorithm=checksum_algorithm
).decode("utf-8")
response_headers.update(
{"Checksum": {f"Checksum{checksum_algorithm}": checksum_value}}

View File

@ -68,6 +68,18 @@ def test_copy_key_boto3_with_sha256_checksum():
assert "ChecksumSHA256" in resp["Checksum"]
assert resp["Checksum"]["ChecksumSHA256"] == expected_hash
# Verify in place
copy_in_place = client.copy_object(
Bucket=bucket,
CopySource=f"{bucket}/{new_key}",
Key=new_key,
ChecksumAlgorithm="SHA256",
MetadataDirective="REPLACE",
)
assert "ChecksumSHA256" in copy_in_place["CopyObjectResult"]
assert copy_in_place["CopyObjectResult"]["ChecksumSHA256"] == expected_hash
@mock_s3
def test_copy_key_with_version_boto3():