Added support for multiple placeholders for LDAP_USER_FILTER
This commit is contained in:
@@ -3,6 +3,7 @@ Version 1.0.27 (unreleased)
|
|||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
* Added support for multiple placeholders for LDAP_USER_FILTER
|
||||||
* Added local file link provider
|
* Added local file link provider
|
||||||
* Show configuration in settings page
|
* Show configuration in settings page
|
||||||
* Added "?" to display list of keyboard shortcuts
|
* Added "?" to display list of keyboard shortcuts
|
||||||
|
|||||||
@@ -211,14 +211,15 @@ class User
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $username
|
* @param string $username
|
||||||
|
* @param string $filter
|
||||||
* @return string
|
* @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');
|
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()
|
public function testGetUserNotFound()
|
||||||
{
|
{
|
||||||
$entries = new Entries(array());
|
|
||||||
|
|
||||||
$this->client
|
$this->client
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('getConnection')
|
->method('getConnection')
|
||||||
@@ -376,4 +374,30 @@ class LdapUserTest extends Base
|
|||||||
$user = new User($this->query);
|
$user = new User($this->query);
|
||||||
$user->getBasDn();
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user