public function testUseBackupServer() { $mainHost = 'ldap://nixda.ldap'; $backupHost = 'ldap://fallback.ldap'; $config = ['ldapConfigurationActive' => true, 'ldapHost' => $mainHost, 'ldapPort' => 389, 'ldapBackupHost' => $backupHost, 'ldapBackupPort' => 389, 'ldapAgentName' => 'uid=agent', 'ldapAgentPassword' => 'SuchASecret']; $this->connection->setIgnoreValidation(true); $this->connection->setConfiguration($config); $this->ldap->expects($this->any())->method('isResource')->will($this->returnValue(true)); $this->ldap->expects($this->any())->method('setOption')->will($this->returnValue(true)); $this->ldap->expects($this->exactly(3))->method('connect')->will($this->returnValue('ldapResource')); // Not called often enough? Then, the fallback to the backup server is broken. $this->connection->expects($this->exactly(4))->method('getFromCache')->with('overrideMainServer')->will($this->onConsecutiveCalls(false, false, true, true)); $this->connection->expects($this->once())->method('writeToCache')->with('overrideMainServer', true); $isThrown = false; $this->ldap->expects($this->exactly(3))->method('bind')->will($this->returnCallback(function () use(&$isThrown) { if (!$isThrown) { $isThrown = true; throw new \OC\ServerNotAvailableException(); } return true; })); $this->connection->init(); $this->connection->resetConnectionResource(); // with the second init() we test whether caching works $this->connection->init(); }
/** * creates a unique name for internal ownCloud use. * @param string $name the display name of the object * @param boolean $isUser whether name should be created for a user (true) or a group (false) * @return string|false with with the name to use in ownCloud or false if unsuccessful */ private function createAltInternalOwnCloudName($name, $isUser) { $originalTTL = $this->connection->ldapCacheTTL; $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); if ($isUser) { $altName = $this->_createAltInternalOwnCloudNameForUsers($name); } else { $altName = $this->_createAltInternalOwnCloudNameForGroups($name); } $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); return $altName; }
/** * tests the specified connection * @param string $configID * @return int */ protected function testConfig($configID) { $lw = new \OCA\User_LDAP\LDAP(); $connection = new Connection($lw, $configID); //ensure validation is run before we attempt the bind $connection->getConfiguration(); if (!$connection->setConfiguration(array('ldap_configuration_active' => 1))) { return 1; } if ($connection->bind()) { return 0; } return 2; }
/** * sets up the LDAP configuration to be used for the test */ protected function initConnection() { $this->connection = new Connection($this->ldap, '', null); $this->connection->setConfiguration(['ldapHost' => $this->server['host'], 'ldapPort' => $this->server['port'], 'ldapBase' => $this->base, 'ldapAgentName' => $this->server['dn'], 'ldapAgentPassword' => $this->server['pwd'], 'ldapUserFilter' => 'objectclass=inetOrgPerson', 'ldapUserDisplayName' => 'cn', 'ldapGroupDisplayName' => 'cn', 'ldapLoginFilter' => '(|(uid=%uid)(samaccountname=%uid))', 'ldapCacheTTL' => 0, 'ldapConfigurationActive' => 1]); }