]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(files): Check if the target path is a descendant of the shared folder path backport/47756/stable30 47796/head
authorGit'Fellow <12234510+solracsf@users.noreply.github.com>
Wed, 4 Sep 2024 20:24:19 +0000 (22:24 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Fri, 6 Sep 2024 02:00:43 +0000 (02:00 +0000)
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
fix: tests

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
fix: fix tests

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
fix: add tests

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
fix: tests

lib/private/Files/View.php
tests/lib/Files/ViewTest.php

index 2f0d297237df8b330f25a9681f9236b5ec55e175..db2483fab766e8409ab41cc1679ccfbb88ec6de6 100644 (file)
@@ -1794,7 +1794,8 @@ class View {
                }, $providers));
 
                foreach ($shares as $share) {
-                       if (str_starts_with($targetPath, $share->getNode()->getPath())) {
+                       $sharedPath = $share->getNode()->getPath();
+                       if ($targetPath === $sharedPath || str_starts_with($targetPath, $sharedPath . '/')) {
                                $this->logger->debug(
                                        'It is not allowed to move one mount point into a shared folder',
                                        ['app' => 'files']);
index 379a8389355ab0696630ff6b4cdd933cbe18f254..2dfbf61641ac0daac35d3c2b659cef92acbae91c 100644 (file)
@@ -1668,17 +1668,24 @@ class ViewTest extends \Test\TestCase {
        public function testMoveMountPointIntoSharedFolder() {
                self::loginAsUser($this->user);
 
-               [$mount1] = $this->createTestMovableMountPoints([
+               [$mount1, $mount2] = $this->createTestMovableMountPoints([
                        $this->user . '/files/mount1',
+                       $this->user . '/files/mount2',
                ]);
 
                $mount1->expects($this->never())
                        ->method('moveMount');
 
+               $mount2->expects($this->once())
+                       ->method('moveMount')
+                       ->willReturn(true);
+
                $view = new View('/' . $this->user . '/files/');
                $view->mkdir('shareddir');
                $view->mkdir('shareddir/sub');
                $view->mkdir('shareddir/sub2');
+               // Create a similar named but non-shared folder
+               $view->mkdir('shareddir notshared');
 
                $fileId = $view->getFileInfo('shareddir')->getId();
                $userObject = \OC::$server->getUserManager()->createUser('test2', 'IHateNonMockableStaticClasses');
@@ -1697,6 +1704,7 @@ class ViewTest extends \Test\TestCase {
                $this->assertFalse($view->rename('mount1', 'shareddir'), 'Cannot overwrite shared folder');
                $this->assertFalse($view->rename('mount1', 'shareddir/sub'), 'Cannot move mount point into shared folder');
                $this->assertFalse($view->rename('mount1', 'shareddir/sub/sub2'), 'Cannot move mount point into shared subfolder');
+               $this->assertTrue($view->rename('mount2', 'shareddir notshared/sub'), 'Can move mount point into a similarly named but non-shared folder');
 
                $shareManager->deleteShare($share);
                $userObject->delete();