]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added tests to check mount point list for a target user
authorVincent Petry <pvince81@owncloud.com>
Wed, 19 Mar 2014 13:23:36 +0000 (14:23 +0100)
committerVincent Petry <pvince81@owncloud.com>
Wed, 19 Mar 2014 14:21:54 +0000 (15:21 +0100)
apps/files_external/lib/config.php
apps/files_external/tests/mountconfig.php

index 28761b4862e035a7ca7809ffc39d53ceea0269ad..6de7c91358c4c0adcc779443c5965f3538874229 100755 (executable)
@@ -167,12 +167,25 @@ class OC_Mount_Config {
        }
 
        /**
-        * Init mount points hook
+        * Hook that mounts the given user's visible mount points
         * @param array $data
         */
        public static function initMountPointsHook($data) {
-               $user = $data['user'];
-               $root = $data['user_dir'];
+               $mountPoints = self::getAbsoluteMountPoints($data['user']);
+               foreach ($mountPoints as $mountPoints => $options) {
+                       \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+               }
+       }
+
+       /**
+        * Returns the mount points for the given user.
+        * The mount point is relative to the data directory.
+        *
+        * @param string $user user
+        * @return array of mount point string as key, mountpoint config as value
+        */
+       public static function getAbsoluteMountPoints($user) {
+               $mountPoints = array(); 
 
                $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
                $mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json");
@@ -187,7 +200,7 @@ class OC_Mount_Config {
                if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
                        foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
                                $options['options'] = self::decryptPasswords($options['options']);
-                               \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+                               $mountPoints[$mountPoint] = $options;
                        }
                }
                if (isset($mountConfig[self::MOUNT_TYPE_GROUP])) {
@@ -199,7 +212,7 @@ class OC_Mount_Config {
                                                        $option = self::setUserVars($user, $option);
                                                }
                                                $options['options'] = self::decryptPasswords($options['options']);
-                                               \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+                                               $mountPoints[$mountPoint] = $options;
                                        }
                                }
                        }
@@ -213,7 +226,7 @@ class OC_Mount_Config {
                                                        $option = self::setUserVars($user, $option);
                                                }
                                                $options['options'] = self::decryptPasswords($options['options']);
-                                               \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+                                               $mountPoints[$mountPoint] = $options;
                                        }
                                }
                        }
@@ -224,9 +237,11 @@ class OC_Mount_Config {
                if (isset($mountConfig[self::MOUNT_TYPE_USER][$user])) {
                        foreach ($mountConfig[self::MOUNT_TYPE_USER][$user] as $mountPoint => $options) {
                                $options['options'] = self::decryptPasswords($options['options']);
-                               \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+                               $mountPoints[$mountPoint] = $options;
                        }
                }
+
+               return $mountPoints;
        }
 
        /**
index 8c255769fc1d72e2af9599232621b179cad9e797..cfe04f66ce3b2480e3a44383b2289808b9283ed8 100644 (file)
@@ -345,4 +345,114 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase {
                $savedMountConfig = $config['ext']['configuration'];
                $this->assertEquals($mountConfig, $savedMountConfig);
        }
+
+       public function mountDataProvider() {
+               return array(
+                       // Tests for visible mount points
+                       // system mount point for all users
+                       array(
+                               false,
+                               OC_Mount_Config::MOUNT_TYPE_USER,
+                               'all',
+                               'test',
+                               true,
+                       ),
+                       // system mount point for a specific user
+                       array(
+                               false,
+                               OC_Mount_Config::MOUNT_TYPE_USER,
+                               'test',
+                               'test',
+                               true,
+                       ),
+                       // system mount point for a specific group
+                       array(
+                               false,
+                               OC_Mount_Config::MOUNT_TYPE_GROUP,
+                               'testgroup1',
+                               'test',
+                               true,
+                       ),
+                       // user mount point
+                       array(
+                               true,
+                               OC_Mount_Config::MOUNT_TYPE_USER,
+                               'test',
+                               'test',
+                               true,
+                       ),
+
+                       // Tests for non-visible mount points
+                       // system mount point for another user
+                       array(
+                               false,
+                               OC_Mount_Config::MOUNT_TYPE_USER,
+                               'anotheruser',
+                               'test',
+                               false,
+                       ),
+                       // system mount point for a specific group
+                       array(
+                               false,
+                               OC_Mount_Config::MOUNT_TYPE_GROUP,
+                               'anothergroup',
+                               'test',
+                               false,
+                       ),
+                       // user mount point
+                       array(
+                               true,
+                               OC_Mount_Config::MOUNT_TYPE_USER,
+                               'test',
+                               'anotheruser',
+                               false,
+                       ),
+               );
+       }
+
+       /**
+        * Test mount points used at mount time, making sure
+        * the configuration is prepared properly.
+        *
+        * @dataProvider mountDataProvider
+        * @param bool $isPersonal true for personal mount point, false for system mount point
+        * @param string $mountType mount type
+        * @param string $applicable target user/group or "all"
+        * @param string $testUser user for which to retrieve the mount points
+        * @param bool $expectVisible whether to expect the mount point to be visible for $testUser
+        */
+       public function testMount($isPersonal, $mountType, $applicable, $testUser, $expectVisible) {
+               $mountConfig = array(
+                       'host' => 'someost',
+                       'user' => 'someuser',
+                       'password' => 'somepassword',
+                       'root' => 'someroot'
+               );
+
+               // add mount point as "test" user 
+               $this->assertTrue(
+                       OC_Mount_Config::addMountPoint(
+                               '/ext',
+                               '\OC\Files\Storage\SMB',
+                               $mountConfig,
+                               $mountType,
+                               $applicable,
+                               $isPersonal
+                       )
+               );
+
+               // check mount points in the perspective of user $testUser
+               \OC_User::setUserId($testUser);
+
+               $mountPoints = OC_Mount_Config::getAbsoluteMountPoints($testUser);
+               if ($expectVisible) {
+                       $this->assertEquals(1, count($mountPoints));
+                       $this->assertTrue(isset($mountPoints['/test/files/ext']));
+                       $this->assertEquals('\OC\Files\Storage\SMB', $mountPoints['/test/files/ext']['class']);
+                       $this->assertEquals($mountConfig, $mountPoints['/test/files/ext']['options']);
+               }
+               else {
+                       $this->assertEquals(0, count($mountPoints));
+               }
+       }
 }