From 982f2fc21abdc5adb40d07609f1b9c68b232d137 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 3 Jun 2020 09:29:19 +0200 Subject: [PATCH] Prevent harder to share your root Signed-off-by: Joas Schilling --- lib/private/Share20/Manager.php | 4 +--- tests/lib/Share20/ManagerTest.php | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index cbc456a974..0409327869 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -277,12 +277,10 @@ class Manager implements IManager { // And you can't share your rootfolder if ($this->userManager->userExists($share->getSharedBy())) { $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); - $userFolderPath = $userFolder->getPath(); } else { $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); - $userFolderPath = $userFolder->getPath(); } - if ($userFolderPath === $share->getNode()->getPath()) { + if ($userFolder->getId() === $share->getNode()->getId()) { throw new \InvalidArgumentException('You can’t share your root folder'); } diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 54feedf15c..e66ac51aee 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -646,7 +646,7 @@ class ManagerTest extends \Test\TestCase { $rootFolder = $this->createMock(Folder::class); $rootFolder->method('isShareable')->willReturn(true); $rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); - $rootFolder->method('getPath')->willReturn('myrootfolder'); + $rootFolder->method('getId')->willReturn(42); $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You can’t share your root folder', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You can’t share your root folder', true]; @@ -706,7 +706,9 @@ class ManagerTest extends \Test\TestCase { ]); $userFolder = $this->createMock(Folder::class); - $userFolder->method('getPath')->willReturn('myrootfolder'); + $userFolder->expects($this->any()) + ->method('getId') + ->willReturn(42); $userFolder->expects($this->any()) ->method('getRelativePath') ->willReturnArgument(0);