From ec0985ba68069a6fb2bd3c9454be5d533a124881 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 25 Jan 2021 17:38:34 +0100 Subject: fix search in nested jails Signed-off-by: Robin Appelman --- apps/files_sharing/lib/Cache.php | 4 ++++ apps/files_sharing/tests/CacheTest.php | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'apps/files_sharing') diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php index c3f31ac3e4f..3a6ade5a2ac 100644 --- a/apps/files_sharing/lib/Cache.php +++ b/apps/files_sharing/lib/Cache.php @@ -89,6 +89,10 @@ class Cache extends CacheJail { return $this->root; } + protected function getGetUnjailedRoot() { + return $this->sourceRootInfo->getPath(); + } + public function getCache() { if (is_null($this->cache)) { $sourceStorage = $this->storage->getSourceStorage(); diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index b55fba78d42..ba9f347e291 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -517,4 +517,40 @@ class CacheTest extends TestCase { $this->assertTrue($sourceStorage->getCache()->inCache('jail/sub/bar.txt')); } + + public function testSearchShareJailedStorage() { + $sourceStorage = new Temporary(); + $sourceStorage->mkdir('jail'); + $sourceStorage->mkdir('jail/sub'); + $sourceStorage->file_put_contents('jail/sub/foo.txt', 'foo'); + $jailedSource = new Jail([ + 'storage' => $sourceStorage, + 'root' => 'jail' + ]); + $sourceStorage->getScanner()->scan(''); + $this->registerMount(self::TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo'); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + + $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1); + $node = $rootFolder->get('foo/sub'); + $share = $this->shareManager->newShare(); + $share->setNode($node) + ->setShareType(IShare::TYPE_USER) + ->setSharedWith(self::TEST_FILES_SHARING_API_USER2) + ->setSharedBy(self::TEST_FILES_SHARING_API_USER1) + ->setPermissions(\OCP\Constants::PERMISSION_ALL); + $share = $this->shareManager->createShare($share); + $share->setStatus(IShare::STATUS_ACCEPTED); + $this->shareManager->updateShare($share); + \OC_Util::tearDownFS(); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + + /** @var SharedStorage $sharedStorage */ + list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub'); + + $results = $sharedStorage->getCache()->search("foo.txt"); + $this->assertCount(1, $results); + } } -- cgit v1.2.3