]> source.dussan.org Git - nextcloud-server.git/commitdiff
Prevent harder to share your root 21227/head
authorJoas Schilling <coding@schilljs.com>
Wed, 3 Jun 2020 07:29:19 +0000 (09:29 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 4 Jun 2020 09:03:54 +0000 (09:03 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Share20/Manager.php
tests/lib/Share20/ManagerTest.php

index 73860fd39f42baa344be1c5d6029fa6a2f4bd1af..111de519bfce431af437c9caffc74ecc7a97b52a 100644 (file)
@@ -278,12 +278,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');
                }
 
index 9bc1531ac7fb9e810478721fda14d4ac4bdc410e..476413b67ad31bec27ad050ed2ce7619b9b6cf7c 100644 (file)
@@ -647,7 +647,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];
@@ -707,7 +707,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);