allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [allura] 02/02: [#7878] ldap unicode fixes
Date Mon, 27 Jan 2020 21:03:09 GMT
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit b6f250ad58bbf27ef4f552830fa2d13b633dcf5f
Author: Dave Brondsema <dave@brondsema.net>
AuthorDate: Mon Jan 27 15:44:02 2020 -0500

    [#7878] ldap unicode fixes
---
 Allura/allura/lib/plugin.py                         | 20 ++++++++++----------
 Allura/allura/tests/unit/test_ldap_auth_provider.py |  4 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 904ddca..5c09d53 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -657,7 +657,7 @@ class LdapAuthenticationProvider(AuthenticationProvider):
                 return result
 
         # full registration into LDAP
-        uid = str(M.AuthGlobals.get_next_uid())
+        uid = str(M.AuthGlobals.get_next_uid()).encode('utf-8')
         try:
             con = ldap_conn()
             uname = user_doc['username'].encode('utf-8')
@@ -665,14 +665,14 @@ class LdapAuthenticationProvider(AuthenticationProvider):
             ldif_u = modlist.addModlist(dict(
                 uid=uname,
                 userPassword=self._encode_password(user_doc['password']),
-                objectClass=['account', 'posixAccount'],
+                objectClass=[b'account', b'posixAccount'],
                 cn=display_name,
                 uidNumber=uid,
-                gidNumber='10001',
-                homeDirectory='/home/' + uname,
-                loginShell='/bin/bash',
+                gidNumber=b'10001',
+                homeDirectory=b'/home/' + uname,
+                loginShell=b'/bin/bash',
                 gecos=uname,
-                description='SCM user account'))
+                description=b'SCM user account'))
             try:
                 con.add_s(ldap_user_dn(user_doc['username']), ldif_u)
             except ldap.ALREADY_EXISTS:
@@ -720,9 +720,9 @@ class LdapAuthenticationProvider(AuthenticationProvider):
         rounds = asint(config.get(cfg_prefix + 'rounds', 6000))
         salt = self._get_salt(salt_len) if salt is None else salt
         encrypted = crypt.crypt(
-            password.encode('utf-8'),
+            six.ensure_str(password),
             '$%s$rounds=%s$%s' % (algorithm, rounds, salt))
-        return '{CRYPT}%s' % encrypted
+        return b'{CRYPT}%s' % encrypted.encode('utf-8')
 
     def by_username(self, username):
         from allura import model as M
@@ -739,7 +739,7 @@ class LdapAuthenticationProvider(AuthenticationProvider):
             con = ldap_conn(ldap_ident, ldap_pass)
             new_password = self._encode_password(new_password)
             con.modify_s(
-                dn, [(ldap.MOD_REPLACE, 'userPassword', new_password)])
+                dn, [(ldap.MOD_REPLACE, b'userPassword', new_password)])
             con.unbind_s()
             user.last_password_updated = datetime.utcnow()
             session(user).flush(user)
@@ -1734,7 +1734,7 @@ class LdapUserPreferencesProvider(UserPreferencesProvider):
             con = ldap_conn()
             ldap_attr = self.fields[pref_name]
             con.modify_s(ldap_user_dn(user.username),
-                         [(ldap.MOD_REPLACE, ldap_attr, pref_value.encode('utf-8'))])
+                         [(ldap.MOD_REPLACE, ldap_attr.encode('utf-8'), pref_value.encode('utf-8'))])
             con.unbind_s()
         else:
             return LocalUserPreferencesProvider().set_pref(user, pref_name, pref_value)
diff --git a/Allura/allura/tests/unit/test_ldap_auth_provider.py b/Allura/allura/tests/unit/test_ldap_auth_provider.py
index f635dd5..69865dc 100644
--- a/Allura/allura/tests/unit/test_ldap_auth_provider.py
+++ b/Allura/allura/tests/unit/test_ldap_auth_provider.py
@@ -64,9 +64,9 @@ class TestLdapAuthenticationProvider(object):
         self.provider.set_password(user, 'old-pass', 'new-pass')
         ldap.initialize.assert_called_once_with('ldaps://localhost/')
         connection = ldap.initialize.return_value
-        connection.bind_s.called_once_with(dn, 'old-pass')
+        connection.bind_s.called_once_with(dn, b'old-pass')
         connection.modify_s.assert_called_once_with(
-            dn, [(ldap.MOD_REPLACE, 'userPassword', 'new-pass-hash')])
+            dn, [(ldap.MOD_REPLACE, b'userPassword', b'new-pass-hash')])
         assert_equal(connection.unbind_s.call_count, 1)
 
     @patch('allura.lib.plugin.ldap')


Mime
View raw message