Ejemplo n.º 1
0
 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();
 }