summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--app/Core/Ldap/User.php7
-rw-r--r--tests/units/Core/Ldap/LdapUserTest.php28
3 files changed, 31 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index ed777dfe..6980fd1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/app/Core/Ldap/User.php b/app/Core/Ldap/User.php
index d36d6f34..52283434 100644
--- a/app/Core/Ldap/User.php
+++ b/app/Core/Ldap/User.php
@@ -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);
}
}
diff --git a/tests/units/Core/Ldap/LdapUserTest.php b/tests/units/Core/Ldap/LdapUserTest.php
index 2b3db1e5..b4b63053 100644
--- a/tests/units/Core/Ldap/LdapUserTest.php
+++ b/tests/units/Core/Ldap/LdapUserTest.php
@@ -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));
+ }
}