32 from os.path import join |
32 from os.path import join |
33 |
33 |
34 from six import string_types |
34 from six import string_types |
35 from six.moves import range |
35 from six.moves import range |
36 |
36 |
37 from cubicweb import AuthenticationError |
37 from cubicweb import AuthenticationError, ValidationError |
38 from cubicweb.devtools.testlib import CubicWebTC |
38 from cubicweb.devtools.testlib import CubicWebTC |
39 from cubicweb.devtools.httptest import get_available_port |
39 from cubicweb.devtools.httptest import get_available_port |
40 |
40 |
41 |
41 |
42 CONFIG_LDAPFEED = u''' |
42 CONFIG_LDAPFEED = u''' |
305 cu = cnx.system_sql("SELECT cw_upassword FROM cw_cwuser WHERE cw_login='syt';") |
305 cu = cnx.system_sql("SELECT cw_upassword FROM cw_cwuser WHERE cw_login='syt';") |
306 pwd = cu.fetchall()[0][0] |
306 pwd = cu.fetchall()[0][0] |
307 self.assertIsNotNone(pwd) |
307 self.assertIsNotNone(pwd) |
308 self.assertTrue(str(pwd)) |
308 self.assertTrue(str(pwd)) |
309 |
309 |
|
310 def test_bad_config(self): |
|
311 with self.admin_access.cnx() as cnx: |
|
312 |
|
313 with self.assertRaises(ValidationError) as cm: |
|
314 cnx.create_entity( |
|
315 'CWSource', name=u'erroneous', type=u'ldapfeed', parser=u'ldapfeed', |
|
316 url=u'ldap.com', config=CONFIG_LDAPFEED) |
|
317 self.assertIn('badly formatted url', |
|
318 str(cm.exception)) |
|
319 cnx.rollback() |
|
320 |
|
321 with self.assertRaises(ValidationError) as cm: |
|
322 cnx.create_entity( |
|
323 'CWSource', name=u'erroneous', type=u'ldapfeed', parser=u'ldapfeed', |
|
324 url=u'http://ldap.com', config=CONFIG_LDAPFEED) |
|
325 self.assertIn('unsupported protocol', |
|
326 str(cm.exception)) |
|
327 cnx.rollback() |
|
328 |
|
329 with self.assertRaises(ValidationError) as cm: |
|
330 cnx.create_entity( |
|
331 'CWSource', name=u'erroneous', type=u'ldapfeed', parser=u'ldapfeed', |
|
332 url=u'ldap://host1\nldap://host2', config=CONFIG_LDAPFEED) |
|
333 self.assertIn('can only have one url', |
|
334 str(cm.exception)) |
|
335 cnx.rollback() |
|
336 |
310 |
337 |
311 class LDAPGeneratePwdTC(LDAPFeedTestBase): |
338 class LDAPGeneratePwdTC(LDAPFeedTestBase): |
312 """ |
339 """ |
313 A testcase for password generation on CWUser when none is imported |
340 A testcase for password generation on CWUser when none is imported |
314 """ |
341 """ |