Skip to content

Commit 045c6ed

Browse files
committed
jira python83: unicode names and passwords should be encoded as utf8, with test
1 parent 24e0330 commit 045c6ed

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

pymongo/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def _password_digest(self, username, password):
361361
raise TypeError("username must be an instance of (str, unicode)")
362362

363363
md5hash = _md5func()
364-
md5hash.update(username + ":mongo:" + password)
364+
md5hash.update(username.encode('utf-8') + ":mongo:" + password.encode('utf-8'))
365365
return unicode(md5hash.hexdigest())
366366

367367
def authenticate(self, name, password):

test/test_database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ def test_password_digest(self):
227227
u"cd7e45b3b2767dc2fa9b6b548457ed00")
228228
self.assertEqual(db._password_digest("mike", "password"),
229229
db._password_digest(u"mike", u"password"))
230+
self.assertEqual(db._password_digest("Gustave", u"Dor\xe9"),
231+
u"81e0e2364499209f466e75926a162d73")
230232

231233
def test_authenticate(self):
232234
db = self.connection.pymongo_test

0 commit comments

Comments
 (0)