Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prevent harder to share your root
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Jun 4, 2020
commit 982f2fc21abdc5adb40d07609f1b9c68b232d137
4 changes: 1 addition & 3 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,10 @@ protected function generalCreateChecks(\OCP\Share\IShare $share) {
// 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');
}

Expand Down
6 changes: 4 additions & 2 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public function dataGeneralChecks() {
$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];
Expand Down Expand Up @@ -706,7 +706,9 @@ public function testGeneralChecks($share, $exceptionMessage, $exception) {
]);

$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);
Expand Down