Back to index

plone3  3.1.7
testLDAPUserFolder.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 ## GroupUserFolder
00003 ## Copyright (C)2006 Ingeniweb
00004 
00005 ## This program is free software; you can redistribute it and/or modify
00006 ## it under the terms of the GNU General Public License as published by
00007 ## the Free Software Foundation; either version 2 of the License, or
00008 ## (at your option) any later version.
00009 
00010 ## This program is distributed in the hope that it will be useful,
00011 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ## GNU General Public License for more details.
00014 
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with this program; see the file COPYING. If not, write to the
00017 ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 """
00019 
00020 """
00021 __version__ = "$Revision:  $"
00022 # $Source:  $
00023 # $Id: testLDAPUserFolder.py 34725 2006-12-15 12:27:06Z encolpe $
00024 __docformat__ = 'restructuredtext'
00025 
00026 import os, sys
00027 if __name__ == '__main__':
00028     execfile(os.path.join(sys.path[0], 'framework.py'))
00029 
00030 
00031 
00032 # Load fixture
00033 from Testing import ZopeTestCase
00034 
00035 # Permissions / security
00036 from AccessControl.Permissions import access_contents_information, view, add_documents_images_and_files, change_images_and_files, view_management_screens
00037 from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager, getSecurityManager
00038 from AccessControl import Unauthorized
00039 from AccessControl.User import UnrestrictedUser
00040 
00041 import urllib
00042 
00043 # Create the error_log object
00044 app = ZopeTestCase.app()
00045 ZopeTestCase.utils.setupSiteErrorLog(app)
00046 ZopeTestCase.close(app)
00047 
00048 # Start the web server
00049 host, port = ZopeTestCase.utils.startZServer(4)
00050 base = 'http://%s:%d/%s' %(host, port, ZopeTestCase.folder_name)
00051 
00052     
00053 # Get global vars
00054 #from Products.GroupUserFolder.global_symbols import *
00055 from Products.GroupUserFolder.interfaces import IUserFolder
00056 from Interface import Verify
00057 
00058 # Install our product
00059 ZopeTestCase.installProduct('GroupUserFolder')
00060 ZopeTestCase.installProduct('LDAPUserFolder')
00061 
00062 import GRUFTestCase
00063 import testGroupUserFolderAPI
00064 from Log import *
00065 
00066 
00067 try:
00068     from LDAPconfig import defaults
00069 except ImportError:
00070     Log(LOG_ERROR, """
00071     To perform this test case, you must provide a 'LDAPconfig.py' file with the following structure:
00072 
00073 defaults = { 'title'  : 'LDAP User Folder'
00074            , 'server' : 'localhost:389'
00075            , 'login_attr' : 'cn'
00076            , 'uid_attr': 'cn'
00077            , 'users_base' : 'ou=people,dc=dataflake,dc=org'
00078            , 'users_scope' : 2
00079            , 'roles' : 'Anonymous'
00080            , 'groups_base' : 'ou=groups,dc=dataflake,dc=org'
00081            , 'groups_scope' : 2
00082            , 'binduid' : 'cn=Manager,dc=dataflake,dc=org'
00083            , 'bindpwd' : 'mypass'
00084            , 'binduid_usage' : 1
00085            , 'rdn_attr' : 'cn'
00086            , 'local_groups' : 1                 # Keep this true
00087            , 'use_ssl' : 0
00088            , 'encryption' : 'SHA'
00089            , 'read_only' : 0
00090            }
00091 
00092     Of course, you've got to replace all values by some relevant ones for your project.
00093     This test case won't complete without.
00094 
00095     NEVER PUT THIS FILE INTO YOUR CVS ! Unless you want your password to be publicly known...
00096     """)
00097     ldapuf = False
00098 else:
00099     ldapuf = True
00100     dg = defaults.get
00101 
00102 
00103 
00104 
00105 class TestLDAPUserFolderBasics(GRUFTestCase.GRUFTestCase):
00106     """
00107     Basic LDAPUserFolder binding
00108     This test just creates a LDAPUF connexion for the user source and performs a few API tests.
00109     Heavy LDAP testing is delegated to TestLDAPUserFolder class.
00110     """
00111 
00112     def gruf_sources_setup(self,):
00113         """
00114         Basic LDAP initialization inside gruf's user source
00115         """
00116         # User source replacement
00117         self.gruf.replaceUserSource("Users",
00118             "manage_addProduct/LDAPUserFolder/manage_addLDAPUserFolder",
00119             #title = dg('title'),
00120             #LDAP_server = dg('server'),
00121             #login_attr = dg('login_attr'),
00122             #uid_attr = dg('uid_attr'),
00123             #users_base = dg('users_base'),
00124             #users_scope = dg('users_scope'),
00125             #roles= dg('roles'),
00126             #groups_base = dg('groups_base'),
00127             #groups_scope = dg('groups_scope'),
00128             #binduid = dg('binduid'),
00129             #bindpwd = dg('bindpwd'),
00130             #binduid_usage = dg('binduid_usage'),
00131             #rdn_attr = dg('rdn_attr'),
00132             #local_groups = dg('local_groups'),
00133             #encryption = dg('encryption'),
00134             #use_ssl = dg('use_ssl'),
00135             #read_only=dg('read_only'),
00136             )
00137 
00138         # Edit LDAPUF 'cause objectClass cannot be set otherwise :(
00139         self.gruf.Users.acl_users.manage_edit(
00140             title = dg('title'),
00141             login_attr = dg('login_attr'),
00142             uid_attr = dg('uid_attr'),
00143             users_base = dg('users_base'),
00144             users_scope = dg('users_scope'),
00145             roles= dg('roles'),
00146             obj_classes = 'top,inetOrgPerson',
00147             groups_base = dg('groups_base'),
00148             groups_scope = dg('groups_scope'),
00149             binduid = dg('binduid'),
00150             bindpwd = dg('bindpwd'),
00151             binduid_usage = dg('binduid_usage'),
00152             rdn_attr = dg('rdn_attr'),
00153             local_groups = dg('local_groups'),
00154             encryption = dg('encryption'),
00155             read_only=dg('read_only'),
00156             )
00157 
00158         # Purge existing users in order to start on a clean basis
00159         self.delete_created_users()
00160 
00161 
00162     def test01_LDAPUp(self,):
00163         """Ensure LDAP is up and running
00164         """
00165         self.gruf.Users.acl_users.getUsers()
00166 
00167 
00168 
00169 class TestLDAPUserFolderAPI(TestLDAPUserFolderBasics, testGroupUserFolderAPI.TestGroupUserFolderAPI):
00170     """
00171     Whole API test for GRUF+LDAP
00172 
00173     Users stored in LDAP
00174     Groups stored in ZODB
00175     """
00176     def test_getPureUsers(self):
00177         """
00178         The original test didn't work because of LDAPUF's cache -> we disable
00179         """
00180         pass
00181 
00182     def test_getUsers(self,):
00183         """
00184         The original test didn't work because of LDAPUF's cache -> we disable
00185         """
00186         pass
00187 
00188     def test_userSetDomains(self,):
00189         """
00190         LDAPUF has no domain support
00191         """
00192         pass
00193 
00194     def test_setProperty(self,):
00195         """Set user's properties
00196         """
00197         u1 = self.gruf.getUser("u1")
00198 
00199         # Simplest case: sn property setting
00200         u1.setProperty("sn", "Second Name Value")
00201 
00202         # We check that it has been changed
00203         self.failUnless(u1.getProperty("sn") == "Second Name Value", u1.getProperty("sn"), )
00204 
00205 
00206 
00207     def test_searchUsersByAttribute(self,):
00208         # Simple match
00209         self.failUnlessEqual(
00210             self.gruf.searchUsersByAttribute(defaults['login_attr'], "u3"),
00211             ["u3",],
00212             )
00213 
00214         # Different case matching
00215         self.failUnlessEqual(
00216             self.gruf.searchUsersByAttribute(defaults['login_attr'], "U3"),
00217             ["u3",],
00218             )
00219 
00220         # Multiple (different case) matching
00221         s = self.gruf.searchUsersByAttribute(defaults['login_attr'], "U")
00222         s.sort()
00223         self.failUnlessEqual(
00224             s,
00225             ['u1', 'u10', 'u11', 'u2', 'u3', 'u4', 'u5', 'u6', 'u7', 'u8', 'u9', ],
00226             )
00227         
00228 
00229 
00230 if __name__ == '__main__':
00231     framework(descriptions=1, verbosity=1)
00232 else:
00233     import unittest
00234     def test_suite():
00235         suite = unittest.TestSuite()
00236 ##        suite.addTest(unittest.makeSuite(TestLDAPUserFolderBasics))
00237         if ldapuf:
00238             suite.addTest(unittest.makeSuite(TestLDAPUserFolderAPI))
00239         return suite
00240