Don't pass unicode to hmac.new()

This issue can be hit when swift3 middleware is in the pipeline.

Change-Id: If87a6663efcf31febe4a207b3d7f331b5f79b834
Signed-off-by: Prashanth Pai <ppai@redhat.com>
This commit is contained in:
Prashanth Pai 2016-02-19 11:29:23 +05:30
parent f195a5f6ec
commit 2e4c9f954a
2 changed files with 21 additions and 0 deletions

View File

@ -344,6 +344,13 @@ class Swauth(object):
password = detail['auth'].split(':')[-1]
msg = base64.urlsafe_b64decode(unquote(token))
# https://bugs.python.org/issue5285
if isinstance(password, unicode):
password = password.encode('utf-8')
if isinstance(msg, unicode):
msg = msg.encode('utf-8')
s = base64.encodestring(hmac.new(password,
msg, sha1).digest()).strip()
if s != sign:

View File

@ -3935,6 +3935,20 @@ class TestAuth(unittest.TestCase):
auth.filter_factory({'default_storage_policy': 'ssd'})(FakeApp())
self.assertEqual(ath.default_storage_policy, 'ssd')
def test_s3_creds_unicode(self):
self.test_auth.app = FakeApp(iter([
('200 Ok', {},
json.dumps({"auth": unicode("plaintext:key)"),
"groups": [{'name': "act:usr"}, {'name': "act"},
{'name': ".admin"}]})),
('204 Ok', {'X-Container-Meta-Account-Id': 'AUTH_act'}, '')]))
env = \
{'HTTP_AUTHORIZATION': 'AWS act:user:3yW7oFFWOn+fhHMu7E47RKotL1Q=',
'PATH_INFO': '/v1/AUTH_act/c1'}
token = 'UFVUCgoKRnJpLCAyNiBGZWIgMjAxNiAwNjo0NT'\
'ozNCArMDAwMAovY29udGFpbmVyMw=='
self.assertEqual(self.test_auth.get_groups(env, token), None)
if __name__ == '__main__':
unittest.main()