diff options
Diffstat (limited to 'tests/lib/files/filesystem.php')
-rw-r--r-- | tests/lib/files/filesystem.php | 167 |
1 files changed, 143 insertions, 24 deletions
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index bef70cc725b..90f1dfe581b 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -26,7 +26,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase { /** * @var array tmpDirs */ - private $tmpDirs=array(); + private $tmpDirs = array(); /** * @return array @@ -41,57 +41,115 @@ class Filesystem extends \PHPUnit_Framework_TestCase { foreach ($this->tmpDirs as $dir) { \OC_Helper::rmdirr($dir); } + \OC\Files\Filesystem::clearMounts(); + \OC_User::setUserId(''); } public function setUp() { + \OC_User::setUserId(''); \OC\Files\Filesystem::clearMounts(); } public function testMount() { - \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); + \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); } public function testNormalize() { + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('')); + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('/')); + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('/', false)); + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('//')); + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('//', false)); $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('/path/')); $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('/path/', false)); $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('path')); - $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\path')); $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/')); + $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo//bar/', false)); $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar')); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/////bar')); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/.')); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/./')); + $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/bar/./', false)); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/./.')); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/././')); + $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/bar/././', false)); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/./bar/')); + $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/./bar/', false)); + $this->assertEquals('/foo/.bar', \OC\Files\Filesystem::normalizePath('/foo/.bar/')); + $this->assertEquals('/foo/.bar/', \OC\Files\Filesystem::normalizePath('/foo/.bar/', false)); + $this->assertEquals('/foo/.bar/tee', \OC\Files\Filesystem::normalizePath('/foo/.bar/tee')); + + // normalize does not resolve '..' (by design) + $this->assertEquals('/foo/..', \OC\Files\Filesystem::normalizePath('/foo/../')); + if (class_exists('Patchwork\PHP\Shim\Normalizer')) { $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88")); } } + public function testNormalizeWindowsPaths() { + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('')); + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\')); + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\', false)); + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\\\')); + $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\\\', false)); + $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path')); + $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path', false)); + $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path\\')); + $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('\\path\\', false)); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\bar\\')); + $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\\\bar\\', false)); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\\\\\bar')); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\\\\\\\bar')); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.')); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\')); + $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\', false)); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.')); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.\\')); + $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.\\', false)); + $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\.\\bar\\')); + $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\.\\bar\\', false)); + $this->assertEquals('/foo/.bar', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\')); + $this->assertEquals('/foo/.bar/', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\', false)); + $this->assertEquals('/foo/.bar/tee', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\tee')); + + // normalize does not resolve '..' (by design) + $this->assertEquals('/foo/..', \OC\Files\Filesystem::normalizePath('\\foo\\..\\')); + + if (class_exists('Patchwork\PHP\Shim\Normalizer')) { + $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("\\foo\\baru\xCC\x88")); + } + } + public function testHooks() { - if(\OC\Files\Filesystem::getView()){ + if (\OC\Files\Filesystem::getView()) { $user = \OC_User::getUser(); - }else{ - $user=uniqid(); - \OC\Files\Filesystem::init($user, '/'.$user.'/files'); + } else { + $user = uniqid(); + \OC\Files\Filesystem::init($user, '/' . $user . '/files'); } \OC_Hook::clear('OC_Filesystem'); \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); - $rootView=new \OC\Files\View(''); - $rootView->mkdir('/'.$user); - $rootView->mkdir('/'.$user.'/files'); + $rootView = new \OC\Files\View(''); + $rootView->mkdir('/' . $user); + $rootView->mkdir('/' . $user . '/files'); // \OC\Files\Filesystem::file_put_contents('/foo', 'foo'); \OC\Files\Filesystem::mkdir('/bar'); @@ -103,6 +161,67 @@ class Filesystem extends \PHPUnit_Framework_TestCase { // \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh); } + /** + * Tests that a local storage mount is used when passed user + * does not exist. + */ + public function testLocalMountWhenUserDoesNotExist() { + $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); + $userId = uniqid('user_'); + + \OC\Files\Filesystem::initMountPoints($userId); + + $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); + + $this->assertInstanceOf('\OC\Files\Storage\Local', $homeMount); + $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId()); + } + + /** + * Tests that the home storage is used for the user's mount point + */ + public function testHomeMount() { + $userId = uniqid('user_'); + + \OC_User::createUser($userId, $userId); + + \OC\Files\Filesystem::initMountPoints($userId); + + $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); + + $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount); + $this->assertEquals('home::' . $userId, $homeMount->getId()); + + \OC_User::deleteUser($userId); + } + + /** + * Tests that the home storage is used in legacy mode + * for the user's mount point + */ + public function testLegacyHomeMount() { + $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); + $userId = uniqid('user_'); + + // insert storage into DB by constructing it + // to make initMountsPoint find its existence + $localStorage = new \OC\Files\Storage\Local(array('datadir' => $datadir . '/' . $userId . '/')); + // this will trigger the insert + $cache = $localStorage->getCache(); + + \OC_User::createUser($userId, $userId); + \OC\Files\Filesystem::initMountPoints($userId); + + $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); + + $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount); + $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId()); + + \OC_User::deleteUser($userId); + // delete storage entry + $cache->clear(); + } + 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 |