diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 3b40c8701..7bf70dfbf 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -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}} diff --git a/tests/test_s3/test_s3_copyobject.py b/tests/test_s3/test_s3_copyobject.py index 156918a84..5a54a0537 100644 --- a/tests/test_s3/test_s3_copyobject.py +++ b/tests/test_s3/test_s3_copyobject.py @@ -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():