[Zope3-checkins] SVN: ldapauth/trunk/ Added "modlist.addModList" to FakeLDAP.

Évrard Nicolas nicoe at altern.org
Thu Jul 22 21:16:47 EDT 2004


Log message for revision 26691:
  Added "modlist.addModList" to FakeLDAP.
  
  Wrote tests for addPrincipal and deletePrincipal (not complete).
  
  Fixed the use of principal instead of login in deletePrincipal.
  


Changed:
  U   ldapauth/trunk/manager.py
  U   ldapauth/trunk/tests/FakeLDAP.py
  U   ldapauth/trunk/tests/test_manager.py


-=-
Modified: ldapauth/trunk/manager.py
===================================================================
--- ldapauth/trunk/manager.py	2004-07-23 00:50:51 UTC (rev 26690)
+++ ldapauth/trunk/manager.py	2004-07-23 01:16:46 UTC (rev 26691)
@@ -17,6 +17,7 @@
 """
 
 import ldap
+from ldap.modlist import addModlist
 
 from zope.interface import implements
 from zope.security.proxy import trustedRemoveSecurityProxy
@@ -43,7 +44,7 @@
         source = trustedRemoveSecurityProxy(self.context)
         l = self.__connect(source)
         dn = self._createdn(ldap_principal, source)
-        modification = ldap.modlist.addModlist(
+        modification = addModlist(
                 {source.login_attribute : ldap_principal.login,
                  'userPassword' : ldap_principal.password})
         l.add_s(dn, modification)
@@ -54,12 +55,12 @@
     def editPrincipal(self, ldap_principal):
         source = trustedRemoveSecurityProxy(self.context)
 
-    def deletePrincipal(self, login):
+    def deletePrincipal(self, ldap_principal):
         source = trustedRemoveSecurityProxy(self.context)
         l = self.__connect(source)
         dn = self._createdn(ldap_principal, source)
         l.delete_s(dn)
-        del source[login]
+        del source[ldap_principal.login]
 
     def _createdn(self, principal, ldapauth):
         return '%s=%s,%s' % (ldapauth.login_attribute,

Modified: ldapauth/trunk/tests/FakeLDAP.py
===================================================================
--- ldapauth/trunk/tests/FakeLDAP.py	2004-07-23 00:50:51 UTC (rev 26690)
+++ ldapauth/trunk/tests/FakeLDAP.py	2004-07-23 01:16:46 UTC (rev 26691)
@@ -10,6 +10,7 @@
 __version__='$Revision: 1.7 $'[11:-2]
 
 import ldap, sha, base64, copy
+from ldap.modlist import addModlist
 
 # Module-level stuff
 __version__ = '2.fake'
@@ -70,6 +71,10 @@
     paswd_enc = base64.encodestring(sha_dig).strip()
     return '{SHA}%s' % paswd_enc
 
+class modlist:
+
+    addModlist = addModlist
+
 class FakeLDAPConnection:
     
     def __init__(self):

Modified: ldapauth/trunk/tests/test_manager.py
===================================================================
--- ldapauth/trunk/tests/test_manager.py	2004-07-23 00:50:51 UTC (rev 26690)
+++ ldapauth/trunk/tests/test_manager.py	2004-07-23 01:16:46 UTC (rev 26691)
@@ -24,39 +24,55 @@
 sys.modules['ldap'] = FakeLDAP
 
 import ldap
+
+from zope.exceptions import NotFoundError
+from zope.app.pluggableauth import SimplePrincipal
+
 from ldapauth.source import LDAPPrincipalSource
 from ldapauth.manager import LDAPManagerAdapter
 
 class LDAPManagerAdapterTest(TestCase):
 
     def setUp(self):
-        l = ldap.initialize('ldap://localhost:389')
-        l.simple_bind_s('cn=Manager,dc=fake', 'root')
+        self.conn = ldap.initialize('ldap://localhost:389')
+        self.conn.simple_bind_s('cn=Manager,dc=fake', 'root')
         try:
-            l.add_s('uid=toto_l,ou=people,dc=fake',
+            self.conn.add_s('uid=toto_l,ou=people,dc=fake',
                     (('uid', 'toto_l'),
                      ('userPassword', 'toto_p')))
-            l.add_s('uid=tata_l,ou=people,dc=fake',
+            self.conn.add_s('uid=tata_l,ou=people,dc=fake',
                     (('uid', 'tata_l'),
                      ('userPassword', 'tata_p')))
-            l.add_s('uid=titi_l,ou=people,dc=fake',
+            self.conn.add_s('uid=titi_l,ou=people,dc=fake',
                     (('uid', 'titi_l'),
                      ('userPassword', 'titi_p')))
         except ldap.ALREADY_EXISTS:
             pass
 
+        self.toto = SimplePrincipal('toto_l', 'toto_p')
+        self.tutu = SimplePrincipal('tutu_l', 'tutu_p')
+
         self.source = LDAPPrincipalSource(
                 'localhost', 389, 'ou=people,dc=fake',
                 'uid', 'cn=Manager,dc=fake', 'root')
 
     def test_addPrincipal(self):
-        pass
+        manager = LDAPManagerAdapter(self.source)
+        manager.addPrincipal(self.tutu)
+        tutu = self.source.getPrincipal('\t\ttutu_l')
+        self.assertEquals('tutu_l', tutu.login)
+        rs = self.conn.search_s('ou=people,dc=fake', query='(uid=tutu_l)')
+        self.assertEquals(len(rs), 1)
 
     def test_editPrincipal(self):
         pass
 
     def test_deletePrincipal(self):
-        pass
+        manager = LDAPManagerAdapter(self.source)
+        manager.deletePrincipal(self.toto)
+        self.assertRaises(NotFoundError, self.source.getPrincipal, '\t\ttoto_l')
+        rs = self.conn.search_s('ou=people,dc=fake', query='(uid=toto_l)')
+        self.assertEquals(len(rs), 0)
 
 def test_suite():
     return TestSuite((



More information about the Zope3-Checkins mailing list