Skip to content

Commit

Permalink
Fixed unicode username user creation error
Browse files Browse the repository at this point in the history
The code tries to construct a byte string object to test the
length of the string field (The explicit construction of the
string object is neccessary as sometime v can be other types,
for example int). This will cause error if the string field
(v) is a unicode object.

Fixes bug #1166701

Change-Id: I73cee4da5c9f91ce135e7f81d88c979871f61767
  • Loading branch information
LiangChen77 committed Apr 13, 2013
1 parent cbac771 commit 78dcfc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion keystone/common/sql/core.py
Expand Up @@ -73,8 +73,10 @@ def initialize(self, *args, **kwargs):
if isinstance(attr, InstrumentedAttribute):
column = attr.property.columns[0]
if isinstance(column.type, String):
if not isinstance(v, unicode):
v = str(v)
if column.type.length and \
column.type.length < len(str(v)):
column.type.length < len(v):
#if signing.token_format == 'PKI', the id will
#store it's public key which is very long.
if config.CONF.signing.token_format == 'PKI' and \
Expand Down
9 changes: 9 additions & 0 deletions tests/test_backend.py
Expand Up @@ -136,6 +136,15 @@ def test_password_hashed(self):
user_ref = self.identity_api._get_user(self.user_foo['id'])
self.assertNotEqual(user_ref['password'], self.user_foo['password'])

def test_create_unicode_user_name(self):
unicode_name = u'name \u540d\u5b57'
user = {'id': uuid.uuid4().hex,
'name': unicode_name,
'domain_id': DEFAULT_DOMAIN_ID,
'password': uuid.uuid4().hex}
ref = self.identity_api.create_user(user['id'], user)
self.assertEqual(unicode_name, ref['name'])

def test_get_project(self):
tenant_ref = self.identity_api.get_project(
tenant_id=self.tenant_bar['id'])
Expand Down

0 comments on commit 78dcfc6

Please sign in to comment.