[ldapfeed] Fix crash when user's password has to be generated
Binary isn't hashable hence can't be added to a set. Test added.
--- a/cubicweb/server/test/unittest_ldapsource.py Wed Oct 19 15:56:35 2016 +0200
+++ b/cubicweb/server/test/unittest_ldapsource.py Wed Oct 19 15:57:52 2016 +0200
@@ -311,6 +311,24 @@
self.assertTrue(str(pwd))
+class LDAPGeneratePwdTC(LDAPFeedTestBase):
+ """
+ A testcase for password generation on CWUser when none is imported
+ """
+
+ def setup_database(self):
+ with self.admin_access.repo_cnx() as cnx:
+ lfsource = cnx.repo.sources_by_uri['ldap']
+ del lfsource.user_attrs['userPassword']
+ super(LDAPGeneratePwdTC, self).setup_database()
+
+ def test_no_password(self):
+ with self.admin_access.repo_cnx() as cnx:
+ cu = cnx.system_sql("SELECT cw_upassword FROM cw_cwuser WHERE cw_login='syt';")
+ pwd = cu.fetchall()[0][0]
+ self.assertTrue(pwd)
+
+
class LDAPFeedUserDeletionTC(LDAPFeedTestBase):
"""
A testcase for situations where users are deleted from or
--- a/cubicweb/sobjects/ldapparser.py Wed Oct 19 15:56:35 2016 +0200
+++ b/cubicweb/sobjects/ldapparser.py Wed Oct 19 15:57:52 2016 +0200
@@ -25,7 +25,7 @@
from logilab.common.decorators import cached, cachedproperty
from logilab.common.shellutils import generate_password
-from cubicweb import Binary, ConfigurationError
+from cubicweb import ConfigurationError
from cubicweb.server.utils import crypt_password
from cubicweb.server.sources import datafeed
from cubicweb.dataimport import stores, importer
@@ -149,7 +149,7 @@
# generate a dumb password if not fetched from ldap (see
# userPassword)
pwd = crypt_password(generate_password())
- attrs['upassword'] = set([Binary(pwd)])
+ attrs['upassword'] = set([pwd])
extuser = importer.ExtEntity('CWUser', userdict['dn'].encode('ascii'), attrs)
extuser.values['owned_by'] = set([extuser.extid])
for extemail in self._process_email(extuser, userdict):