# HG changeset patch # User Sylvain Thénault # Date 1476885472 -7200 # Node ID 36443c44b9a5357c9f03fd65a1a91cdcd3f716eb # Parent e32e328e7d1ff214a5c2cb2b59075eeac51064c8 [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. diff -r e32e328e7d1f -r 36443c44b9a5 cubicweb/server/test/unittest_ldapsource.py --- 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 diff -r e32e328e7d1f -r 36443c44b9a5 cubicweb/sobjects/ldapparser.py --- 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):