S3: Checksum headers added to response (#5392)

This commit is contained in:
Cristopher Pinzón 2022-08-23 14:48:19 -05:00 committed by GitHub
parent f05d56afc5
commit 7affaf3e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -1356,6 +1356,16 @@ class S3Response(BaseResponse):
"x-amz-server-side-encryption-aws-kms-key-id", None
)
checksum_algorithm = request.headers.get("x-amz-sdk-checksum-algorithm", "")
checksum_header = f"x-amz-checksum-{checksum_algorithm.lower()}"
checksum_value = request.headers.get(checksum_header)
if not checksum_value and checksum_algorithm:
search = re.search(r"x-amz-checksum-\w+:(\w+={1,2})", body.decode())
checksum_value = search.group(1) if search else None
if checksum_value:
response_headers.update({checksum_header: checksum_value})
bucket_key_enabled = request.headers.get(
"x-amz-server-side-encryption-bucket-key-enabled", None
)

View File

@ -3395,3 +3395,21 @@ def test_prefix_encoding():
map(lambda common_prefix: common_prefix["Prefix"], data["CommonPrefixes"])
)
assert ["foo%2Fbar/", "foo/"] == folders
@mock_s3
@pytest.mark.parametrize("algorithm", ["CRC32", "CRC32C", "SHA1", "SHA256"])
def test_checksum_response(algorithm):
bucket_name = "checksum-bucket"
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
client.create_bucket(Bucket=bucket_name)
if (
algorithm != "CRC32C"
): # awscrt is required to allow botocore checksum with CRC32C
response = client.put_object(
Bucket=bucket_name,
Key="test-key",
Body=b"data",
ChecksumAlgorithm=algorithm,
)
assert f"Checksum{algorithm}" in response