fix ldapsource w/ restriction on unsupported relation (return no results in that case)
authorsylvain.thenault@logilab.fr
Thu, 26 Feb 2009 13:31:13 +0100
changeset 975 0928daea04e9
parent 974 3ec0a7bd87ae
child 976 84884807b77b
fix ldapsource w/ restriction on unsupported relation (return no results in that case)
server/sources/ldapuser.py
server/test/unittest_ldapuser.py
--- a/server/sources/ldapuser.py	Thu Feb 26 13:12:39 2009 +0100
+++ b/server/sources/ldapuser.py	Thu Feb 26 13:31:13 2009 +0100
@@ -632,7 +632,10 @@
             filter = '(%s%s)' % (self._ldap_attrs[relation.r_type],
                                  rhs.accept(self))
         except KeyError:
-            assert relation.r_type == 'password' # 2.38 migration
+            # unsupported attribute
+            self.source.warning('%s source can\'t handle relation %s, no '
+                                'results will be returned from this source',
+                                self.source.uri, relation)
             raise UnknownEid # trick to return no result
         return filter
 
--- a/server/test/unittest_ldapuser.py	Thu Feb 26 13:12:39 2009 +0100
+++ b/server/test/unittest_ldapuser.py	Thu Feb 26 13:31:13 2009 +0100
@@ -33,8 +33,8 @@
 repo, cnx = init_test_database('sqlite', config=config)
 
 class LDAPUserSourceTC(RepositoryBasedTC):
-    repo = repo
-        
+    repo, cnx = repo, cnx
+    
     def patch_authenticate(self):
         self._orig_authenticate = LDAPUserSource.authenticate
         LDAPUserSource.authenticate = nopwd_authenticate
@@ -242,7 +242,10 @@
                                               ['users', 'cochon'],
                                               ['users', 'syt']])
         
-
+    def test_cd_restriction(self):
+        rset = self.execute('EUser X WHERE X creation_date > "2009-02-01"')
+        self.assertEquals(len(rset), 2) # admin/anon but no ldap user since it doesn't support creation_date
+        
     def test_union(self):
         afeids = self.execute('State X')
         ueids = self.execute('EUser X')