[test] fix ldap test when executed from certain hosts stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 11 Oct 2010 10:47:22 +0200
branchstable
changeset 6434 d99b742a9c49
parent 6433 95c40961df21
child 6435 71b2a3fe7ba1
child 6436 275e9f402ccc
[test] fix ldap test when executed from certain hosts
server/test/data/sources_ldap1
server/test/data/sources_ldap2
server/test/data/sourcesldap
server/test/unittest_ldapuser.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/test/data/sources_ldap1	Mon Oct 11 10:47:22 2010 +0200
@@ -0,0 +1,35 @@
+[system]
+adapter=native
+# database driver (postgres or sqlite)
+db-driver=sqlite
+# database host
+db-host=
+# database name
+db-name=tmpdb
+# database user
+db-user=admin
+# database password
+db-password=gingkow
+# database encoding
+db-encoding=utf8
+
+[admin]
+login = admin
+password = gingkow
+
+[ldapuser]
+adapter=ldapuser
+# ldap host
+host=ldap1
+# base DN to lookup for usres
+user-base-dn=ou=People,dc=logilab,dc=fr
+# user search scope
+user-scope=ONELEVEL
+# classes of user
+user-classes=top,posixAccount
+# attribute used as login on authentication
+user-login-attr=uid
+# name of a group in which ldap users will be by default
+user-default-group=users
+# map from ldap user attributes to cubicweb attributes
+user-attrs-map=gecos:email,uid:login
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/test/data/sources_ldap2	Mon Oct 11 10:47:22 2010 +0200
@@ -0,0 +1,35 @@
+[system]
+adapter=native
+# database driver (postgres or sqlite)
+db-driver=sqlite
+# database host
+db-host=
+# database name
+db-name=tmpdb
+# database user
+db-user=admin
+# database password
+db-password=gingkow
+# database encoding
+db-encoding=utf8
+
+[admin]
+login = admin
+password = gingkow
+
+[ldapuser]
+adapter=ldapuser
+# ldap host
+host=ldap1
+# base DN to lookup for usres
+user-base-dn=ou=People,dc=logilab,dc=net
+# user search scope
+user-scope=ONELEVEL
+# classes of user
+user-classes=top,OpenLDAPperson
+# attribute used as login on authentication
+user-login-attr=uid
+# name of a group in which ldap users will be by default
+user-default-group=users
+# map from ldap user attributes to cubicweb attributes
+user-attrs-map=mail:email,uid:login
--- a/server/test/data/sourcesldap	Mon Oct 11 10:14:22 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-[system]
-adapter=native
-# database driver (postgres or sqlite)
-db-driver=sqlite
-# database host
-db-host=
-# database name
-db-name=tmpdb
-# database user
-db-user=admin
-# database password
-db-password=gingkow
-# database encoding
-db-encoding=utf8
-
-[admin]
-login = admin
-password = gingkow
-
-[ldapuser]
-adapter=ldapuser
-# ldap host
-host=ldap1
-# base DN to lookup for usres
-user-base-dn=ou=People,dc=logilab,dc=fr
-# user search scope
-user-scope=ONELEVEL
-# classes of user
-user-classes=top,posixAccount
-# attribute used as login on authentication
-user-login-attr=uid
-# name of a group in which ldap users will be by default
-user-default-group=users
-# map from ldap user attributes to cubicweb attributes
-user-attrs-map=gecos:email,uid:login
--- a/server/test/unittest_ldapuser.py	Mon Oct 11 10:14:22 2010 +0200
+++ b/server/test/unittest_ldapuser.py	Mon Oct 11 10:47:22 2010 +0200
@@ -15,9 +15,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""cubicweb.server.sources.ldapusers unit and functional tests
-
-"""
+"""cubicweb.server.sources.ldapusers unit and functional tests"""
 
 import socket
 
@@ -30,10 +28,14 @@
 
 if '17.1' in socket.gethostbyname('ldap1'):
     SYT = 'syt'
+    SYT_EMAIL = 'Sylvain Thenault'
     ADIM = 'adim'
+    SOURCESFILE = 'data/sources_ldap1'
 else:
     SYT = 'sthenault'
+    SYT_EMAIL = 'sylvain.thenault@logilab.fr'
     ADIM = 'adimascio'
+    SOURCESFILE = 'data/sources_ldap2'
 
 
 def nopwd_authenticate(self, session, login, password):
@@ -59,7 +61,7 @@
 
 class LDAPUserSourceTC(CubicWebTC):
     config = TestServerConfiguration('data')
-    config.sources_file = lambda : 'data/sourcesldap'
+    config.sources_file = lambda: SOURCESFILE
 
     def patch_authenticate(self):
         self._orig_authenticate = LDAPUserSource.authenticate
@@ -101,7 +103,7 @@
         self.assertEqual(e.in_group[0].name, 'users')
         self.assertEqual(e.owned_by[0].login, SYT)
         self.assertEqual(e.created_by, ())
-        self.assertEqual(e.primary_email[0].address, 'Sylvain Thenault')
+        self.assertEqual(e.primary_email[0].address, SYT_EMAIL)
         # email content should be indexed on the user
         rset = self.sexecute('CWUser X WHERE X has_text "thenault"')
         self.assertEqual(rset.rows, [[e.eid]])
@@ -398,6 +400,8 @@
         self.pool = repo._get_pool()
         session = mock_object(pool=self.pool)
         self.o = RQL2LDAPFilter(ldapsource, session)
+        self.ldapclasses = ''.join('(objectClass=%s)' % ldapcls
+                                   for ldapcls in ldapsource.user_classes)
 
     def tearDown(self):
         repo._free_pool(self.pool)
@@ -406,13 +410,13 @@
     def test_base(self):
         rqlst = self._prepare('CWUser X WHERE X login "toto"').children[0]
         self.assertEqual(self.o.generate(rqlst, 'X')[1],
-                          '(&(objectClass=top)(objectClass=posixAccount)(uid=toto))')
+                          '(&%s(uid=toto))' % self.ldapclasses)
 
     def test_kwargs(self):
         rqlst = self._prepare('CWUser X WHERE X login %(x)s').children[0]
         self.o._args = {'x': "toto"}
         self.assertEqual(self.o.generate(rqlst, 'X')[1],
-                          '(&(objectClass=top)(objectClass=posixAccount)(uid=toto))')
+                          '(&%s(uid=toto))' % self.ldapclasses)
 
     def test_get_attr(self):
         rqlst = self._prepare('Any X WHERE E firstname X, E eid 12').children[0]