[Zope3-checkins] SVN: ldapauth/trunk/tests/test_ Completed the tests on pluggableauth integration (authenticate). Added a

Évrard Nicolas nicoe at altern.org
Thu Jul 22 20:50:51 EDT 2004


Log message for revision 26690:
  Completed the tests on pluggableauth integration (authenticate). Added a
  skeleton for test_manager.
  


Changed:
  A   ldapauth/trunk/tests/test_manager.py
  U   ldapauth/trunk/tests/test_pluggableauthandcache.py


-=-
Added: ldapauth/trunk/tests/test_manager.py
===================================================================
--- ldapauth/trunk/tests/test_manager.py	2004-07-22 20:59:26 UTC (rev 26689)
+++ ldapauth/trunk/tests/test_manager.py	2004-07-23 00:50:51 UTC (rev 26690)
@@ -0,0 +1,66 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Test for the management of LDAP users
+
+$Id$
+"""
+import sys
+from unittest import TestCase, TestSuite, makeSuite, main
+
+import FakeLDAP
+if sys.modules.has_key('_ldap'):
+    del sys.modules['_ldap']
+sys.modules['ldap'] = FakeLDAP
+
+import ldap
+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')
+        try:
+            l.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',
+                    (('uid', 'tata_l'),
+                     ('userPassword', 'tata_p')))
+            l.add_s('uid=titi_l,ou=people,dc=fake',
+                    (('uid', 'titi_l'),
+                     ('userPassword', 'titi_p')))
+        except ldap.ALREADY_EXISTS:
+            pass
+
+        self.source = LDAPPrincipalSource(
+                'localhost', 389, 'ou=people,dc=fake',
+                'uid', 'cn=Manager,dc=fake', 'root')
+
+    def test_addPrincipal(self):
+        pass
+
+    def test_editPrincipal(self):
+        pass
+
+    def test_deletePrincipal(self):
+        pass
+
+def test_suite():
+    return TestSuite((
+        makeSuite(LDAPManagerAdapterTest),))
+
+if __name__ == '__main__' :
+    main(defaultTest='test_suite')


Property changes on: ldapauth/trunk/tests/test_manager.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: ldapauth/trunk/tests/test_pluggableauthandcache.py
===================================================================
--- ldapauth/trunk/tests/test_pluggableauthandcache.py	2004-07-22 20:59:26 UTC (rev 26689)
+++ ldapauth/trunk/tests/test_pluggableauthandcache.py	2004-07-23 00:50:51 UTC (rev 26690)
@@ -18,6 +18,7 @@
 
 import sys
 from unittest import TestCase, TestSuite, makeSuite, main
+import base64
 
 # FakeLDAP taken from LDAPUserFolder of Jens Vagelpohl
 import FakeLDAP
@@ -41,12 +42,32 @@
 from zope.app.cache.annotationcacheable import AnnotationCacheable
 from zope.app.cache.caching import getCacheForObject
 
+from zope.app.security.interfaces import IPrincipal, ILoginPassword
+from zope.app.security.basicauthadapter import BasicAuthAdapter
+
+from zope.app.pluggableauth.interfaces import IPrincipalSource
 from zope.app.pluggableauth import PluggableAuthenticationService, \
         SimplePrincipal
+from zope.app.pluggableauth.browser.authentication import \
+    PrincipalAuthenticationView
 
+from zope.publisher.interfaces.http import IHTTPCredentials
+from zope.publisher.browser import TestRequest as Request
+
 from ldapauth.source import LDAPPrincipalSource
 from zope.exceptions import NotFoundError
 
+def stubRequest(login=None, password=None):
+    if login is None:
+        return Request()
+    if password is None:
+        password = ''
+    dict = {
+        'HTTP_AUTHORIZATION':
+            "Basic %s" % base64.encodestring('%s:%s' % (login, password))
+            }
+    return Request(**dict)
+
 # Cachin test idea shamefully taken from
 # zope.app.sqlscript.tests.test_sqlscript
 class CacheStub:
@@ -77,6 +98,9 @@
 
         sm = placefulsetup.PlacefulSetup.setUp(self, site=True)
 
+        ztapi.provideAdapter(IHTTPCredentials, ILoginPassword, BasicAuthAdapter)
+        ztapi.browserView(IPrincipalSource, "login",
+                          PrincipalAuthenticationView)
         ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                 AttributeAnnotations)
         ztapi.provideAdapter(IAnnotatable, ICacheable, AnnotationCacheable)
@@ -125,7 +149,16 @@
         self.assertEquals(len(list(self._auth.getPrincipals('ta'))), 1)
 
     def test_authServiceAuthenticate(self):
-        pass
+        auth = self._auth
+        source = self._source
+        source_toto = source.getPrincipal('\t\ttoto_l')
+        auth_toto = auth.getPrincipal(source_toto.id)
+        self.assertEquals(
+                auth.authenticate(stubRequest('toto_l', 'toto_p')).login,
+                'toto_l')
+        self.failIf(auth.authenticate(stubRequest()))
+        self.failIf(auth.authenticate(stubRequest('toto_l')))
+        self.failIf(auth.authenticate(stubRequest('toto_l', 'tata')))
 
     def test_cache(self):
         auth = self._auth



More information about the Zope3-Checkins mailing list