Skip to content

Commit a1204be

Browse files
authored
Merge pull request #21226 from nextcloud/backport/21199/stable19
[stable19] Prevent harder to share your root
2 parents c296a55 + 982f2fc commit a1204be

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/private/Share20/Manager.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,10 @@ protected function generalCreateChecks(\OCP\Share\IShare $share) {
277277
// And you can't share your rootfolder
278278
if ($this->userManager->userExists($share->getSharedBy())) {
279279
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
280-
$userFolderPath = $userFolder->getPath();
281280
} else {
282281
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
283-
$userFolderPath = $userFolder->getPath();
284282
}
285-
if ($userFolderPath === $share->getNode()->getPath()) {
283+
if ($userFolder->getId() === $share->getNode()->getId()) {
286284
throw new \InvalidArgumentException('You can’t share your root folder');
287285
}
288286

tests/lib/Share20/ManagerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ public function dataGeneralChecks() {
646646
$rootFolder = $this->createMock(Folder::class);
647647
$rootFolder->method('isShareable')->willReturn(true);
648648
$rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL);
649-
$rootFolder->method('getPath')->willReturn('myrootfolder');
649+
$rootFolder->method('getId')->willReturn(42);
650650

651651
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You can’t share your root folder', true];
652652
$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 @@ public function testGeneralChecks($share, $exceptionMessage, $exception) {
706706
]);
707707

708708
$userFolder = $this->createMock(Folder::class);
709-
$userFolder->method('getPath')->willReturn('myrootfolder');
709+
$userFolder->expects($this->any())
710+
->method('getId')
711+
->willReturn(42);
710712
$userFolder->expects($this->any())
711713
->method('getRelativePath')
712714
->willReturnArgument(0);

0 commit comments

Comments
 (0)