summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-10-06 09:23:24 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-10-06 09:23:24 +0200
commit1525ef43f9a08f1da463228f9e3c7827f4a3b3c2 (patch)
treedd282fecf60f883dc427d34368d4b20fc27c3faa /apps
parent3ff60cc2e3a47efd9796b5376694743c168efeb3 (diff)
parentfc273ac88c76b8dfa0385fb0f9380132b6cb2ffa (diff)
downloadnextcloud-server-1525ef43f9a08f1da463228f9e3c7827f4a3b3c2.tar.gz
nextcloud-server-1525ef43f9a08f1da463228f9e3c7827f4a3b3c2.zip
Merge pull request #18484 from owncloud/fix-17964
Remove whitespace from base-DNs
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/lib/configuration.php53
-rw-r--r--apps/user_ldap/tests/configuration.php106
2 files changed, 152 insertions, 7 deletions
diff --git a/apps/user_ldap/lib/configuration.php b/apps/user_ldap/lib/configuration.php
index 1cbe45a82c2..6e62f5730b9 100644
--- a/apps/user_ldap/lib/configuration.php
+++ b/apps/user_ldap/lib/configuration.php
@@ -146,9 +146,12 @@ class Configuration {
$setMethod = 'setValue';
switch($key) {
+ case 'ldapAgentPassword':
+ $setMethod = 'setRawValue';
+ break;
case 'homeFolderNamingRule':
- if(!empty($val) && strpos($val, 'attr:') === false) {
- $val = 'attr:'.$val;
+ if(!empty(trim($val)) && strpos($val, 'attr:') === false) {
+ $val = 'attr:'.trim($val);
}
break;
case 'ldapBase':
@@ -272,8 +275,11 @@ class Configuration {
}
/**
- * @param string $varName
- * @param array|string $value
+ * Sets multi-line values as arrays
+ *
+ * @param string $varName name of config-key
+ * @param array|string $value to set
+ * @param boolean $trim Trim value? (default: false)
*/
protected function setMultiLine($varName, $value) {
if(empty($value)) {
@@ -285,7 +291,25 @@ class Configuration {
}
}
- $this->setValue($varName, $value);
+ if(!is_array($value)) {
+ $finalValue = trim($value);
+ } else {
+ $finalValue = [];
+ foreach($value as $key => $val) {
+ if(is_string($val)) {
+ $val = trim($val);
+ if(!empty($val)) {
+ //accidental line breaks are not wanted and can cause
+ // odd behaviour. Thus, away with them.
+ $finalValue[] = $val;
+ }
+ } else {
+ $finalValue[] = $val;
+ }
+ }
+ }
+
+ $this->setRawValue($varName, $finalValue);
}
/**
@@ -328,10 +352,25 @@ class Configuration {
}
/**
- * @param string $varName
- * @param mixed $value
+ * Sets a scalar value.
+ *
+ * @param string $varName name of config key
+ * @param mixed $value to set
*/
protected function setValue($varName, $value) {
+ if(is_string($value)) {
+ $value = trim($value);
+ }
+ $this->config[$varName] = $value;
+ }
+
+ /**
+ * Sets a scalar value without trimming.
+ *
+ * @param string $varName name of config key
+ * @param mixed $value to set
+ */
+ protected function setRawValue($varName, $value) {
$this->config[$varName] = $value;
}
diff --git a/apps/user_ldap/tests/configuration.php b/apps/user_ldap/tests/configuration.php
new file mode 100644
index 00000000000..efe4d7eec83
--- /dev/null
+++ b/apps/user_ldap/tests/configuration.php
@@ -0,0 +1,106 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\user_ldap\tests;
+
+class Test_Configuration extends \Test\TestCase {
+
+ public function configurationDataProvider() {
+ $inputWithDN = array(
+ 'cn=someUsers,dc=example,dc=org',
+ ' ',
+ ' cn=moreUsers,dc=example,dc=org '
+ );
+ $expectWithDN = array(
+ 'cn=someUsers,dc=example,dc=org',
+ 'cn=moreUsers,dc=example,dc=org'
+ );
+
+ $inputNames = array(
+ ' uid ',
+ 'cn ',
+ ' ',
+ '',
+ ' whats my name',
+ ' '
+ );
+ $expectedNames = array('uid', 'cn', 'whats my name');
+
+ $inputString = ' alea iacta est ';
+ $expectedString = 'alea iacta est';
+
+ $inputHomeFolder = array(
+ ' homeDirectory ',
+ ' attr:homeDirectory ',
+ ' '
+ );
+
+ $expectedHomeFolder = array(
+ 'attr:homeDirectory', 'attr:homeDirectory', ''
+ );
+
+ $password = ' such a passw0rd ';
+
+ return array(
+ 'set general base' => array('ldapBase', $inputWithDN, $expectWithDN),
+ 'set user base' => array('ldapBaseUsers', $inputWithDN, $expectWithDN),
+ 'set group base' => array('ldapBaseGroups', $inputWithDN, $expectWithDN),
+
+ 'set search attributes users' => array('ldapAttributesForUserSearch', $inputNames, $expectedNames),
+ 'set search attributes groups' => array('ldapAttributesForGroupSearch', $inputNames, $expectedNames),
+
+ 'set user filter objectclasses' => array('ldapUserFilterObjectclass', $inputNames, $expectedNames),
+ 'set user filter groups' => array('ldapUserFilterGroups', $inputNames, $expectedNames),
+ 'set group filter objectclasses' => array('ldapGroupFilterObjectclass', $inputNames, $expectedNames),
+ 'set group filter groups' => array('ldapGroupFilterGroups', $inputNames, $expectedNames),
+ 'set login filter attributes' => array('ldapLoginFilterAttributes', $inputNames, $expectedNames),
+
+ 'set agent password' => array('ldapAgentPassword', $password, $password),
+
+ 'set home folder, variant 1' => array('homeFolderNamingRule', $inputHomeFolder[0], $expectedHomeFolder[0]),
+ 'set home folder, variant 2' => array('homeFolderNamingRule', $inputHomeFolder[1], $expectedHomeFolder[1]),
+ 'set home folder, empty' => array('homeFolderNamingRule', $inputHomeFolder[2], $expectedHomeFolder[2]),
+
+ // default behaviour, one case is enough, special needs must be tested
+ // individually
+ 'set string value' => array('ldapHost', $inputString, $expectedString),
+ );
+ }
+
+ /**
+ * @dataProvider configurationDataProvider
+ */
+ public function testSetValue($key, $input, $expected) {
+ $configuration = new \OCA\user_ldap\lib\Configuration('t01', false);
+
+ $settingsInput = array(
+ 'ldapBaseUsers' => array(
+ 'cn=someUsers,dc=example,dc=org',
+ ' ',
+ ' cn=moreUsers,dc=example,dc=org '
+ )
+ );
+
+ $configuration->setConfiguration([$key => $input]);
+ $this->assertSame($configuration->$key, $expected);
+ }
+
+}