diff options
author | Daniel G. Taylor <danielgtaylor@gmail.com> | 2014-08-13 15:37:23 -0700 |
---|---|---|
committer | Daniel G. Taylor <danielgtaylor@gmail.com> | 2014-08-13 15:37:23 -0700 |
commit | b161f611081e9dc4369d53cc12957137fe6a9579 (patch) | |
tree | 1b05123494eb783074d52a42d5e6cc1e412a4499 | |
parent | 3cbbc21b61852738adbeda837588b60b5857ce68 (diff) | |
download | boto-b161f611081e9dc4369d53cc12957137fe6a9579.tar.gz |
Support auth when headers contains bytes
This fixes #2520 by checking whether headers are `bytes` and decoding
them before performing string operations. It adds a new test covering
this functionality which now passes on all supported Python versions.
-rw-r--r-- | boto/auth.py | 2 | ||||
-rw-r--r-- | tests/unit/auth/test_sigv4.py | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/boto/auth.py b/boto/auth.py index 6012962a..bc8290d7 100644 --- a/boto/auth.py +++ b/boto/auth.py @@ -317,6 +317,8 @@ class HmacAuthV4Handler(AuthHandler, HmacKeys): for name, value in http_request.headers.items(): lname = name.lower() if lname.startswith('x-amz'): + if isinstance(value, bytes): + value = value.decode('utf-8') headers_to_sign[name] = value return headers_to_sign diff --git a/tests/unit/auth/test_sigv4.py b/tests/unit/auth/test_sigv4.py index 674ec0a7..7b4afa5c 100644 --- a/tests/unit/auth/test_sigv4.py +++ b/tests/unit/auth/test_sigv4.py @@ -251,6 +251,17 @@ class TestSigV4Handler(unittest.TestCase): auth2 = pickle.loads(pickled) self.assertEqual(auth.host, auth2.host) + def test_bytes_header(self): + auth = HmacAuthV4Handler('glacier.us-east-1.amazonaws.com', + mock.Mock(), self.provider) + request = HTTPRequest( + 'GET', 'http', 'glacier.us-east-1.amazonaws.com', 80, + 'x/./././x .html', None, {}, + {'x-amz-glacier-version': '2012-06-01', 'x-amz-hash': b'f00'}, '') + canonical = auth.canonical_request(request) + + self.assertIn('f00', canonical) + class TestS3HmacAuthV4Handler(unittest.TestCase): def setUp(self): |