#6752: ci ldap tests
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 23 Apr 2014 09:31:58 +0000 (11:31 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 23 Apr 2014 10:03:57 +0000 (12:03 +0200)
* adds ldapsearch + delete howto for resetting users/groups
* allows to add an initial admin user when using LDAP backend

https://forge.tine20.org/mantisbt/view.php?id=6752

Change-Id: If12ebe84cf225e5f311e4bd165d7007e65c41640
Reviewed-on: http://gerrit.tine20.com/customers/549
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/ldap/openldap.txt
tine20/Addressbook/Setup/Initialize.php
tine20/Tinebase/User.php

index afe2780..b0d3b03 100644 (file)
@@ -30,12 +30,10 @@ this does not work :/
 $ ldapadd -D cn=admin,dc=nodomain -wpassword -f nodomain.ldif
 
 reset all users/groups
---------
+-----------
 
-$ ldapdelete -D cn=admin,dc=nodomain -wpassword "cn=Administrators,ou=groups,dc=nodomain"
-$ ldapdelete -D cn=admin,dc=nodomain -wpassword "cn=Users,ou=groups,dc=nodomain"
-$ ldapdelete -D cn=admin,dc=nodomain -wpassword "uid=unittest,ou=users,dc=nodomain"
-$ ldapdelete -D cn=admin,dc=nodomain -wpassword "ou=users,dc=nodomain"
-$ ldapdelete -D cn=admin,dc=nodomain -wpassword "ou=groups,dc=nodomain"
+ldapsearch -D "cn=admin,dc=nodomain" -wpassword -b "ou=users,dc=nodomain" | grep "dn: " | grep -v "dn: ou" > users.list
+sed -i -e "s/dn: //" users.list
+ldapdelete -D "cn=admin,dc=nodomain" -wpassword -f users.list 
 
-// more users/groups to delete?
\ No newline at end of file
+# replace ou=users,dc=nodomain with ou=groups,dc=nodomain and repeat
\ No newline at end of file
index 5f16d0a..072a598 100644 (file)
@@ -34,14 +34,19 @@ class Addressbook_Setup_Initialize extends Setup_Initialize
     {
         $initialAdminUserOptions = $this->_parseInitialAdminUserOptions($_options);
         
-        if(Tinebase_User::getInstance() instanceof Tinebase_User_Interface_SyncAble) {
+        if (Tinebase_User::getInstance() instanceof Tinebase_User_Interface_SyncAble) {
             Tinebase_User::syncUsers(array('syncContactData' => TRUE));
-        } else {
+        }
+        
+        try {
+            $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']);
+        } catch (Tinebase_Exception_NotFound $tenf) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' '
+                . ' Could not find initial admin account in user backend. Creating new one ...');
             Tinebase_User::createInitialAccounts($initialAdminUserOptions);
+            $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']);
         }
-
-        // set current user
-        $initialUser = Tinebase_User::getInstance()->getUserByProperty('accountLoginName', $initialAdminUserOptions['adminLoginName']);
+        
         Tinebase_Core::set(Tinebase_Core::USER, $initialUser);
         
         parent::_initialize($_application, $_options);
index 9e93429..7253a8c 100644 (file)
@@ -640,8 +640,8 @@ class Tinebase_User
         $adminEmailAddress  = ((isset($_options['adminEmailAddress']) || array_key_exists('adminEmailAddress', $_options))) ? $_options['adminEmailAddress'] : NULL;
 
         // get admin & user groups
-        $userBackend   = Tinebase_User::factory(Tinebase_User::SQL);
-        $groupsBackend = Tinebase_Group::factory(Tinebase_Group::SQL);
+        $userBackend   = Tinebase_User::getInstance();
+        $groupsBackend = Tinebase_Group::getInstance();
         
         $adminGroup = $groupsBackend->getDefaultAdminGroup();
         $userGroup  = $groupsBackend->getDefaultGroup();
@@ -683,6 +683,5 @@ class Tinebase_User
         // add the admin account to all groups
         Tinebase_Group::getInstance()->addGroupMember($adminGroup, $user);
         Tinebase_Group::getInstance()->addGroupMember($userGroup, $user);
-        
     }
 }