Improve LDAP auth

This commit is contained in:
Frederic Guillot
2015-10-11 14:44:16 -04:00
parent cf6d4d1c0a
commit dc0749ecce
4 changed files with 86 additions and 65 deletions

View File

@@ -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()