Skip to content

Commit 4245e18

Browse files
committed
Allow lower case checksum algorithms
This is was made to keep parity with the pure Python transfer manager which accepts lowercase algorithm values.
1 parent 3a7e6e4 commit 4245e18

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

awscli/s3transfer/crt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ def _validate_checksum_algorithm_supported(self, extra_args):
236236
checksum_algorithm = extra_args.get('ChecksumAlgorithm')
237237
if checksum_algorithm is None:
238238
return
239-
if checksum_algorithm not in awscrt.s3.S3ChecksumAlgorithm.__members__:
239+
supported_algorithms = list(awscrt.s3.S3ChecksumAlgorithm.__members__)
240+
if checksum_algorithm.upper() not in supported_algorithms:
240241
raise ValueError(
241242
f'ChecksumAlgorithm: {checksum_algorithm} not supported. '
242-
f'Supported algorithms are: '
243-
f'{list(awscrt.s3.S3ChecksumAlgorithm.__members__)}'
243+
f'Supported algorithms are: {supported_algorithms}'
244244
)
245245

246246
def _cancel_transfers(self):
@@ -637,7 +637,7 @@ def _get_make_request_args_put_object(
637637

638638
checksum_algorithm = call_args.extra_args.pop(
639639
'ChecksumAlgorithm', 'CRC32'
640-
)
640+
).upper()
641641
checksum_config = awscrt.s3.S3ChecksumConfig(
642642
algorithm=awscrt.s3.S3ChecksumAlgorithm[checksum_algorithm],
643643
location=awscrt.s3.S3ChecksumLocation.TRAILER,

tests/functional/s3transfer/test_crt.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,42 @@ def test_upload_override_checksum_algorithm(self):
307307
)
308308
self._assert_subscribers_called(future)
309309

310+
def test_upload_override_checksum_algorithm_accepts_lowercase(self):
311+
future = self.transfer_manager.upload(
312+
self.filename,
313+
self.bucket,
314+
self.key,
315+
{'ChecksumAlgorithm': 'crc32c'},
316+
[self.record_subscriber],
317+
)
318+
future.result()
319+
320+
callargs_kwargs = self.s3_crt_client.make_request.call_args[1]
321+
self.assertEqual(
322+
callargs_kwargs,
323+
{
324+
'request': mock.ANY,
325+
'type': awscrt.s3.S3RequestType.PUT_OBJECT,
326+
'send_filepath': self.filename,
327+
'on_progress': mock.ANY,
328+
'on_done': mock.ANY,
329+
'checksum_config': self._get_expected_upload_checksum_config(
330+
algorithm=awscrt.s3.S3ChecksumAlgorithm.CRC32C
331+
),
332+
},
333+
)
334+
self._assert_expected_crt_http_request(
335+
callargs_kwargs["request"],
336+
expected_http_method='PUT',
337+
expected_content_length=len(self.expected_content),
338+
expected_missing_headers=[
339+
'Content-MD5',
340+
'x-amz-sdk-checksum-algorithm',
341+
'X-Amz-Trailer',
342+
],
343+
)
344+
self._assert_subscribers_called(future)
345+
310346
def test_upload_throws_error_for_unsupported_checksum(self):
311347
with self.assertRaisesRegex(
312348
ValueError, 'ChecksumAlgorithm: UNSUPPORTED not supported'

0 commit comments

Comments
 (0)