Merge "Fix token ids for memcached"

This commit is contained in:
Jenkins 2013-04-13 11:28:11 +00:00 committed by Gerrit Code Review
commit b4db547d0a
3 changed files with 15 additions and 9 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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}}