/** * Test mount point validation */ public function testAddMountPointValidation() { $storageClass = 'Test_Mount_Config_Dummy_Storage'; $mountType = 'user'; $applicable = 'all'; $isPersonal = false; $this->assertEquals(false, OC_Mount_Config::addMountPoint('', $storageClass, array(), $mountType, $applicable, $isPersonal)); $this->assertEquals(false, OC_Mount_Config::addMountPoint('/', $storageClass, array(), $mountType, $applicable, $isPersonal)); $this->assertEquals(false, OC_Mount_Config::addMountPoint('Shared', $storageClass, array(), $mountType, $applicable, $isPersonal)); $this->assertEquals(false, OC_Mount_Config::addMountPoint('/Shared', $storageClass, array(), $mountType, $applicable, $isPersonal)); }
<?php OCP\JSON::checkAppEnabled('files_external'); OCP\JSON::callCheck(); if ($_POST['isPersonal'] == 'true') { OCP\JSON::checkLoggedIn(); $isPersonal = true; } else { OCP\JSON::checkAdminUser(); $isPersonal = false; } $mountPoint = (string) $_POST['mountPoint']; $oldMountPoint = (string) $_POST['oldMountPoint']; $class = (string) $_POST['class']; $options = (string) $_POST['classOptions']; $type = (string) $_POST['mountType']; $applicable = (string) $_POST['applicable']; if ($oldMountPoint and $oldMountPoint !== $mountPoint) { OC_Mount_Config::removeMountPoint($oldMountPoint, $type, $applicable, $isPersonal); } $status = OC_Mount_Config::addMountPoint($mountPoint, $class, $options, $type, $applicable, $isPersonal); OCP\JSON::success(array('data' => array('message' => $status)));
public function testMultiUserPersonalConfigLoading() { $mountConfig = array('host' => 'somehost', 'user' => 'someuser', 'password' => 'somepassword', 'root' => 'someroot'); // Create personal mount point $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', '\\OC\\Files\\Storage\\SMB', $mountConfig, OC_Mount_Config::MOUNT_TYPE_USER, self::TEST_USER1, true)); // Ensure other user can read mount points \OC_User::setUserId(self::TEST_USER2); $mountPointsMe = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER2); $mountPointsOther = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1); $this->assertEquals(0, count($mountPointsMe)); $this->assertEquals(1, count($mountPointsOther)); $this->assertTrue(isset($mountPointsOther['/' . self::TEST_USER1 . '/files/ext'])); $this->assertEquals('\\OC\\Files\\Storage\\SMB', $mountPointsOther['/' . self::TEST_USER1 . '/files/ext']['class']); $this->assertEquals($mountConfig, $mountPointsOther['/' . self::TEST_USER1 . '/files/ext']['options']); }
<?php OCP\JSON::checkAppEnabled('files_external'); OCP\JSON::callCheck(); if ($_POST['isPersonal'] == 'true') { OCP\JSON::checkLoggedIn(); $isPersonal = true; } else { OCP\JSON::checkAdminUser(); $isPersonal = false; } OC_Mount_Config::addMountPoint($_POST['mountPoint'], $_POST['class'], $_POST['classOptions'], $_POST['mountType'], $_POST['applicable'], $isPersonal);
/** * 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['/' . self::TEST_USER1 . '/files/ext'])); $this->assertEquals('\\OC\\Files\\Storage\\SMB', $mountPoints['/' . self::TEST_USER1 . '/files/ext']['class']); $this->assertEquals($mountConfig, $mountPoints['/' . self::TEST_USER1 . '/files/ext']['options']); } else { $this->assertEquals(0, count($mountPoints)); } }
/** * Test for persistence of priority when changing mount options */ public function testPriorityPersistence() { $class = '\\OC\\Files\\Storage\\SMB'; $priority = 123; $mountConfig = array('host' => 'somehost', 'user' => 'someuser', 'password' => 'somepassword', 'root' => 'someroot'); $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', $class, $mountConfig, OC_Mount_Config::MOUNT_TYPE_USER, self::TEST_USER1, false, $priority)); // Check for correct priority $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1); $this->assertEquals($priority, $mountPoints['/' . self::TEST_USER1 . '/files/ext']['priority']); // Simulate changed mount options (without priority set) $this->assertTrue(OC_Mount_Config::addMountPoint('/ext', $class, $mountConfig, OC_Mount_Config::MOUNT_TYPE_USER, self::TEST_USER1, false)); // Check for correct priority $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1); $this->assertEquals($priority, $mountPoints['/' . self::TEST_USER1 . '/files/ext']['priority']); }
public function testAllowWritingIncompleteConfigIfStorageContructorFails() { $storageClass = 'Test_Mount_Config_Dummy_Storage'; $mountType = 'user'; $applicable = 'all'; $isPersonal = false; $this->assertEquals(0, OC_Mount_Config::addMountPoint('/ext', $storageClass, array('simulateFail' => true), $mountType, $applicable, $isPersonal)); // config can be retrieved afterwards $mounts = OC_Mount_Config::getSystemMountPoints(); $this->assertEquals(1, count($mounts)); // no storage id was set $this->assertFalse(isset($mounts[0]['storage_id'])); }
/** * saves mount configuration */ private function saveConfig() { // we read all mountpoints $mountPoints = \OC_Mount_Config::getAbsoluteMountPoints(\OCP\User::getUser()); // we use the refresh token as unique ID $new_refresh_token = json_decode($this->params['hubic_token'], TRUE)['refresh_token']; foreach ($mountPoints as $mountPoint => $options) { if ($options['class'] == '\\OC\\Files\\Storage\\Hubic' && json_decode($options['options']['hubic_token'], TRUE)['refresh_token'] == $new_refresh_token) { $shortMountPoint = end(explode('/', $mountPoint, 4)); if ($options['personal']) { $mountType = \OC_Mount_Config::MOUNT_TYPE_USER; $applicable = \OCP\User::getUser(); } else { $mountType = $options['priority_type']; $applicable = $options['applicable']; } \OC_Mount_Config::addMountPoint($shortMountPoint, $options['class'], $this->params, $mountType, $applicable, $options['personal'], $options['priority']); break; } } }