]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make sure mountOptions keep their data type
authorVincent Petry <pvince81@owncloud.com>
Thu, 26 Mar 2015 18:24:37 +0000 (19:24 +0100)
committerVincent Petry <pvince81@owncloud.com>
Thu, 26 Mar 2015 18:24:37 +0000 (19:24 +0100)
str_replace for $user substitution was converting the data type of
mountOptions to string. This fix prevents this to happen by making sure
only strings are processed by substitution.

Also added a int conversion when reading the watcher policy

apps/files_external/lib/config.php
apps/files_external/tests/mountconfig.php
lib/private/files/storage/common.php

index 85a93a779ae088f57b84b8f7cdf45cec9a0e9636..d72955fc472beeceb876111e938fffc9559969b6 100644 (file)
@@ -146,8 +146,6 @@ class OC_Mount_Config {
        public static function getAbsoluteMountPoints($user) {
                $mountPoints = array();
 
-               $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
-
                $backends = self::getBackends();
 
                // Load system mount points
@@ -277,12 +275,21 @@ class OC_Mount_Config {
        /**
         * fill in the correct values for $user
         *
-        * @param string $user
-        * @param string $input
+        * @param string $user user value
+        * @param string|array $input
         * @return string
         */
        private static function setUserVars($user, $input) {
-               return str_replace('$user', $user, $input);
+               if (is_array($input)) {
+                       foreach ($input as &$value) {
+                               if (is_string($value)) {
+                                       $value = str_replace('$user', $user, $value);
+                               }
+                       }
+               } else {
+                       $input = str_replace('$user', $user, $input);
+               }
+               return $input;
        }
 
 
index 645f0c64e11b3020de6858e9cd4b5a6faeed70e6..4bc8429db231051f0905a65410ac4f8354463a12 100644 (file)
@@ -120,7 +120,6 @@ class Test_Mount_Config extends \Test\TestCase {
        private $dataDir;
        private $userHome;
        private $oldAllowedBackends;
-       private $allBackends;
 
        const TEST_USER1 = 'user1';
        const TEST_USER2 = 'user2';
@@ -210,6 +209,11 @@ class Test_Mount_Config extends \Test\TestCase {
                return json_decode(file_get_contents($configFile), true);
        }
 
+       private function writeGlobalConfig($config) {
+               $configFile = $this->dataDir . '/mount.json';
+               file_put_contents($configFile, json_encode($config));
+       }
+
        /**
         * Reads the user config, for checking
         */
@@ -627,6 +631,51 @@ class Test_Mount_Config extends \Test\TestCase {
                $this->assertEquals($mountConfig, $savedMountConfig);
        }
 
+       public function testVariableSubstitution() {
+               $legacyBackendOptions = [
+                       'user' => 'someuser',
+                       'password' => 'somepassword',
+                       'replacethis' => '$user',
+               ];
+               $legacyBackendOptions = \OC_Mount_Config::encryptPasswords($legacyBackendOptions);
+
+               $legacyConfig = [
+                       'class' => '\OC\Files\Storage\SMB',
+                       'options' => $legacyBackendOptions,
+                       'mountOptions' => ['preview' => false, 'int' => 1],
+               ];
+               // different mount options
+               $legacyConfig2 = [
+                       'class' => '\OC\Files\Storage\SMB',
+                       'options' => $legacyBackendOptions,
+                       'mountOptions' => ['preview' => true, 'string' => 'abc'],
+               ];
+
+               $json = [
+                       'user' => [
+                               self::TEST_USER1 => [
+                                       '/$user/files/somemount' => $legacyConfig,
+                                       '/$user/files/anothermount' => $legacyConfig2,
+                               ],
+                       ],
+               ];
+
+               $this->writeGlobalConfig($json);
+
+               // re-read config, password was read correctly
+               $config = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
+
+               $config1 = $config['/' . self::TEST_USER1 . '/files/somemount'];
+               $config2 = $config['/' . self::TEST_USER1 . '/files/anothermount'];
+
+               $this->assertSame(self::TEST_USER1, $config1['options']['replacethis']);
+               $this->assertSame(self::TEST_USER1, $config1['options']['replacethis']);
+               $this->assertSame(1, $config1['mountOptions']['int']);
+               $this->assertSame(true, $config2['mountOptions']['preview']);
+               $this->assertSame('abc', $config2['mountOptions']['string']);
+       }
+
+
        public function mountDataProvider() {
                return array(
                        // Tests for visible mount points
index 11cf3405fd92a494a86cd7aa8582de0f87716de9..10abf87f1518ca0ad4ac7476e77f1d1b25228391 100644 (file)
@@ -333,7 +333,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
                if (!isset($this->watcher)) {
                        $this->watcher = new Watcher($storage);
                        $globalPolicy = \OC::$server->getConfig()->getSystemValue('filesystem_check_changes', Watcher::CHECK_ONCE);
-                       $this->watcher->setPolicy($this->getMountOption('filesystem_check_changes', $globalPolicy));
+                       $this->watcher->setPolicy((int)$this->getMountOption('filesystem_check_changes', $globalPolicy));
                }
                return $this->watcher;
        }