[#7787] ticket:689 Handle unicode in ldap usernames and passwords
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index ea66b60..006a8e0 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -562,7 +562,10 @@
if ldap is None:
raise Exception('The python-ldap package needs to be installed. Run `pip install python-ldap` in your allura environment.')
from allura import model as M
- username = self.request.params['username']
+ try:
+ username = str(self.request.params['username'])
+ except UnicodeEncodeError:
+ raise exc.HTTPBadRequest('Unicode is not allowed in usernames')
if not self._validate_password(username, self.request.params['password']):
raise exc.HTTPUnauthorized()
user = M.User.query.get(username=username)
@@ -586,6 +589,7 @@
def _validate_password(self, username, password):
'''by username'''
+ password = h.really_unicode(password).encode('utf-8')
try:
ldap_user = ldap_user_dn(username)
except ValueError:
diff --git a/Allura/allura/lib/widgets/auth_widgets.py b/Allura/allura/lib/widgets/auth_widgets.py
index 33444f9..22f4429 100644
--- a/Allura/allura/lib/widgets/auth_widgets.py
+++ b/Allura/allura/lib/widgets/auth_widgets.py
@@ -66,6 +66,12 @@
dict(username=value['username'], rememberme=value.get('rememberme'),
return_to=value.get('return_to')),
None)
+ except exc.HTTPBadRequest as e:
+ raise Invalid(
+ e.message,
+ dict(username=value['username'], rememberme=value.get('rememberme'),
+ return_to=value.get('return_to')),
+ None)
return value