From c426b9c4e71d6b99eec7c68716a7ee152ed43f1c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 28 Feb 2025 17:06:47 +0100 Subject: [PATCH] feat: add appconfig value to disable fixed userfolder permissions optimization Signed-off-by: Robin Appelman --- lib/private/Files/Node/LazyUserFolder.php | 20 ++++++---- lib/private/Files/Node/Root.php | 6 ++- lib/private/Server.php | 1 + tests/lib/Files/Node/FileTest.php | 15 ++++--- tests/lib/Files/Node/FolderTest.php | 46 +++++++++++----------- tests/lib/Files/Node/HookConnectorTest.php | 2 + tests/lib/Files/Node/IntegrationTest.php | 2 + tests/lib/Files/Node/NodeTest.php | 11 +++++- tests/lib/Files/Node/RootTest.php | 10 +++++ 9 files changed, 74 insertions(+), 39 deletions(-) diff --git a/lib/private/Files/Node/LazyUserFolder.php b/lib/private/Files/Node/LazyUserFolder.php index 77479c2fa5e06..07bc47460235f 100644 --- a/lib/private/Files/Node/LazyUserFolder.php +++ b/lib/private/Files/Node/LazyUserFolder.php @@ -23,10 +23,20 @@ class LazyUserFolder extends LazyFolder { private string $path; private IMountManager $mountManager; - public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager $mountManager) { + public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager $mountManager, bool $useDefaultPermissions = true) { $this->user = $user; $this->mountManager = $mountManager; $this->path = '/' . $user->getUID() . '/files'; + $data = [ + 'path' => $this->path, + // Sharing user root folder is not allowed + 'type' => FileInfo::TYPE_FOLDER, + 'mimetype' => FileInfo::MIMETYPE_FOLDER, + ]; + if ($useDefaultPermissions) { + $data['permissions'] = Constants::PERMISSION_ALL ^ Constants::PERMISSION_SHARE; + } + parent::__construct($rootFolder, function () use ($user): Folder { try { $node = $this->getRootFolder()->get($this->path); @@ -44,13 +54,7 @@ public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager } return $this->getRootFolder()->newFolder($this->path); } - }, [ - 'path' => $this->path, - // Sharing user root folder is not allowed - 'permissions' => Constants::PERMISSION_ALL ^ Constants::PERMISSION_SHARE, - 'type' => FileInfo::TYPE_FOLDER, - 'mimetype' => FileInfo::MIMETYPE_FOLDER, - ]); + }, $data); } public function getMountPoint() { diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 1686051131dac..feb855b63ae10 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -24,6 +24,7 @@ use OCP\Files\Node as INode; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\IAppConfig; use OCP\ICache; use OCP\ICacheFactory; use OCP\IUser; @@ -60,6 +61,7 @@ class Root extends Folder implements IRootFolder { private IUserManager $userManager; private IEventDispatcher $eventDispatcher; private ICache $pathByIdCache; + private bool $homeFolderOverwritten = false; /** * @param Manager $manager @@ -75,6 +77,7 @@ public function __construct( IUserManager $userManager, IEventDispatcher $eventDispatcher, ICacheFactory $cacheFactory, + IAppConfig $appConfig, ) { parent::__construct($this, $view, ''); $this->mountManager = $manager; @@ -88,6 +91,7 @@ public function __construct( $this->userFolderCache = new CappedMemoryCache(); }); $this->pathByIdCache = $cacheFactory->createLocal('path-by-id'); + $this->homeFolderOverwritten = $appConfig->getValueBool('files', 'homeFolderOverwritten'); } /** @@ -367,7 +371,7 @@ public function getUserFolder($userId) { $folder = $this->newFolder('/' . $userId . '/files'); } } else { - $folder = new LazyUserFolder($this, $userObject, $this->mountManager); + $folder = new LazyUserFolder($this, $userObject, $this->mountManager, !$this->homeFolderOverwritten); } $this->userFolderCache->set($userId, $folder); diff --git a/lib/private/Server.php b/lib/private/Server.php index 77759de30c5d1..1b70769c85aa6 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -406,6 +406,7 @@ public function __construct($webRoot, \OC\Config $config) { $this->get(IUserManager::class), $this->get(IEventDispatcher::class), $this->get(ICacheFactory::class), + $this->get(IAppConfig::class), ); $previewConnector = new \OC\Preview\WatcherConnector( diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index a67c94336630f..fc4968d436cc2 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -38,7 +38,7 @@ protected function getViewDeleteMethod() { public function testGetContent(): void { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $hook = function ($file) { @@ -68,7 +68,7 @@ public function testGetContentNotPermitted(): void { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) @@ -87,7 +87,7 @@ public function testGetContentNotPermitted(): void { public function testPutContent(): void { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) @@ -114,7 +114,7 @@ public function testPutContentNotPermitted(): void { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $this->view->expects($this->once()) @@ -129,7 +129,7 @@ public function testPutContentNotPermitted(): void { public function testGetMimeType(): void { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $this->view->expects($this->once()) @@ -155,6 +155,7 @@ public function testFOpenRead(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $hook = function ($file) { @@ -192,6 +193,7 @@ public function testFOpenWrite(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $hooksCalled = 0; $hook = function ($file) use (&$hooksCalled) { @@ -233,6 +235,7 @@ public function testFOpenReadNotPermitted(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $hook = function ($file) { throw new \Exception('Hooks are not supposed to be called'); @@ -260,6 +263,7 @@ public function testFOpenReadWriteNoReadPermissions(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); @@ -287,6 +291,7 @@ public function testFOpenReadWriteNoWritePermissions(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index e3edf202f8eef..12ab85904cc78 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -70,7 +70,7 @@ public function testGetDirectoryContent(): void { * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view */ $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -103,7 +103,7 @@ public function testGet(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -122,7 +122,7 @@ public function testNodeExists(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -142,7 +142,7 @@ public function testNodeExistsNotExists(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -160,7 +160,7 @@ public function testNewFolder(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -184,7 +184,7 @@ public function testNewFolderDeepParent(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -211,7 +211,7 @@ public function testNewFolderNotPermitted(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -228,7 +228,7 @@ public function testNewFile(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -255,7 +255,7 @@ public function testNewFileNotPermitted(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -272,7 +272,7 @@ public function testGetFreeSpace(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -289,7 +289,7 @@ public function testSearch(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -338,7 +338,7 @@ public function testSearchInRoot(): void { $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -381,7 +381,7 @@ public function testSearchInStorageRoot(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -424,7 +424,7 @@ public function testSearchSubStorages(): void { $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -500,7 +500,7 @@ public function testGetById(): void { $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) ->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); @@ -549,7 +549,7 @@ public function testGetByIdMountRoot(): void { $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) ->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); @@ -594,7 +594,7 @@ public function testGetByIdOutsideFolder(): void { $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) ->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); @@ -638,7 +638,7 @@ public function testGetByIdMultipleStorages(): void { $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) ->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount1 = new MountPoint($storage, '/bar'); @@ -699,7 +699,7 @@ public function testGetUniqueName($name, $existingFiles, $expected): void { $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $view->expects($this->any()) @@ -724,7 +724,7 @@ public function testRecent(): void { /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */ $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) @@ -793,7 +793,7 @@ public function testRecentFolder(): void { /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */ $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) @@ -860,7 +860,7 @@ public function testRecentJail(): void { /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */ $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) @@ -947,7 +947,7 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $manager = $this->createMock(Manager::class); $view = $this->getRootViewMock(); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); $root->expects($this->any()) ->method('getUser') diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 1a3337b9ddcee..64bc4d8f5bae1 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -30,6 +30,7 @@ use OCP\Files\Events\Node\NodeTouchedEvent; use OCP\Files\Events\Node\NodeWrittenEvent; use OCP\Files\Node; +use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IUserManager; use Psr\Log\LoggerInterface; @@ -85,6 +86,7 @@ protected function setUp(): void { $this->createMock(IUserManager::class), $this->createMock(IEventDispatcher::class), $cacheFactory, + $this->createMock(IAppConfig::class), ); $this->eventDispatcher = \OC::$server->query(IEventDispatcher::class); $this->logger = \OC::$server->query(LoggerInterface::class); diff --git a/tests/lib/Files/Node/IntegrationTest.php b/tests/lib/Files/Node/IntegrationTest.php index c90a6115f2aba..65194c58ee164 100644 --- a/tests/lib/Files/Node/IntegrationTest.php +++ b/tests/lib/Files/Node/IntegrationTest.php @@ -14,6 +14,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; use OCP\Files\Mount\IMountManager; +use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IUserManager; use Psr\Log\LoggerInterface; @@ -69,6 +70,7 @@ protected function setUp(): void { $this->createMock(IUserManager::class), $this->createMock(IEventDispatcher::class), $cacheFactory, + $this->createMock(IAppConfig::class), ); $storage = new Temporary([]); $subStorage = new Temporary([]); diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index db87aa925d3b3..5c26a5386a04c 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -17,6 +17,7 @@ use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorage; +use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IUser; use OCP\IUserManager; @@ -46,6 +47,8 @@ abstract class NodeTest extends \Test\TestCase { protected $eventDispatcher; /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */ protected $cacheFactory; + /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */ + protected $appConfig; protected function setUp(): void { parent::setUp(); @@ -71,8 +74,10 @@ protected function setUp(): void { ->willReturnCallback(function () { return new ArrayCache(); }); + $this->appConfig = $this->createMock(IAppConfig::class); + $this->root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->getMock(); } @@ -184,6 +189,7 @@ public function testDeleteHooks(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->createMock(IAppConfig::class), ); $root->listen('\OC\Files', 'preDelete', $preListener); @@ -433,6 +439,7 @@ public function testTouchHooks(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->createMock(IAppConfig::class), ); $root->listen('\OC\Files', 'preTouch', $preListener); $root->listen('\OC\Files', 'postTouch', $postListener); @@ -609,7 +616,7 @@ public function moveOrCopyProvider() { public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName): void { /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory, $this->appConfig]) ->setMethods(['get']) ->getMock(); diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index f2ef1a0e3ee04..7890b2c1a2620 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -14,6 +14,7 @@ use OC\Memcache\ArrayCache; use OCP\Cache\CappedMemoryCache; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IUser; use OCP\IUserManager; @@ -39,6 +40,8 @@ class RootTest extends \Test\TestCase { private $eventDispatcher; /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */ protected $cacheFactory; + /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */ + protected $appConfig; protected function setUp(): void { parent::setUp(); @@ -58,6 +61,7 @@ protected function setUp(): void { ->willReturnCallback(function () { return new ArrayCache(); }); + $this->appConfig = $this->createMock(IAppConfig::class); } /** @@ -92,6 +96,7 @@ public function testGet(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $view->expects($this->once()) @@ -125,6 +130,7 @@ public function testGetNotFound(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $view->expects($this->once()) @@ -150,6 +156,7 @@ public function testGetInvalidPath(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $root->get('/../foo'); @@ -169,6 +176,7 @@ public function testGetNoStorages(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $root->get('/bar/foo'); @@ -184,6 +192,7 @@ public function testGetUserFolder(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $user = $this->createMock(IUser::class); $user @@ -226,6 +235,7 @@ public function testGetUserFolderWithNoUserObj(): void { $this->userManager, $this->eventDispatcher, $this->cacheFactory, + $this->appConfig, ); $this->userManager ->expects($this->once())