From b116e80c5629caab679e158813f1b3fda13cb501 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 26 Feb 2016 16:05:32 +0100 Subject: [PATCH] Relax rootfolder check * Updated unit tests * Added intergration test --- build/integration/features/sharing-v1.feature | 14 +++++++++++++- lib/private/share20/manager.php | 2 +- tests/lib/share20/managertest.php | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index 462915cf5b..bfd52ec660 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -513,4 +513,16 @@ Feature: sharing When creating a share with | path | / | | shareType | 3 | - Then the OCS status code should be "403" \ No newline at end of file + Then the OCS status code should be "403" + + Scenario: Allow modification of reshare + Given user "user0" exists + And user "user1" exists + And user "user2" exists + And user "user0" created a folder "/TMP" + And file "TMP" of user "user0" is shared with user "user1" + And file "TMP" of user "user1" is shared with user "user2" + And As an "user1" + When Updating last share with + | permissions | 1 | + Then the OCS status code should be "100" diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index 6932360a7e..edcab8ab98 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -198,7 +198,7 @@ class Manager implements IManager { } // And you can't share your rootfolder - if ($this->rootFolder->getUserFolder($share->getSharedBy())->isSubNode($share->getNode()) === false) { + if ($this->rootFolder->getUserFolder($share->getSharedBy())->getPath() === $share->getNode()->getPath()) { 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 2c40bf65c2..27444d9035 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -644,6 +644,15 @@ class ManagerTest extends \Test\TestCase { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true]; + $rootFolder = $this->getMock('\OCP\Files\Folder'); + $rootFolder->method('isShareable')->willReturn(true); + $rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); + $rootFolder->method('getPath')->willReturn('myrootfolder'); + + $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]; + $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You can\'t share your root folder', true]; + $allPermssions = $this->getMock('\OCP\Files\Folder'); $allPermssions->method('isShareable')->willReturn(true); $allPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); @@ -678,8 +687,10 @@ class ManagerTest extends \Test\TestCase { ])); $userFolder = $this->getMock('\OCP\Files\Folder'); + $userFolder->method('getPath')->willReturn('myrootfolder'); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); + try { $this->invokePrivate($this->manager, 'generalCreateChecks', [$share]); $thrown = false;