diff options
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/ConnectionTest.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/ConnectionTest.php b/apps/user_ldap/tests/ConnectionTest.php index 65d148b709e..87ebc8d9ad3 100644 --- a/apps/user_ldap/tests/ConnectionTest.php +++ b/apps/user_ldap/tests/ConnectionTest.php @@ -186,4 +186,54 @@ class ConnectionTest extends \Test\TestCase { $this->fail('Failed asserting that exception of type "OC\ServerNotAvailableException" is not thrown.'); } } + + public function testStartTlsNegotiationFailure() { + // background: If Start TLS negotiation fails, + // a ServerNotAvailableException should be thrown. + + $host = 'ldap://nixda.ldap'; + $port = 389; + $config = [ + 'ldapConfigurationActive' => true, + 'ldapHost' => $host, + 'ldapPort' => $port, + 'ldapTLS' => true, + 'ldapBackupHost' => '', + 'ldapAgentName' => 'user', + 'ldapAgentPassword' => 'password' + ]; + + $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('connect') + ->will($this->returnValue('ldapResource')); + + $this->ldap->expects($this->any()) + ->method('setOption') + ->will($this->returnValue(true)); + + $this->ldap->expects($this->any()) + ->method('bind') + ->will($this->returnValue(true)); + + $this->ldap->expects($this->any()) + ->method('errno') + ->will($this->returnValue(0)); + + $this->ldap->expects($this->any()) + ->method('startTls') + ->will($this->returnValue(false)); + + $this->expectException(\OC\ServerNotAvailableException::class); + $this->expectExceptionMessage('Start TLS failed, when connecting to LDAP host ' . $host . '.'); + + $this->connection->init(); + } + } |