diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-02-14 19:43:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-14 19:43:25 +0100 |
commit | 5b9429777afaf07c979ed54260f2bb479e5e6322 (patch) | |
tree | ae193c14bfd1cdc7c09002be89abece5a51d64d5 | |
parent | 331f705a7a323d515fc8fea47467f7e478981328 (diff) | |
parent | ccd3addb56e3c9017c45a84047212158770c5b00 (diff) | |
download | nextcloud-server-5b9429777afaf07c979ed54260f2bb479e5e6322.tar.gz nextcloud-server-5b9429777afaf07c979ed54260f2bb479e5e6322.zip |
Merge pull request #14208 from nextcloud/backport/14200/stable13
[stable13] ensure attribute names are lower cased
-rw-r--r-- | apps/user_ldap/lib/User/Manager.php | 26 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/ManagerTest.php | 8 |
2 files changed, 19 insertions, 15 deletions
diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php index 63520072578..5d7fb33b7ca 100644 --- a/apps/user_ldap/lib/User/Manager.php +++ b/apps/user_ldap/lib/User/Manager.php @@ -169,19 +169,14 @@ class Manager { * @return string[] */ public function getAttributes($minimal = false) { - $attributes = array_merge(Access::UUID_ATTRIBUTES, ['dn', 'uid', 'samaccountname', 'memberof']); - $possible = array( + $baseAttributes = array_merge(Access::UUID_ATTRIBUTES, ['dn', 'uid', 'samaccountname', 'memberof']); + $attributes = [ $this->access->getConnection()->ldapExpertUUIDUserAttr, $this->access->getConnection()->ldapQuotaAttribute, $this->access->getConnection()->ldapEmailAttribute, $this->access->getConnection()->ldapUserDisplayName, $this->access->getConnection()->ldapUserDisplayName2, - ); - foreach($possible as $attr) { - if(!is_null($attr)) { - $attributes[] = $attr; - } - } + ]; $homeRule = $this->access->getConnection()->homeFolderNamingRule; if(strpos($homeRule, 'attr:') === 0) { @@ -197,11 +192,16 @@ class Manager { ); } - // remove possible empty attributes - $attributes = array_values( - array_filter($attributes, function ($attributeName) { - return !empty($attributeName); - }) + $attributes = array_reduce($attributes, + function($list, $attribute) { + $attribute = strtolower(trim((string)$attribute)); + if(!empty($attribute) && !in_array($attribute, $list)) { + $list[] = $attribute; + } + + return $list; + }, + $baseAttributes // hard-coded, lower-case, non-empty attributes ); return $attributes; diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php index 104a70ff700..a04d8f2af29 100644 --- a/apps/user_ldap/tests/User/ManagerTest.php +++ b/apps/user_ldap/tests/User/ManagerTest.php @@ -257,18 +257,22 @@ class ManagerTest extends \Test\TestCase { $connection = $access->getConnection(); $connection->setConfiguration([ - 'ldapEmailAttribute' => 'mail', + 'ldapEmailAttribute' => 'MAIL', 'ldapUserAvatarRule' => 'default', 'ldapQuotaAttribute' => '', + 'ldapUserDisplayName2' => 'Mail', ]); $attributes = $manager->getAttributes($minimal); $this->assertTrue(in_array('dn', $attributes)); - $this->assertTrue(in_array($access->getConnection()->ldapEmailAttribute, $attributes)); + $this->assertTrue(in_array(strtolower($access->getConnection()->ldapEmailAttribute), $attributes)); + $this->assertTrue(!in_array($access->getConnection()->ldapEmailAttribute, $attributes)); #cases check $this->assertFalse(in_array('', $attributes)); $this->assertSame(!$minimal, in_array('jpegphoto', $attributes)); $this->assertSame(!$minimal, in_array('thumbnailphoto', $attributes)); + $valueCounts = array_count_values($attributes); + $this->assertSame(1, $valueCounts['mail']); } } |