summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests
diff options
context:
space:
mode:
authorJarkko Lehtoranta <devel@jlranta.com>2017-07-17 19:12:43 +0300
committerJarkko Lehtoranta <devel@jlranta.com>2017-07-23 14:50:01 +0300
commit3a6511eac8d5c59613df65bd39aa2e2977aa89b6 (patch)
tree8cee65113adc4ef151a4f4bb748a7fc30f01b213 /apps/user_ldap/tests
parent6103677a910f6dbb6685019abcaba853611b86ea (diff)
downloadnextcloud-server-3a6511eac8d5c59613df65bd39aa2e2977aa89b6.tar.gz
nextcloud-server-3a6511eac8d5c59613df65bd39aa2e2977aa89b6.zip
LDAP: Add testBindWithInvalidCredentials unit test
Signed-off-by: Jarkko Lehtoranta <devel@jlranta.com>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r--apps/user_ldap/tests/ConnectionTest.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/ConnectionTest.php b/apps/user_ldap/tests/ConnectionTest.php
index ab7abf63679..65d148b709e 100644
--- a/apps/user_ldap/tests/ConnectionTest.php
+++ b/apps/user_ldap/tests/ConnectionTest.php
@@ -142,4 +142,48 @@ class ConnectionTest extends \Test\TestCase {
$this->connection->init();
}
+ public function testBindWithInvalidCredentials() {
+ // background: Bind with invalid credentials should return false
+ // and not throw a ServerNotAvailableException.
+
+ $host = 'ldap://nixda.ldap';
+ $config = [
+ 'ldapConfigurationActive' => true,
+ 'ldapHost' => $host,
+ 'ldapPort' => 389,
+ '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('setOption')
+ ->will($this->returnValue(true));
+
+ $this->ldap->expects($this->any())
+ ->method('connect')
+ ->will($this->returnValue('ldapResource'));
+
+ $this->ldap->expects($this->exactly(2))
+ ->method('bind')
+ ->will($this->returnValue(false));
+
+ // LDAP_INVALID_CREDENTIALS
+ $this->ldap->expects($this->any())
+ ->method('errno')
+ ->will($this->returnValue(0x31));
+
+ try {
+ $this->assertFalse($this->connection->bind(), 'Connection::bind() should not return true with invalid credentials.');
+ } catch (\OC\ServerNotAvailableException $e) {
+ $this->fail('Failed asserting that exception of type "OC\ServerNotAvailableException" is not thrown.');
+ }
+ }
}