diff options
Diffstat (limited to 'apps/files_external')
-rwxr-xr-x | apps/files_external/lib/config.php | 29 | ||||
-rw-r--r-- | apps/files_external/tests/mountconfig.php | 110 |
2 files changed, 132 insertions, 7 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 28761b4862e..6de7c91358c 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -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; } /** diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php index 8c255769fc1..cfe04f66ce3 100644 --- a/apps/files_external/tests/mountconfig.php +++ b/apps/files_external/tests/mountconfig.php @@ -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)); + } + } } |