From dc0749ecce232a5a68d83fbde965ee4ee8e36d00 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 11 Oct 2015 14:44:16 -0400 Subject: Improve LDAP auth --- tests/units/Auth/LdapTest.php | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'tests/units') diff --git a/tests/units/Auth/LdapTest.php b/tests/units/Auth/LdapTest.php index a52b8cf8..6edd42fc 100644 --- a/tests/units/Auth/LdapTest.php +++ b/tests/units/Auth/LdapTest.php @@ -116,7 +116,16 @@ class LdapTest extends \Base public function testBindAnonymous() { - $ldap = new Ldap($this->container); + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getLdapBindType')) + ->getMock(); + + $ldap + ->expects($this->any()) + ->method('getLdapBindType') + ->will($this->returnValue('anonymous')); self::$functions ->expects($this->once()) @@ -128,7 +137,7 @@ class LdapTest extends \Base ) ->will($this->returnValue(true)); - $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'anonymous')); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password')); } public function testBindUser() @@ -136,14 +145,19 @@ class LdapTest extends \Base $ldap = $this ->getMockBuilder('\Auth\Ldap') ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapUserPattern')) + ->setMethods(array('getLdapUsername', 'getLdapBindType')) ->getMock(); $ldap ->expects($this->once()) - ->method('getLdapUserPattern') + ->method('getLdapUsername') ->will($this->returnValue('uid=my_user')); + $ldap + ->expects($this->any()) + ->method('getLdapBindType') + ->will($this->returnValue('user')); + self::$functions ->expects($this->once()) ->method('ldap_bind') @@ -154,7 +168,7 @@ class LdapTest extends \Base ) ->will($this->returnValue(true)); - $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'user')); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password')); } public function testBindProxy() @@ -162,7 +176,7 @@ class LdapTest extends \Base $ldap = $this ->getMockBuilder('\Auth\Ldap') ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapUsername', 'getLdapPassword')) + ->setMethods(array('getLdapUsername', 'getLdapPassword', 'getLdapBindType')) ->getMock(); $ldap @@ -175,6 +189,11 @@ class LdapTest extends \Base ->method('getLdapPassword') ->will($this->returnValue('something')); + $ldap + ->expects($this->any()) + ->method('getLdapBindType') + ->will($this->returnValue('proxy')); + self::$functions ->expects($this->once()) ->method('ldap_bind') @@ -185,7 +204,7 @@ class LdapTest extends \Base ) ->will($this->returnValue(true)); - $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'proxy')); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password')); } public function testSearchSuccess() -- cgit v1.2.3