diff --git a/keystone/token/backends/memcache.py b/keystone/token/backends/memcache.py index 8ab1f86d96..a62f3421a6 100644 --- a/keystone/token/backends/memcache.py +++ b/keystone/token/backends/memcache.py @@ -54,12 +54,12 @@ class Token(token.Driver): def get_token(self, token_id): if token_id is None: raise exception.TokenNotFound(token_id='') - ptk = self._prefix_token_id(token_id) - token = self.client.get(ptk) - if token is None: + ptk = self._prefix_token_id(token.unique_id(token_id)) + token_ref = self.client.get(ptk) + if token_ref is None: raise exception.TokenNotFound(token_id=token_id) - return token + return token_ref def create_token(self, token_id, data): data_copy = copy.deepcopy(data) @@ -107,7 +107,7 @@ class Token(token.Driver): user_record = self.client.get(user_key) or "" token_list = jsonutils.loads('[%s]' % user_record) for token_id in token_list: - ptk = self._prefix_token_id(token_id) + ptk = self._prefix_token_id(token.unique_id(token_id)) token_ref = self.client.get(ptk) if token_ref: if tenant_id is not None: diff --git a/tests/test_backend.py b/tests/test_backend.py index 6768e9c57c..a73440678f 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -1949,8 +1949,14 @@ class IdentityTests(object): class TokenTests(object): + def _create_token_id(self): + token_id = "" + for i in range(1, 20): + token_id += uuid.uuid4().hex + return token_id + def test_token_crud(self): - token_id = uuid.uuid4().hex + token_id = self._create_token_id() data = {'id': token_id, 'a': 'b', 'trust_id': None, 'user': {'id': 'testuserid'}} @@ -1974,7 +1980,7 @@ class TokenTests(object): self.token_api.delete_token, token_id) def create_token_sample_data(self, tenant_id=None, trust_id=None): - token_id = uuid.uuid4().hex + token_id = self._create_token_id() data = {'id': token_id, 'a': 'b', 'user': {'id': 'testuserid'}} if tenant_id is not None: diff --git a/tests/test_backend_memcache.py b/tests/test_backend_memcache.py index b7f26b1dde..9fbaeb9067 100644 --- a/tests/test_backend_memcache.py +++ b/tests/test_backend_memcache.py @@ -79,14 +79,14 @@ class MemcacheToken(test.TestCase, test_backend.TokenTests): self.token_api = token_memcache.Token(client=fake_client) def test_create_unicode_token_id(self): - token_id = unicode(uuid.uuid4().hex) + token_id = unicode(self._create_token_id()) data = {'id': token_id, 'a': 'b', 'user': {'id': 'testuserid'}} self.token_api.create_token(token_id, data) self.token_api.get_token(token_id) def test_create_unicode_user_id(self): - token_id = uuid.uuid4().hex + token_id = self._create_token_id() user_id = unicode(uuid.uuid4().hex) data = {'id': token_id, 'a': 'b', 'user': {'id': user_id}}