Skip to content
Browse files

utf-8 encode user keys in memcache (bug 1056373)

Change-Id: I026dd4282742213e69c7aa02e109439b07a73c8e
  • Loading branch information...
1 parent cc0ce9b commit 431e50a7851d2e7dbb212d02647faeb958ed21e8 @dolph dolph committed Sep 25, 2012
Showing with 19 additions and 3 deletions.
  1. +6 −2 keystone/token/backends/memcache.py
  2. +13 −1 tests/test_backend_memcache.py
View
8 keystone/token/backends/memcache.py
@@ -48,6 +48,9 @@ def _get_memcache_client(self):
def _prefix_token_id(self, token_id):
return 'token-%s' % token_id.encode('utf-8')
+ def _prefix_user_id(self, user_id):
+ return 'usertokens-%s' % user_id.encode('utf-8')
+
def get_token(self, token_id):
ptk = self._prefix_token_id(token_id)
token = self.client.get(ptk)
@@ -69,7 +72,7 @@ def create_token(self, token_id, data):
if 'id' in data['user']:
token_data = jsonutils.dumps(token_id)
user_id = data['user']['id']
- user_key = 'usertokens-%s' % user_id
+ user_key = self._prefix_user_id(user_id)
if not self.client.append(user_key, ',%s' % token_data):
if not self.client.add(user_key, token_data):
if not self.client.append(user_key, ',%s' % token_data):
@@ -96,7 +99,8 @@ def delete_token(self, token_id):
def list_tokens(self, user_id, tenant_id=None):
tokens = []
- user_record = self.client.get('usertokens-%s' % user_id) or ""
+ user_key = self._prefix_user_id(user_id)
+ 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)
View
14 tests/test_backend_memcache.py
@@ -78,9 +78,21 @@ def setUp(self):
fake_client = MemcacheClient()
self.token_api = token_memcache.Token(client=fake_client)
- def test_get_unicode(self):
+ def test_create_unicode_token_id(self):
token_id = unicode(uuid.uuid4().hex)
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
+ user_id = unicode(uuid.uuid4().hex)
+ data = {'id': token_id, 'a': 'b',
+ 'user': {'id': user_id}}
+ self.token_api.create_token(token_id, data)
+ self.token_api.get_token(token_id)
+
+ def test_list_tokens_unicode_user_id(self):
+ user_id = unicode(uuid.uuid4().hex)
+ self.token_api.list_tokens(user_id)

0 comments on commit 431e50a

Please sign in to comment.
Something went wrong with that request. Please try again.