Added support for multiple placeholders for LDAP_USER_FILTER
This commit is contained in:
parent
e3e08d0e34
commit
24c224ddc2
|
|
@ -3,6 +3,7 @@ Version 1.0.27 (unreleased)
|
|||
|
||||
Improvements:
|
||||
|
||||
* Added support for multiple placeholders for LDAP_USER_FILTER
|
||||
* Added local file link provider
|
||||
* Show configuration in settings page
|
||||
* Added "?" to display list of keyboard shortcuts
|
||||
|
|
|
|||
|
|
@ -211,14 +211,15 @@ class User
|
|||
*
|
||||
* @access public
|
||||
* @param string $username
|
||||
* @param string $filter
|
||||
* @return string
|
||||
*/
|
||||
public function getLdapUserPattern($username)
|
||||
public function getLdapUserPattern($username, $filter = LDAP_USER_FILTER)
|
||||
{
|
||||
if (! LDAP_USER_FILTER) {
|
||||
if (! $filter) {
|
||||
throw new LogicException('LDAP user filter empty, check the parameter LDAP_USER_FILTER');
|
||||
}
|
||||
|
||||
return sprintf(LDAP_USER_FILTER, $username);
|
||||
return str_replace('%s', $username, $filter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -321,8 +321,6 @@ class LdapUserTest extends Base
|
|||
|
||||
public function testGetUserNotFound()
|
||||
{
|
||||
$entries = new Entries(array());
|
||||
|
||||
$this->client
|
||||
->expects($this->any())
|
||||
->method('getConnection')
|
||||
|
|
@ -376,4 +374,30 @@ class LdapUserTest extends Base
|
|||
$user = new User($this->query);
|
||||
$user->getBasDn();
|
||||
}
|
||||
|
||||
public function testGetLdapUserPatternNotConfigured()
|
||||
{
|
||||
$this->setExpectedException('\LogicException');
|
||||
|
||||
$user = new User($this->query);
|
||||
$user->getLdapUserPattern('test');
|
||||
}
|
||||
|
||||
public function testGetLdapUserWithMultiplePlaceholders()
|
||||
{
|
||||
$filter = '(|(&(objectClass=user)(mail=%s))(&(objectClass=user)(sAMAccountName=%s)))';
|
||||
$expected = '(|(&(objectClass=user)(mail=test))(&(objectClass=user)(sAMAccountName=test)))';
|
||||
|
||||
$user = new User($this->query);
|
||||
$this->assertEquals($expected, $user->getLdapUserPattern('test', $filter));
|
||||
}
|
||||
|
||||
public function testGetLdapUserWithOnePlaceholder()
|
||||
{
|
||||
$filter = '(sAMAccountName=%s)';
|
||||
$expected = '(sAMAccountName=test)';
|
||||
|
||||
$user = new User($this->query);
|
||||
$this->assertEquals($expected, $user->getLdapUserPattern('test', $filter));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue