Merge pull request #21199 from nextcloud/bugfix/noid/prevent-harder-sharing-your-root

Prevent harder to share your root
This commit is contained in:
Joas Schilling 2020-06-04 10:59:22 +02:00 committed by GitHub
commit 59c1ff690a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -277,12 +277,10 @@ class Manager implements IManager {
// And you can't share your rootfolder // And you can't share your rootfolder
if ($this->userManager->userExists($share->getSharedBy())) { if ($this->userManager->userExists($share->getSharedBy())) {
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
$userFolderPath = $userFolder->getPath();
} else { } else {
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
$userFolderPath = $userFolder->getPath();
} }
if ($userFolderPath === $share->getNode()->getPath()) { if ($userFolder->getId() === $share->getNode()->getId()) {
throw new \InvalidArgumentException('You cant share your root folder'); throw new \InvalidArgumentException('You cant share your root folder');
} }

View File

@ -646,7 +646,7 @@ class ManagerTest extends \Test\TestCase {
$rootFolder = $this->createMock(Folder::class); $rootFolder = $this->createMock(Folder::class);
$rootFolder->method('isShareable')->willReturn(true); $rootFolder->method('isShareable')->willReturn(true);
$rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); $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 cant share your root folder', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You cant share your root folder', true];
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You cant share your root folder', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You cant share your root folder', true];
@ -706,7 +706,9 @@ class ManagerTest extends \Test\TestCase {
]); ]);
$userFolder = $this->createMock(Folder::class); $userFolder = $this->createMock(Folder::class);
$userFolder->method('getPath')->willReturn('myrootfolder'); $userFolder->expects($this->any())
->method('getId')
->willReturn(42);
$userFolder->expects($this->any()) $userFolder->expects($this->any())
->method('getRelativePath') ->method('getRelativePath')
->willReturnArgument(0); ->willReturnArgument(0);