Merge "Fix token hashing with python 3"

This commit is contained in:
Jenkins 2016-03-22 19:44:02 +00:00 committed by Gerrit Code Review
commit 6304da9292
2 changed files with 2 additions and 5 deletions

View File

@ -29,9 +29,7 @@ from keystoneclient.v2_0 import client as client_v2
from keystoneclient.v3 import client as client_v3 from keystoneclient.v3 import client as client_v3
import mock import mock
from mox3 import mox from mox3 import mox
import sys
from testscenarios import load_tests_apply_scenarios # noqa from testscenarios import load_tests_apply_scenarios # noqa
import unittest
from openstack_auth import policy from openstack_auth import policy
from openstack_auth.tests import data_v2 from openstack_auth.tests import data_v2
@ -1165,7 +1163,6 @@ class UserTestCase(test.TestCase):
def setUp(self): def setUp(self):
self.data = data_v3.generate_test_data(pki=True) self.data = data_v3.generate_test_data(pki=True)
@unittest.skipIf(sys.version_info >= (3, 0), "Bug #1552443")
def test_unscoped_token_is_none(self): def test_unscoped_token_is_none(self):
created_token = user.Token(self.data.domain_scoped_access_info, created_token = user.Token(self.data.domain_scoped_access_info,
unscoped_token=None) unscoped_token=None)

View File

@ -88,12 +88,12 @@ class Token(object):
algorithm = getattr(settings, 'OPENSTACK_TOKEN_HASH_ALGORITHM', algorithm = getattr(settings, 'OPENSTACK_TOKEN_HASH_ALGORITHM',
'md5') 'md5')
hasher = hashlib.new(algorithm) hasher = hashlib.new(algorithm)
hasher.update(self.id) hasher.update(self.id.encode('utf-8'))
self.id = hasher.hexdigest() self.id = hasher.hexdigest()
# Only hash unscoped token if needed # Only hash unscoped token if needed
if self._is_pki_token(self.unscoped_token): if self._is_pki_token(self.unscoped_token):
hasher = hashlib.new(algorithm) hasher = hashlib.new(algorithm)
hasher.update(self.unscoped_token) hasher.update(self.unscoped_token.encode('utf-8'))
self.unscoped_token = hasher.hexdigest() self.unscoped_token = hasher.hexdigest()
self.expires = auth_ref.expires self.expires = auth_ref.expires