summaryrefslogtreecommitdiff
path: root/tests/units/Auth/LdapTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Auth/LdapTest.php')
-rw-r--r--tests/units/Auth/LdapTest.php122
1 files changed, 122 insertions, 0 deletions
diff --git a/tests/units/Auth/LdapTest.php b/tests/units/Auth/LdapTest.php
new file mode 100644
index 00000000..e861be98
--- /dev/null
+++ b/tests/units/Auth/LdapTest.php
@@ -0,0 +1,122 @@
+<?php
+
+namespace Auth;
+
+require_once __DIR__.'/../Base.php';
+
+function ldap_connect($hostname, $port)
+{
+ return LdapTest::$functions->ldap_connect($hostname, $port);
+}
+
+function ldap_set_option()
+{
+}
+
+function ldap_bind($ldap, $ldap_username, $ldap_password)
+{
+ return LdapTest::$functions->ldap_bind($ldap, $ldap_username, $ldap_password);
+}
+
+class LdapTest extends \Base
+{
+ public static $functions;
+
+ public function setUp()
+ {
+ parent::setup();
+
+ self::$functions = $this
+ ->getMockBuilder('stdClass')
+ ->setMethods(array(
+ 'ldap_connect',
+ 'ldap_set_option',
+ 'ldap_bind',
+ ))
+ ->getMock();
+ }
+
+ public function tearDown()
+ {
+ parent::tearDown();
+ self::$functions = null;
+ }
+
+ public function testConnectSuccess()
+ {
+ self::$functions
+ ->expects($this->once())
+ ->method('ldap_connect')
+ ->with(
+ $this->equalTo('my_ldap_server'),
+ $this->equalTo(389)
+ )
+ ->willReturn(true);
+
+ $ldap = new Ldap($this->container);
+ $this->assertNotFalse($ldap->connect());
+ }
+
+ public function testConnectFailure()
+ {
+ self::$functions
+ ->expects($this->once())
+ ->method('ldap_connect')
+ ->with(
+ $this->equalTo('my_ldap_server'),
+ $this->equalTo(389)
+ )
+ ->willReturn(false);
+
+ $ldap = new Ldap($this->container);
+ $this->assertFalse($ldap->connect());
+ }
+
+ public function testBindAnonymous()
+ {
+ self::$functions
+ ->expects($this->once())
+ ->method('ldap_bind')
+ ->with(
+ $this->equalTo('my_ldap_connection'),
+ $this->equalTo(null),
+ $this->equalTo(null)
+ )
+ ->willReturn(true);
+
+ $ldap = new Ldap($this->container);
+ $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'anonymous'));
+ }
+
+ public function testBindUser()
+ {
+ self::$functions
+ ->expects($this->once())
+ ->method('ldap_bind')
+ ->with(
+ $this->equalTo('my_ldap_connection'),
+ $this->equalTo('uid=my_user'),
+ $this->equalTo('my_password')
+ )
+ ->willReturn(true);
+
+ $ldap = new Ldap($this->container);
+ $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'user', 'uid=%s', 'something'));
+ }
+
+ public function testBindProxy()
+ {
+ self::$functions
+ ->expects($this->once())
+ ->method('ldap_bind')
+ ->with(
+ $this->equalTo('my_ldap_connection'),
+ $this->equalTo('someone'),
+ $this->equalTo('something')
+ )
+ ->willReturn(true);
+
+ $ldap = new Ldap($this->container);
+ $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'proxy', 'someone', 'something'));
+ }
+}