2012-10-26 20:07:01 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Robin Appelman
|
|
|
|
* @copyright 2012 Robin Appelman icewind@owncloud.com
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Files;
|
|
|
|
|
2015-05-07 15:07:02 +03:00
|
|
|
use OC\Files\Mount\MountPoint;
|
|
|
|
use OC\Files\Storage\Temporary;
|
2015-04-02 12:28:10 +03:00
|
|
|
use OC\User\NoUserException;
|
2015-05-07 15:07:02 +03:00
|
|
|
use OCP\Files\Config\IMountProvider;
|
|
|
|
use OCP\Files\Storage\IStorageFactory;
|
|
|
|
use OCP\IUser;
|
|
|
|
|
|
|
|
class DummyMountProvider implements IMountProvider {
|
|
|
|
private $mounts = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $mounts
|
|
|
|
*/
|
|
|
|
public function __construct(array $mounts) {
|
|
|
|
$this->mounts = $mounts;
|
|
|
|
}
|
|
|
|
|
2015-05-08 14:51:32 +03:00
|
|
|
/**
|
|
|
|
* Get the pre-registered mount points
|
|
|
|
*
|
|
|
|
* @param IUser $user
|
|
|
|
* @param IStorageFactory $loader
|
|
|
|
* @return \OCP\Files\Mount\IMountPoint[]
|
|
|
|
*/
|
2020-04-09 14:53:40 +03:00
|
|
|
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
|
2015-05-07 15:07:02 +03:00
|
|
|
return isset($this->mounts[$user->getUID()]) ? $this->mounts[$user->getUID()] : [];
|
|
|
|
}
|
|
|
|
}
|
2015-04-02 12:28:10 +03:00
|
|
|
|
2015-11-03 03:52:41 +03:00
|
|
|
/**
|
2016-05-20 16:38:20 +03:00
|
|
|
* Class FilesystemTest
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test\Files
|
|
|
|
*/
|
2016-05-20 16:38:20 +03:00
|
|
|
class FilesystemTest extends \Test\TestCase {
|
2015-04-09 15:03:30 +03:00
|
|
|
|
|
|
|
const TEST_FILESYSTEM_USER1 = "test-filesystem-user1";
|
2015-05-07 15:07:02 +03:00
|
|
|
const TEST_FILESYSTEM_USER2 = "test-filesystem-user1";
|
2015-04-09 15:03:30 +03:00
|
|
|
|
2012-10-26 20:07:01 +04:00
|
|
|
/**
|
|
|
|
* @var array tmpDirs
|
|
|
|
*/
|
2020-03-26 11:30:18 +03:00
|
|
|
private $tmpDirs = [];
|
2012-10-26 20:07:01 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getStorageData() {
|
2015-12-18 13:19:53 +03:00
|
|
|
$dir = \OC::$server->getTempManager()->getTemporaryFolder();
|
2012-10-26 20:07:01 +04:00
|
|
|
$this->tmpDirs[] = $dir;
|
2020-03-26 11:30:18 +03:00
|
|
|
return ['datadir' => $dir];
|
2012-10-26 20:07:01 +04:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-12 17:54:41 +03:00
|
|
|
parent::setUp();
|
2015-09-22 01:56:36 +03:00
|
|
|
$userBackend = new \Test\Util\User\Dummy();
|
2015-05-07 15:07:02 +03:00
|
|
|
$userBackend->createUser(self::TEST_FILESYSTEM_USER1, self::TEST_FILESYSTEM_USER1);
|
|
|
|
$userBackend->createUser(self::TEST_FILESYSTEM_USER2, self::TEST_FILESYSTEM_USER2);
|
|
|
|
\OC::$server->getUserManager()->registerBackend($userBackend);
|
2015-04-08 13:03:55 +03:00
|
|
|
$this->loginAsUser();
|
2014-11-12 17:54:41 +03:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2012-10-26 20:07:01 +04:00
|
|
|
foreach ($this->tmpDirs as $dir) {
|
|
|
|
\OC_Helper::rmdirr($dir);
|
|
|
|
}
|
2014-11-07 17:23:15 +03:00
|
|
|
|
2015-04-08 13:03:55 +03:00
|
|
|
$this->logout();
|
2016-06-01 13:20:38 +03:00
|
|
|
$this->invokePrivate('\OC\Files\Filesystem', 'normalizedPathCache', [null]);
|
2014-11-07 17:23:15 +03:00
|
|
|
parent::tearDown();
|
2012-10-26 20:07:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMount() {
|
2013-12-06 21:26:38 +04:00
|
|
|
\OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/');
|
|
|
|
$this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/'));
|
|
|
|
$this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/some/folder'));
|
|
|
|
list(, $internalPath) = \OC\Files\Filesystem::resolvePath('/');
|
|
|
|
$this->assertEquals('', $internalPath);
|
|
|
|
list(, $internalPath) = \OC\Files\Filesystem::resolvePath('/some/folder');
|
|
|
|
$this->assertEquals('some/folder', $internalPath);
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/some');
|
|
|
|
$this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/'));
|
|
|
|
$this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some/folder'));
|
|
|
|
$this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some/'));
|
|
|
|
$this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some'));
|
|
|
|
list(, $internalPath) = \OC\Files\Filesystem::resolvePath('/some/folder');
|
|
|
|
$this->assertEquals('folder', $internalPath);
|
2012-10-26 20:07:01 +04:00
|
|
|
}
|
|
|
|
|
2014-11-17 18:52:45 +03:00
|
|
|
public function normalizePathData() {
|
2018-10-08 23:51:40 +03:00
|
|
|
return [
|
|
|
|
['/', ''],
|
|
|
|
['/', '/'],
|
|
|
|
['/', '//'],
|
|
|
|
['/', '/', false],
|
|
|
|
['/', '//', false],
|
|
|
|
|
|
|
|
['/path', '/path/'],
|
|
|
|
['/path/', '/path/', false],
|
|
|
|
['/path', 'path'],
|
|
|
|
|
|
|
|
['/foo/bar', '/foo//bar/'],
|
|
|
|
['/foo/bar/', '/foo//bar/', false],
|
|
|
|
['/foo/bar', '/foo////bar'],
|
|
|
|
['/foo/bar', '/foo/////bar'],
|
|
|
|
['/foo/bar', '/foo/bar/.'],
|
|
|
|
['/foo/bar', '/foo/bar/./'],
|
|
|
|
['/foo/bar/', '/foo/bar/./', false],
|
|
|
|
['/foo/bar', '/foo/bar/./.'],
|
|
|
|
['/foo/bar', '/foo/bar/././'],
|
|
|
|
['/foo/bar/', '/foo/bar/././', false],
|
|
|
|
['/foo/bar', '/foo/./bar/'],
|
|
|
|
['/foo/bar/', '/foo/./bar/', false],
|
|
|
|
['/foo/.bar', '/foo/.bar/'],
|
|
|
|
['/foo/.bar/', '/foo/.bar/', false],
|
|
|
|
['/foo/.bar/tee', '/foo/.bar/tee'],
|
|
|
|
|
|
|
|
['/foo/bar', '/.///././//./foo/.///././//./bar/./././.'],
|
|
|
|
['/foo/bar/', '/.///././//./foo/.///././//./bar/./././.', false],
|
|
|
|
['/foo/bar', '/.///././//./foo/.///././//./bar/././././'],
|
|
|
|
['/foo/bar/', '/.///././//./foo/.///././//./bar/././././', false],
|
2014-11-17 18:52:45 +03:00
|
|
|
|
|
|
|
// Windows paths
|
2018-10-08 23:51:40 +03:00
|
|
|
['/', ''],
|
|
|
|
['/', '\\'],
|
|
|
|
['/', '\\', false],
|
|
|
|
['/', '\\\\'],
|
|
|
|
['/', '\\\\', false],
|
|
|
|
|
|
|
|
['/path', '\\path'],
|
|
|
|
['/path', '\\path', false],
|
|
|
|
['/path', '\\path\\'],
|
|
|
|
['/path/', '\\path\\', false],
|
|
|
|
|
|
|
|
['/foo/bar', '\\foo\\\\bar\\'],
|
|
|
|
['/foo/bar/', '\\foo\\\\bar\\', false],
|
|
|
|
['/foo/bar', '\\foo\\\\\\\\bar'],
|
|
|
|
['/foo/bar', '\\foo\\\\\\\\\\bar'],
|
|
|
|
['/foo/bar', '\\foo\\bar\\.'],
|
|
|
|
['/foo/bar', '\\foo\\bar\\.\\'],
|
|
|
|
['/foo/bar/', '\\foo\\bar\\.\\', false],
|
|
|
|
['/foo/bar', '\\foo\\bar\\.\\.'],
|
|
|
|
['/foo/bar', '\\foo\\bar\\.\\.\\'],
|
|
|
|
['/foo/bar/', '\\foo\\bar\\.\\.\\', false],
|
|
|
|
['/foo/bar', '\\foo\\.\\bar\\'],
|
|
|
|
['/foo/bar/', '\\foo\\.\\bar\\', false],
|
|
|
|
['/foo/.bar', '\\foo\\.bar\\'],
|
|
|
|
['/foo/.bar/', '\\foo\\.bar\\', false],
|
|
|
|
['/foo/.bar/tee', '\\foo\\.bar\\tee'],
|
2014-11-17 18:52:45 +03:00
|
|
|
|
2014-11-17 18:57:15 +03:00
|
|
|
// Absolute windows paths NOT marked as absolute
|
2018-10-08 23:51:40 +03:00
|
|
|
['/C:', 'C:\\'],
|
|
|
|
['/C:/', 'C:\\', false],
|
|
|
|
['/C:/tests', 'C:\\tests'],
|
|
|
|
['/C:/tests', 'C:\\tests', false],
|
|
|
|
['/C:/tests', 'C:\\tests\\'],
|
|
|
|
['/C:/tests/', 'C:\\tests\\', false],
|
|
|
|
['/C:/tests/bar', 'C:\\tests\\.\\.\\bar'],
|
|
|
|
['/C:/tests/bar/', 'C:\\tests\\.\\.\\bar\\.\\', false],
|
2014-11-17 18:57:15 +03:00
|
|
|
|
2014-11-17 18:52:45 +03:00
|
|
|
// normalize does not resolve '..' (by design)
|
2018-10-08 23:51:40 +03:00
|
|
|
['/foo/..', '/foo/../'],
|
|
|
|
['/foo/..', '\\foo\\..\\'],
|
|
|
|
];
|
2014-11-17 18:52:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider normalizePathData
|
|
|
|
*/
|
2014-11-17 18:57:15 +03:00
|
|
|
public function testNormalizePath($expected, $path, $stripTrailingSlash = true) {
|
|
|
|
$this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash));
|
|
|
|
}
|
|
|
|
|
2016-06-01 13:20:38 +03:00
|
|
|
public function normalizePathKeepUnicodeData() {
|
|
|
|
$nfdName = 'ümlaut';
|
|
|
|
$nfcName = 'ümlaut';
|
|
|
|
return [
|
|
|
|
['/' . $nfcName, $nfcName, true],
|
|
|
|
['/' . $nfcName, $nfcName, false],
|
|
|
|
['/' . $nfdName, $nfdName, true],
|
|
|
|
['/' . $nfcName, $nfdName, false],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider normalizePathKeepUnicodeData
|
|
|
|
*/
|
|
|
|
public function testNormalizePathKeepUnicode($expected, $path, $keepUnicode = false) {
|
|
|
|
$this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, true, false, $keepUnicode));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNormalizePathKeepUnicodeCache() {
|
|
|
|
$nfdName = 'ümlaut';
|
|
|
|
$nfcName = 'ümlaut';
|
|
|
|
// call in succession due to cache
|
|
|
|
$this->assertEquals('/' . $nfcName, \OC\Files\Filesystem::normalizePath($nfdName, true, false, false));
|
|
|
|
$this->assertEquals('/' . $nfdName, \OC\Files\Filesystem::normalizePath($nfdName, true, false, true));
|
|
|
|
}
|
|
|
|
|
2015-01-10 02:06:30 +03:00
|
|
|
public function isValidPathData() {
|
2020-03-26 11:30:18 +03:00
|
|
|
return [
|
|
|
|
['/', true],
|
|
|
|
['/path', true],
|
|
|
|
['/foo/bar', true],
|
|
|
|
['/foo//bar/', true],
|
|
|
|
['/foo////bar', true],
|
|
|
|
['/foo//\///bar', true],
|
|
|
|
['/foo/bar/.', true],
|
|
|
|
['/foo/bar/./', true],
|
|
|
|
['/foo/bar/./.', true],
|
|
|
|
['/foo/bar/././', true],
|
|
|
|
['/foo/bar/././..bar', true],
|
|
|
|
['/foo/bar/././..bar/a', true],
|
|
|
|
['/foo/bar/././..', false],
|
|
|
|
['/foo/bar/././../', false],
|
|
|
|
['/foo/bar/.././', false],
|
|
|
|
['/foo/bar/../../', false],
|
|
|
|
['/foo/bar/../..\\', false],
|
|
|
|
['..', false],
|
|
|
|
['../', false],
|
|
|
|
['../foo/bar', false],
|
|
|
|
['..\foo/bar', false],
|
|
|
|
];
|
2015-01-10 02:06:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider isValidPathData
|
|
|
|
*/
|
|
|
|
public function testIsValidPath($path, $expected) {
|
|
|
|
$this->assertSame($expected, \OC\Files\Filesystem::isValidPath($path));
|
|
|
|
}
|
|
|
|
|
2015-02-06 17:03:29 +03:00
|
|
|
public function isFileBlacklistedData() {
|
2020-03-26 11:30:18 +03:00
|
|
|
return [
|
|
|
|
['/etc/foo/bar/foo.txt', false],
|
|
|
|
['\etc\foo/bar\foo.txt', false],
|
|
|
|
['.htaccess', true],
|
|
|
|
['.htaccess/', true],
|
|
|
|
['.htaccess\\', true],
|
|
|
|
['/etc/foo\bar/.htaccess\\', true],
|
|
|
|
['/etc/foo\bar/.htaccess/', true],
|
|
|
|
['/etc/foo\bar/.htaccess/foo', false],
|
|
|
|
['//foo//bar/\.htaccess/', true],
|
|
|
|
['\foo\bar\.HTAccess', true],
|
|
|
|
];
|
2015-02-06 17:03:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider isFileBlacklistedData
|
|
|
|
*/
|
|
|
|
public function testIsFileBlacklisted($path, $expected) {
|
|
|
|
$this->assertSame($expected, \OC\Files\Filesystem::isFileBlacklisted($path));
|
|
|
|
}
|
|
|
|
|
2014-11-17 18:52:45 +03:00
|
|
|
public function testNormalizePathUTF8() {
|
|
|
|
if (!class_exists('Patchwork\PHP\Shim\Normalizer')) {
|
|
|
|
$this->markTestSkipped('UTF8 normalizer Patchwork was not found');
|
2013-11-14 16:15:03 +04:00
|
|
|
}
|
2014-11-17 18:52:45 +03:00
|
|
|
|
|
|
|
$this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88"));
|
|
|
|
$this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("\\foo\\baru\xCC\x88"));
|
2013-11-14 16:15:03 +04:00
|
|
|
}
|
|
|
|
|
2012-10-26 20:07:01 +04:00
|
|
|
public function testHooks() {
|
2013-12-06 21:26:38 +04:00
|
|
|
if (\OC\Files\Filesystem::getView()) {
|
2012-10-26 20:07:01 +04:00
|
|
|
$user = \OC_User::getUser();
|
2013-12-06 21:26:38 +04:00
|
|
|
} else {
|
2015-04-09 15:03:30 +03:00
|
|
|
$user = self::TEST_FILESYSTEM_USER1;
|
2015-09-22 01:56:36 +03:00
|
|
|
$backend = new \Test\Util\User\Dummy();
|
2015-04-09 15:03:30 +03:00
|
|
|
\OC_User::useBackend($backend);
|
|
|
|
$backend->createUser($user, $user);
|
|
|
|
$userObj = \OC::$server->getUserManager()->get($user);
|
|
|
|
\OC::$server->getUserSession()->setUser($userObj);
|
2013-12-06 21:26:38 +04:00
|
|
|
\OC\Files\Filesystem::init($user, '/' . $user . '/files');
|
2015-04-09 15:03:30 +03:00
|
|
|
|
2012-10-26 20:07:01 +04:00
|
|
|
}
|
|
|
|
\OC_Hook::clear('OC_Filesystem');
|
|
|
|
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
\OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', [], '/');
|
2012-10-26 20:07:01 +04:00
|
|
|
|
2013-12-06 21:26:38 +04:00
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
$rootView->mkdir('/' . $user);
|
|
|
|
$rootView->mkdir('/' . $user . '/files');
|
2012-10-26 20:07:01 +04:00
|
|
|
|
2013-02-05 23:21:29 +04:00
|
|
|
// \OC\Files\Filesystem::file_put_contents('/foo', 'foo');
|
2012-10-26 20:07:01 +04:00
|
|
|
\OC\Files\Filesystem::mkdir('/bar');
|
2013-02-05 23:21:29 +04:00
|
|
|
// \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
|
2012-10-26 20:07:01 +04:00
|
|
|
|
2015-12-18 13:25:33 +03:00
|
|
|
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
|
2012-10-26 20:07:01 +04:00
|
|
|
file_put_contents($tmpFile, 'foo');
|
|
|
|
$fh = fopen($tmpFile, 'r');
|
2013-02-05 23:21:29 +04:00
|
|
|
// \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
|
2012-10-26 20:07:01 +04:00
|
|
|
}
|
|
|
|
|
2013-11-12 18:46:01 +04:00
|
|
|
/**
|
2015-04-02 12:28:10 +03:00
|
|
|
* Tests that an exception is thrown when passed user does not exist.
|
2015-05-07 15:07:02 +03:00
|
|
|
*
|
2013-11-12 18:46:01 +04:00
|
|
|
*/
|
|
|
|
public function testLocalMountWhenUserDoesNotExist() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OC\User\NoUserException::class);
|
|
|
|
|
2014-12-02 15:51:36 +03:00
|
|
|
$userId = $this->getUniqueID('user_');
|
2013-11-12 18:46:01 +04:00
|
|
|
|
|
|
|
\OC\Files\Filesystem::initMountPoints($userId);
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2016-04-22 12:10:51 +03:00
|
|
|
public function testNullUserThrows() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OC\User\NoUserException::class);
|
|
|
|
|
2016-04-22 12:10:51 +03:00
|
|
|
\OC\Files\Filesystem::initMountPoints(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNullUserThrowsTwice() {
|
|
|
|
$thrown = 0;
|
|
|
|
try {
|
|
|
|
\OC\Files\Filesystem::initMountPoints(null);
|
|
|
|
} catch (NoUserException $e) {
|
|
|
|
$thrown++;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
\OC\Files\Filesystem::initMountPoints(null);
|
|
|
|
} catch (NoUserException $e) {
|
|
|
|
$thrown++;
|
|
|
|
}
|
|
|
|
$this->assertEquals(2, $thrown);
|
|
|
|
}
|
|
|
|
|
2016-04-22 12:17:36 +03:00
|
|
|
/**
|
|
|
|
* Tests that an exception is thrown when passed user does not exist.
|
|
|
|
*/
|
|
|
|
public function testLocalMountWhenUserDoesNotExistTwice() {
|
|
|
|
$thrown = 0;
|
|
|
|
$userId = $this->getUniqueID('user_');
|
|
|
|
|
|
|
|
try {
|
|
|
|
\OC\Files\Filesystem::initMountPoints($userId);
|
|
|
|
} catch (NoUserException $e) {
|
|
|
|
$thrown++;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
\OC\Files\Filesystem::initMountPoints($userId);
|
|
|
|
} catch (NoUserException $e) {
|
|
|
|
$thrown++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals(2, $thrown);
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:46:01 +04:00
|
|
|
/**
|
|
|
|
* Tests that the home storage is used for the user's mount point
|
|
|
|
*/
|
|
|
|
public function testHomeMount() {
|
2014-12-02 15:51:36 +03:00
|
|
|
$userId = $this->getUniqueID('user_');
|
2013-11-12 18:46:01 +04:00
|
|
|
|
2015-12-17 17:10:11 +03:00
|
|
|
\OC::$server->getUserManager()->createUser($userId, $userId);
|
2013-11-12 18:46:01 +04:00
|
|
|
|
|
|
|
\OC\Files\Filesystem::initMountPoints($userId);
|
|
|
|
|
|
|
|
$homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
|
|
|
|
|
2015-10-01 14:23:30 +03:00
|
|
|
$this->assertTrue($homeMount->instanceOfStorage('\OCP\Files\IHomeStorage'));
|
2016-11-16 16:33:59 +03:00
|
|
|
if ($homeMount->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) {
|
2015-10-01 14:23:30 +03:00
|
|
|
$this->assertEquals('object::user:' . $userId, $homeMount->getId());
|
2016-11-16 16:33:59 +03:00
|
|
|
} else if ($homeMount->instanceOfStorage('\OC\Files\Storage\Home')) {
|
2015-10-01 14:23:30 +03:00
|
|
|
$this->assertEquals('home::' . $userId, $homeMount->getId());
|
|
|
|
}
|
2013-11-12 18:46:01 +04:00
|
|
|
|
2015-12-17 17:59:23 +03:00
|
|
|
$user = \OC::$server->getUserManager()->get($userId);
|
|
|
|
if ($user !== null) { $user->delete(); }
|
2013-11-12 18:46:01 +04:00
|
|
|
}
|
|
|
|
|
2012-10-26 20:07:01 +04:00
|
|
|
public function dummyHook($arguments) {
|
|
|
|
$path = $arguments['path'];
|
|
|
|
$this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
|
|
|
|
}
|
2014-03-24 17:32:04 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the default cache dir is part of the user's home
|
|
|
|
*/
|
|
|
|
public function testMountDefaultCacheDir() {
|
2014-12-02 15:51:36 +03:00
|
|
|
$userId = $this->getUniqueID('user_');
|
2015-12-03 15:48:19 +03:00
|
|
|
$config = \OC::$server->getConfig();
|
|
|
|
$oldCachePath = $config->getSystemValue('cache_path', '');
|
2014-03-24 17:32:04 +04:00
|
|
|
// no cache path configured
|
2015-12-03 15:48:19 +03:00
|
|
|
$config->setSystemValue('cache_path', '');
|
2014-03-24 17:32:04 +04:00
|
|
|
|
2015-12-17 17:10:11 +03:00
|
|
|
\OC::$server->getUserManager()->createUser($userId, $userId);
|
2014-03-24 17:32:04 +04:00
|
|
|
\OC\Files\Filesystem::initMountPoints($userId);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'/' . $userId . '/',
|
|
|
|
\OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache')
|
|
|
|
);
|
|
|
|
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
|
2015-10-01 14:23:30 +03:00
|
|
|
$this->assertTrue($storage->instanceOfStorage('\OCP\Files\IHomeStorage'));
|
2014-03-24 17:32:04 +04:00
|
|
|
$this->assertEquals('cache', $internalPath);
|
2015-12-17 17:59:23 +03:00
|
|
|
$user = \OC::$server->getUserManager()->get($userId);
|
|
|
|
if ($user !== null) { $user->delete(); }
|
2014-03-24 17:32:04 +04:00
|
|
|
|
2015-12-03 15:48:19 +03:00
|
|
|
$config->setSystemValue('cache_path', $oldCachePath);
|
2014-03-24 17:32:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an external cache is mounted into
|
|
|
|
* the user's home
|
|
|
|
*/
|
|
|
|
public function testMountExternalCacheDir() {
|
2014-12-02 15:51:36 +03:00
|
|
|
$userId = $this->getUniqueID('user_');
|
2014-03-24 17:32:04 +04:00
|
|
|
|
2015-12-03 16:03:05 +03:00
|
|
|
$config = \OC::$server->getConfig();
|
|
|
|
$oldCachePath = $config->getSystemValue('cache_path', '');
|
2014-03-24 17:32:04 +04:00
|
|
|
// set cache path to temp dir
|
2015-12-18 13:19:53 +03:00
|
|
|
$cachePath = \OC::$server->getTempManager()->getTemporaryFolder() . '/extcache';
|
2015-12-03 16:03:05 +03:00
|
|
|
$config->setSystemValue('cache_path', $cachePath);
|
2014-03-24 17:32:04 +04:00
|
|
|
|
2015-12-17 17:10:11 +03:00
|
|
|
\OC::$server->getUserManager()->createUser($userId, $userId);
|
2014-03-24 17:32:04 +04:00
|
|
|
\OC\Files\Filesystem::initMountPoints($userId);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'/' . $userId . '/cache/',
|
|
|
|
\OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache')
|
|
|
|
);
|
|
|
|
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
|
2014-06-02 18:54:41 +04:00
|
|
|
$this->assertTrue($storage->instanceOfStorage('\OC\Files\Storage\Local'));
|
2014-03-24 17:32:04 +04:00
|
|
|
$this->assertEquals('', $internalPath);
|
2015-12-17 17:59:23 +03:00
|
|
|
$user = \OC::$server->getUserManager()->get($userId);
|
|
|
|
if ($user !== null) { $user->delete(); }
|
2014-03-24 17:32:04 +04:00
|
|
|
|
2015-12-03 16:03:05 +03:00
|
|
|
$config->setSystemValue('cache_path', $oldCachePath);
|
2014-03-24 17:32:04 +04:00
|
|
|
}
|
2015-05-07 15:07:02 +03:00
|
|
|
|
|
|
|
public function testRegisterMountProviderAfterSetup() {
|
|
|
|
\OC\Files\Filesystem::initMountPoints(self::TEST_FILESYSTEM_USER2);
|
|
|
|
$this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/foo/bar'));
|
|
|
|
$mount = new MountPoint(new Temporary([]), '/foo/bar');
|
|
|
|
$mountProvider = new DummyMountProvider([self::TEST_FILESYSTEM_USER2 => [$mount]]);
|
|
|
|
\OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
|
|
|
|
$this->assertEquals('/foo/bar/', \OC\Files\Filesystem::getMountPoint('/foo/bar'));
|
|
|
|
}
|
2012-10-26 20:07:01 +04:00
|
|
|
}
|