From 7a31dd71006ae0dbd9fe99776a7031a95a816947 Mon Sep 17 00:00:00 2001 From: JordonPhillips Date: Tue, 23 Feb 2016 12:09:23 -0800 Subject: [PATCH] Don't use MD5 with s3v4 --- botocore/handlers.py | 2 +- tests/unit/test_handlers.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/botocore/handlers.py b/botocore/handlers.py index 32d4eda48b..1b8f07b9af 100644 --- a/botocore/handlers.py +++ b/botocore/handlers.py @@ -150,7 +150,7 @@ def _calculate_md5_from_file(fileobj): def conditionally_calculate_md5(params, **kwargs): """Only add a Content-MD5 when not using sigv4""" signer = kwargs['request_signer'] - if signer.signature_version != 'v4': + if signer.signature_version not in ['v4', 's3v4']: calculate_md5(params, **kwargs) diff --git a/tests/unit/test_handlers.py b/tests/unit/test_handlers.py index aa8ef20752..bcbbf76680 100644 --- a/tests/unit/test_handlers.py +++ b/tests/unit/test_handlers.py @@ -521,6 +521,18 @@ def test_does_not_add_md5_when_v4(self): request_signer=request_signer) self.assertTrue('Content-MD5' not in request_dict['headers']) + def test_does_not_add_md5_when_s3v4(self): + credentials = Credentials('key', 'secret') + request_signer = RequestSigner( + 's3', 'us-east-1', 's3', 's3v4', credentials, mock.Mock()) + request_dict = {'body': b'bar', + 'url': 'https://s3.us-east-1.amazonaws.com', + 'method': 'PUT', + 'headers': {}} + handlers.conditionally_calculate_md5(request_dict, + request_signer=request_signer) + self.assertTrue('Content-MD5' not in request_dict['headers']) + def test_adds_md5_when_not_v4(self): credentials = Credentials('key', 'secret') request_signer = RequestSigner(