Browse Source

feat(files): Add appconfig value to disable fixed userfolder permissions optimization

Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/51145/head
Louis Chemineau 2 weeks ago
parent
commit
bd8a0ec3cf
Failed to extract signature
  1. 1
      apps/files/composer/composer/autoload_classmap.php
  2. 1
      apps/files/composer/composer/autoload_static.php
  3. 4
      apps/files/lib/AppInfo/Application.php
  4. 46
      apps/files/lib/ConfigLexicon.php
  5. 64
      lib/private/Files/Node/LazyUserFolder.php
  6. 36
      lib/private/Files/Node/Root.php
  7. 1
      lib/private/Server.php
  8. 15
      tests/lib/Files/Node/FileTest.php
  9. 46
      tests/lib/Files/Node/FolderTest.php
  10. 2
      tests/lib/Files/Node/HookConnectorTest.php
  11. 2
      tests/lib/Files/Node/IntegrationTest.php
  12. 39
      tests/lib/Files/Node/NodeTestCase.php
  13. 36
      tests/lib/Files/Node/RootTest.php

1
apps/files/composer/composer/autoload_classmap.php

@ -50,6 +50,7 @@ return array(
'OCA\\Files\\Command\\ScanAppData' => $baseDir . '/../lib/Command/ScanAppData.php',
'OCA\\Files\\Command\\TransferOwnership' => $baseDir . '/../lib/Command/TransferOwnership.php',
'OCA\\Files\\Command\\WindowsCompatibleFilenames' => $baseDir . '/../lib/Command/WindowsCompatibleFilenames.php',
'OCA\\Files\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php',
'OCA\\Files\\Controller\\ApiController' => $baseDir . '/../lib/Controller/ApiController.php',
'OCA\\Files\\Controller\\ConversionApiController' => $baseDir . '/../lib/Controller/ConversionApiController.php',
'OCA\\Files\\Controller\\DirectEditingController' => $baseDir . '/../lib/Controller/DirectEditingController.php',

1
apps/files/composer/composer/autoload_static.php

@ -65,6 +65,7 @@ class ComposerStaticInitFiles
'OCA\\Files\\Command\\ScanAppData' => __DIR__ . '/..' . '/../lib/Command/ScanAppData.php',
'OCA\\Files\\Command\\TransferOwnership' => __DIR__ . '/..' . '/../lib/Command/TransferOwnership.php',
'OCA\\Files\\Command\\WindowsCompatibleFilenames' => __DIR__ . '/..' . '/../lib/Command/WindowsCompatibleFilenames.php',
'OCA\\Files\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php',
'OCA\\Files\\Controller\\ApiController' => __DIR__ . '/..' . '/../lib/Controller/ApiController.php',
'OCA\\Files\\Controller\\ConversionApiController' => __DIR__ . '/..' . '/../lib/Controller/ConversionApiController.php',
'OCA\\Files\\Controller\\DirectEditingController' => __DIR__ . '/..' . '/../lib/Controller/DirectEditingController.php',

4
apps/files/lib/AppInfo/Application.php

@ -13,6 +13,7 @@ use OCA\Files\AdvancedCapabilities;
use OCA\Files\Capabilities;
use OCA\Files\Collaboration\Resources\Listener;
use OCA\Files\Collaboration\Resources\ResourceProvider;
use OCA\Files\ConfigLexicon;
use OCA\Files\Controller\ApiController;
use OCA\Files\Dashboard\FavoriteWidget;
use OCA\Files\DirectEditingCapabilities;
@ -124,6 +125,9 @@ class Application extends App implements IBootstrap {
$context->registerNotifierService(Notifier::class);
$context->registerDashboardWidget(FavoriteWidget::class);
$context->registerConfigLexicon(ConfigLexicon::class);
}
public function boot(IBootContext $context): void {

46
apps/files/lib/ConfigLexicon.php

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files;
use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;
/**
* Config Lexicon for files.
*
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
*
* {@see ILexicon}
*/
class ConfigLexicon implements ILexicon {
public const OVERWRITES_HOME_FOLDERS = 'overwrites_home_folders';
public function getStrictness(): Strictness {
return Strictness::NOTICE;
}
public function getAppConfigs(): array {
return [
new Entry(
self::OVERWRITES_HOME_FOLDERS,
ValueType::ARRAY,
defaultRaw: [],
definition: 'List of applications overwriting home folders',
lazy: false,
note: 'It will be populated with app IDs of mount providers that overwrite home folders. Currently, only files_external and groupfolders.',
),
];
}
public function getUserConfigs(): array {
return [];
}
}

64
lib/private/Files/Node/LazyUserFolder.php

@ -19,38 +19,50 @@ use OCP\IUser;
use Psr\Log\LoggerInterface;
class LazyUserFolder extends LazyFolder {
private IUser $user;
private string $path;
private IMountManager $mountManager;
public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager $mountManager) {
$this->user = $user;
$this->mountManager = $mountManager;
public function __construct(
IRootFolder $rootFolder,
private IUser $user,
private IMountManager $mountManager,
bool $useDefaultHomeFoldersPermissions = true,
) {
$this->path = '/' . $user->getUID() . '/files';
parent::__construct($rootFolder, function () use ($user): Folder {
try {
$node = $this->getRootFolder()->get($this->path);
if ($node instanceof File) {
$e = new \RuntimeException();
\OCP\Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [
'exception' => $e,
]);
throw $e;
}
return $node;
} catch (NotFoundException $e) {
if (!$this->getRootFolder()->nodeExists('/' . $user->getUID())) {
$this->getRootFolder()->newFolder('/' . $user->getUID());
}
return $this->getRootFolder()->newFolder($this->path);
}
}, [
$data = [
'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,
]);
];
// By default, we assume the permissions for the users' home folders.
// If a mount point is mounted on a user's home folder, the permissions cannot be assumed.
if ($useDefaultHomeFoldersPermissions) {
// Sharing user root folder is not allowed
$data['permissions'] = Constants::PERMISSION_ALL ^ Constants::PERMISSION_SHARE;
}
parent::__construct(
$rootFolder,
function () use ($user): Folder {
try {
$node = $this->getRootFolder()->get($this->path);
if ($node instanceof File) {
$e = new \RuntimeException();
\OCP\Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [
'exception' => $e,
]);
throw $e;
}
return $node;
} catch (NotFoundException $e) {
if (!$this->getRootFolder()->nodeExists('/' . $user->getUID())) {
$this->getRootFolder()->newFolder('/' . $user->getUID());
}
return $this->getRootFolder()->newFolder($this->path);
}
},
$data,
);
}
public function getMountPoint() {

36
lib/private/Files/Node/Root.php

@ -14,6 +14,8 @@ use OC\Files\Utils\PathHelper;
use OC\Files\View;
use OC\Hooks\PublicEmitter;
use OC\User\NoUserException;
use OCA\Files\AppInfo\Application;
use OCA\Files\ConfigLexicon;
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
@ -24,6 +26,7 @@ use OCP\Files\Mount\IMountPoint;
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;
@ -51,43 +54,30 @@ use Psr\Log\LoggerInterface;
* @package OC\Files\Node
*/
class Root extends Folder implements IRootFolder {
private Manager $mountManager;
private PublicEmitter $emitter;
private ?IUser $user;
private CappedMemoryCache $userFolderCache;
private IUserMountCache $userMountCache;
private LoggerInterface $logger;
private IUserManager $userManager;
private IEventDispatcher $eventDispatcher;
private ICache $pathByIdCache;
private bool $useDefaultHomeFoldersPermissions = true;
/**
* @param Manager $manager
* @param View $view
* @param IUser|null $user
*/
public function __construct(
$manager,
$view,
$user,
IUserMountCache $userMountCache,
LoggerInterface $logger,
IUserManager $userManager,
private Manager $mountManager,
View $view,
private ?IUser $user,
private IUserMountCache $userMountCache,
private LoggerInterface $logger,
private IUserManager $userManager,
IEventDispatcher $eventDispatcher,
ICacheFactory $cacheFactory,
IAppConfig $appConfig,
) {
parent::__construct($this, $view, '');
$this->mountManager = $manager;
$this->user = $user;
$this->emitter = new PublicEmitter();
$this->userFolderCache = new CappedMemoryCache();
$this->userMountCache = $userMountCache;
$this->logger = $logger;
$this->userManager = $userManager;
$eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
$this->userFolderCache = new CappedMemoryCache();
});
$this->pathByIdCache = $cacheFactory->createLocal('path-by-id');
$this->useDefaultHomeFoldersPermissions = count($appConfig->getValueArray(Application::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS)) === 0;
}
/**
@ -367,7 +357,7 @@ class Root extends Folder implements IRootFolder {
$folder = $this->newFolder('/' . $userId . '/files');
}
} else {
$folder = new LazyUserFolder($this, $userObject, $this->mountManager);
$folder = new LazyUserFolder($this, $userObject, $this->mountManager, $this->useDefaultHomeFoldersPermissions);
}
$this->userFolderCache->set($userId, $folder);

1
lib/private/Server.php

@ -402,6 +402,7 @@ class Server extends ServerContainer implements IServerContainer {
$this->get(IUserManager::class),
$this->get(IEventDispatcher::class),
$this->get(ICacheFactory::class),
$this->get(IAppConfig::class),
);
$previewConnector = new \OC\Preview\WatcherConnector(

15
tests/lib/Files/Node/FileTest.php

@ -44,7 +44,7 @@ class FileTest extends NodeTestCase {
public function testGetContent(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
->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): void {
@ -74,7 +74,7 @@ class FileTest extends NodeTestCase {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
->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())
@ -93,7 +93,7 @@ class FileTest extends NodeTestCase {
public function testPutContent(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
->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())
@ -120,7 +120,7 @@ class FileTest extends NodeTestCase {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
->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())
@ -135,7 +135,7 @@ class FileTest extends NodeTestCase {
public function testGetMimeType(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
->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())
@ -161,6 +161,7 @@ class FileTest extends NodeTestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$hook = function ($file): void {
@ -198,6 +199,7 @@ class FileTest extends NodeTestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$hooksCalled = 0;
$hook = function ($file) use (&$hooksCalled): void {
@ -239,6 +241,7 @@ class FileTest extends NodeTestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
@ -266,6 +269,7 @@ class FileTest extends NodeTestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$hook = function (): void {
throw new \Exception('Hooks are not supposed to be called');
@ -293,6 +297,7 @@ class FileTest extends NodeTestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$hook = function (): void {
throw new \Exception('Hooks are not supposed to be called');

46
tests/lib/Files/Node/FolderTest.php

@ -76,7 +76,7 @@ class FolderTest extends NodeTestCase {
* @var 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')
@ -109,7 +109,7 @@ class FolderTest extends NodeTestCase {
$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')
@ -128,7 +128,7 @@ class FolderTest extends NodeTestCase {
$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')
@ -148,7 +148,7 @@ class FolderTest extends NodeTestCase {
$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')
@ -166,7 +166,7 @@ class FolderTest extends NodeTestCase {
$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')
@ -190,7 +190,7 @@ class FolderTest extends NodeTestCase {
$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')
@ -217,7 +217,7 @@ class FolderTest extends NodeTestCase {
$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);
@ -234,7 +234,7 @@ class FolderTest extends NodeTestCase {
$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')
@ -261,7 +261,7 @@ class FolderTest extends NodeTestCase {
$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);
@ -278,7 +278,7 @@ class FolderTest extends NodeTestCase {
$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);
@ -295,7 +295,7 @@ class FolderTest extends NodeTestCase {
$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);
@ -344,7 +344,7 @@ class FolderTest extends NodeTestCase {
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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')
@ -387,7 +387,7 @@ class FolderTest extends NodeTestCase {
$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);
@ -430,7 +430,7 @@ class FolderTest extends NodeTestCase {
$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')
@ -506,7 +506,7 @@ class FolderTest extends NodeTestCase {
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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(Storage::class);
$mount = new MountPoint($storage, '/bar');
@ -555,7 +555,7 @@ class FolderTest extends NodeTestCase {
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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(Storage::class);
$mount = new MountPoint($storage, '/bar');
@ -600,7 +600,7 @@ class FolderTest extends NodeTestCase {
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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(Storage::class);
$mount = new MountPoint($storage, '/bar');
@ -644,7 +644,7 @@ class FolderTest extends NodeTestCase {
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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(Storage::class);
$mount1 = new MountPoint($storage, '/bar');
@ -703,7 +703,7 @@ class FolderTest extends NodeTestCase {
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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())
@ -728,7 +728,7 @@ class FolderTest extends NodeTestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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|FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
@ -797,7 +797,7 @@ class FolderTest extends NodeTestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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|FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
@ -864,7 +864,7 @@ class FolderTest extends NodeTestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
->onlyMethods(['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|FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
@ -951,7 +951,7 @@ class FolderTest extends NodeTestCase {
$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')

2
tests/lib/Files/Node/HookConnectorTest.php

@ -32,6 +32,7 @@ use OCP\Files\Events\Node\NodeRenamedEvent;
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 OCP\Server;
@ -88,6 +89,7 @@ class HookConnectorTest extends TestCase {
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class),
$cacheFactory,
$this->createMock(IAppConfig::class),
);
$this->eventDispatcher = Server::get(IEventDispatcher::class);
$this->logger = Server::get(LoggerInterface::class);

2
tests/lib/Files/Node/IntegrationTest.php

@ -16,6 +16,7 @@ use OC\Memcache\ArrayCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountManager;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IUserManager;
use OCP\Server;
@ -72,6 +73,7 @@ class IntegrationTest extends \Test\TestCase {
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class),
$cacheFactory,
$this->createMock(IAppConfig::class),
);
$storage = new Temporary([]);
$subStorage = new Temporary([]);

39
tests/lib/Files/Node/NodeTestCase.php

@ -16,7 +16,6 @@ use OC\Files\Node\Root;
use OC\Files\Storage\Storage;
use OC\Files\View;
use OC\Memcache\ArrayCache;
use OC\User\User;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
@ -27,9 +26,11 @@ use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage\IStorage;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@ -38,24 +39,16 @@ use Psr\Log\LoggerInterface;
* @package Test\Files\Node
*/
abstract class NodeTestCase extends \Test\TestCase {
/** @var User */
protected $user;
/** @var \OC\Files\Mount\Manager */
protected $manager;
/** @var View|\PHPUnit\Framework\MockObject\MockObject */
protected $view;
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject */
protected $root;
/** @var IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */
protected $userMountCache;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
protected $userManager;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
protected $eventDispatcher;
/** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
protected $cacheFactory;
protected IUser&MockObject $user;
protected Manager&MockObject $manager;
protected View&MockObject $view;
protected Root&MockObject $root;
protected IUserMountCache&MockObject $userMountCache;
protected LoggerInterface&MockObject $logger;
protected IUserManager&MockObject $userManager;
protected IEventDispatcher&MockObject $eventDispatcher;
protected ICacheFactory&MockObject $cacheFactory;
protected IAppConfig&MockObject $appConfig;
protected function setUp(): void {
parent::setUp();
@ -81,8 +74,10 @@ abstract class NodeTestCase extends \Test\TestCase {
->willReturnCallback(function () {
return new ArrayCache();
});
$this->appConfig = $this->createMock(IAppConfig::class);
$this->root = $this->getMockBuilder(Root::class)
->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();
}
@ -194,6 +189,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->createMock(IAppConfig::class),
);
$root->listen('\OC\Files', 'preDelete', $preListener);
@ -443,6 +439,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->createMock(IAppConfig::class),
);
$root->listen('\OC\Files', 'preTouch', $preListener);
$root->listen('\OC\Files', 'postTouch', $postListener);
@ -619,7 +616,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName): void {
/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
->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])
->onlyMethods(['get'])
->getMock();

36
tests/lib/Files/Node/RootTest.php

@ -16,15 +16,16 @@ use OC\Files\Storage\Storage;
use OC\Files\View;
use OC\Memcache\ArrayCache;
use OC\User\NoUserException;
use OC\User\User;
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@ -33,20 +34,14 @@ use Psr\Log\LoggerInterface;
* @package Test\Files\Node
*/
class RootTest extends \Test\TestCase {
/** @var User */
private $user;
/** @var \OC\Files\Mount\Manager */
private $manager;
/** @var IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */
private $userMountCache;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger;
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
private $userManager;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $eventDispatcher;
/** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
protected $cacheFactory;
private IUser&MockObject $user;
private Manager&MockObject $manager;
private IUserMountCache&MockObject $userMountCache;
private LoggerInterface&MockObject $logger;
private IUserManager&MockObject $userManager;
private IEventDispatcher&MockObject $eventDispatcher;
protected ICacheFactory&MockObject $cacheFactory;
protected IAppConfig&MockObject $appConfig;
protected function setUp(): void {
parent::setUp();
@ -66,10 +61,11 @@ class RootTest extends \Test\TestCase {
->willReturnCallback(function () {
return new ArrayCache();
});
$this->appConfig = $this->createMock(IAppConfig::class);
}
/**
* @return View|\PHPUnit\Framework\MockObject\MockObject $view
* @return View&MockObject $view
*/
protected function getRootViewMock() {
$view = $this->createMock(View::class);
@ -100,6 +96,7 @@ class RootTest extends \Test\TestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$view->expects($this->once())
@ -133,6 +130,7 @@ class RootTest extends \Test\TestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$view->expects($this->once())
@ -158,6 +156,7 @@ class RootTest extends \Test\TestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$root->get('/../foo');
@ -177,6 +176,7 @@ class RootTest extends \Test\TestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$root->get('/bar/foo');
@ -192,6 +192,7 @@ class RootTest extends \Test\TestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$user = $this->createMock(IUser::class);
$user
@ -203,7 +204,7 @@ class RootTest extends \Test\TestCase {
->method('get')
->with('MyUserId')
->willReturn($user);
/** @var CappedMemoryCache|\PHPUnit\Framework\MockObject\MockObject $cappedMemoryCache */
/** @var CappedMemoryCache&MockObject $cappedMemoryCache */
$cappedMemoryCache = $this->createMock(CappedMemoryCache::class);
$cappedMemoryCache
->expects($this->once())
@ -234,6 +235,7 @@ class RootTest extends \Test\TestCase {
$this->userManager,
$this->eventDispatcher,
$this->cacheFactory,
$this->appConfig,
);
$this->userManager
->expects($this->once())

Loading…
Cancel
Save