Skip to content

Commit

Permalink
add custom error message for using crc32c without crt (#2905)
Browse files Browse the repository at this point in the history
* add custom error message for using crc32c without crt

* pr feedback
  • Loading branch information
dlm6693 authored Apr 11, 2023
1 parent 63d5d35 commit 2318884
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion botocore/httpchecksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,14 @@ def resolve_request_checksum_algorithm(
supported_algorithms = _SUPPORTED_CHECKSUM_ALGORITHMS

algorithm_name = params[algorithm_member].lower()
if algorithm_name not in supported_algorithms:
if algorithm_name == "crc32c" and not HAS_CRT:
raise FlexibleChecksumError(
error_msg=(
"Using CRC32C requires an additional dependency. You will "
"need to pip install botocore[crt] before proceeding."
)
)
elif algorithm_name not in supported_algorithms:
raise FlexibleChecksumError(
error_msg="Unsupported checksum algorithm: %s" % algorithm_name
)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_httpchecksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from io import BytesIO

from botocore.awsrequest import AWSResponse
from botocore.compat import HAS_CRT
from botocore.exceptions import AwsChunkedWrapperError, FlexibleChecksumError
from botocore.httpchecksum import (
_CHECKSUM_CLS,
Expand Down Expand Up @@ -172,6 +173,22 @@ def test_request_checksum_algorithm_model_unsupported_algorithm(self):
request, operation_model, params, supported_algorithms=[]
)

@unittest.skipIf(HAS_CRT, "Error only expected when CRT is not available")
def test_request_checksum_algorithm_model_no_crt_crc32c_unsupported(self):
request = self._build_request(b"")
operation_model = self._make_operation_model(
http_checksum={"requestAlgorithmMember": "Algorithm"},
)
params = {"Algorithm": "crc32c"}
with self.assertRaises(FlexibleChecksumError) as context:
resolve_request_checksum_algorithm(
request, operation_model, params
)
self.assertIn(
"Using CRC32C requires an additional dependency",
str(context.exception),
)

def test_request_checksum_algorithm_model_legacy_md5(self):
request = self._build_request(b"")
operation_model = self._make_operation_model(required=True)
Expand Down

0 comments on commit 2318884

Please sign in to comment.