From 54ff0729566c600859e54af9019b68f8cf814667 Mon Sep 17 00:00:00 2001 From: YangLei Date: Fri, 6 Sep 2013 17:24:05 +0800 Subject: [PATCH] Decode the non-english username str to unicode convert the non-english username str to unicode, then the converted username can match the username from db. Fixes bug #1221576 Change-Id: I9e5f941fe43f081d75750e3f4754e8beea8210db --- keystoneclient/utils.py | 2 ++ tests/test_utils.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/keystoneclient/utils.py b/keystoneclient/utils.py index 479f7c01c..ae489c8de 100644 --- a/keystoneclient/utils.py +++ b/keystoneclient/utils.py @@ -99,6 +99,8 @@ def find_resource(manager, name_or_id): # finally try to find entity by name try: + if isinstance(name_or_id, str): + name_or_id = name_or_id.decode('utf-8', 'strict') return manager.find(name=name_or_id) except exceptions.NotFound: msg = ("No %s with a name or ID of '%s' exists." % diff --git a/tests/test_utils.py b/tests/test_utils.py index 94c4a09e6..36cf1e020 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -28,6 +28,7 @@ class FakeManager(object): resources = { '1234': {'name': 'entity_one'}, '8e8ec658-c7b0-4243-bdf8-6f7f2952c0d0': {'name': 'entity_two'}, + '\xe3\x82\xbdtest': {'name': u'\u30bdtest'}, '5678': {'name': '9876'} } @@ -72,6 +73,11 @@ class FindResourceTestCase(test_utils.TestCase): output = utils.find_resource(self.manager, uuid) self.assertEqual(output, self.manager.resources[uuid]) + def test_find_by_unicode(self): + name = '\xe3\x82\xbdtest' + output = utils.find_resource(self.manager, name) + self.assertEqual(output, self.manager.resources[name]) + def test_find_by_str_name(self): output = utils.find_resource(self.manager, 'entity_one') self.assertEqual(output, self.manager.resources['1234'])