diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-11-03 12:14:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-03 12:14:28 +0100 |
commit | b33ceb6fdd7a9458ba2d8730b401271eb640822d (patch) | |
tree | 88773bb64938ddbc2dd7f41ca883b20781116544 | |
parent | e11197bc4872f2ada4740736969f4c96e24ea229 (diff) | |
parent | 6920e609c02814d03a5dc83792de12d05f1da854 (diff) | |
download | nextcloud-server-b33ceb6fdd7a9458ba2d8730b401271eb640822d.tar.gz nextcloud-server-b33ceb6fdd7a9458ba2d8730b401271eb640822d.zip |
Merge pull request #1915 from nextcloud/downstream-26398
Add using casing check/fix for initMountPoints
-rw-r--r-- | apps/files/lib/Command/TransferOwnership.php | 14 | ||||
-rw-r--r-- | lib/private/Files/Filesystem.php | 14 | ||||
-rw-r--r-- | lib/private/Files/Node/Root.php | 59 | ||||
-rw-r--r-- | lib/private/Server.php | 9 | ||||
-rw-r--r-- | lib/private/Share/Share.php | 29 | ||||
-rw-r--r-- | lib/public/Share.php | 10 | ||||
-rw-r--r-- | tests/lib/AvatarManagerTest.php | 26 | ||||
-rw-r--r-- | tests/lib/Files/FilesystemTest.php | 33 | ||||
-rw-r--r-- | tests/lib/Files/Node/FileTest.php | 100 | ||||
-rw-r--r-- | tests/lib/Files/Node/FolderTest.php | 125 | ||||
-rw-r--r-- | tests/lib/Files/Node/HookConnectorTest.php | 6 | ||||
-rw-r--r-- | tests/lib/Files/Node/IntegrationTest.php | 11 | ||||
-rw-r--r-- | tests/lib/Files/Node/NodeTest.php | 24 | ||||
-rw-r--r-- | tests/lib/Files/Node/RootTest.php | 123 | ||||
-rw-r--r-- | tests/lib/Share/ShareTest.php | 28 |
15 files changed, 498 insertions, 113 deletions
diff --git a/apps/files/lib/Command/TransferOwnership.php b/apps/files/lib/Command/TransferOwnership.php index 742948b7ac3..3b51e4a9e6d 100644 --- a/apps/files/lib/Command/TransferOwnership.php +++ b/apps/files/lib/Command/TransferOwnership.php @@ -91,23 +91,21 @@ class TransferOwnership extends Command { } protected function execute(InputInterface $input, OutputInterface $output) { - $this->sourceUser = $input->getArgument('source-user'); - $this->destinationUser = $input->getArgument('destination-user'); - $source = $this->userManager->get($this->sourceUser); - $destination = $this->userManager->get($this->destinationUser); + $sourceUserObject = $this->userManager->get($input->getArgument('source-user')); + $destinationUserObject = $this->userManager->get($input->getArgument('destination-user')); - if (!$source instanceof IUser) { + if (!$sourceUserObject instanceof IUser) { $output->writeln("<error>Unknown source user $this->sourceUser</error>"); return; } - if (!$destination instanceof IUser) { + if (!$destinationUserObject instanceof IUser) { $output->writeln("<error>Unknown destination user $this->destinationUser</error>"); return; } - $this->sourceUser = $source->getUID(); - $this->destinationUser = $destination->getUID(); + $this->sourceUser = $sourceUserObject->getUID(); + $this->destinationUser = $destinationUserObject->getUID(); // target user has to be ready if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) { diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index 113bb5a85c6..d2662af527a 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -394,9 +394,6 @@ class Filesystem { if ($user === null || $user === false || $user === '') { throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session'); } - if (isset(self::$usersSetup[$user])) { - return; - } $userManager = \OC::$server->getUserManager(); $userObject = $userManager->get($user); @@ -406,6 +403,17 @@ class Filesystem { throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); } + // workaround in case of different casings + if ($user !== $userObject->getUID()) { + $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50)); + \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $userObject->getUID() . '" got "' . $user . '". Stack: ' . $stack, \OCP\Util::WARN); + } + $user = $userObject->getUID(); + + if (isset(self::$usersSetup[$user])) { + return; + } + self::$usersSetup[$user] = true; /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */ diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 0cda2c8b822..515a795d6e0 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -36,6 +36,8 @@ use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OC\Hooks\PublicEmitter; use OCP\Files\IRootFolder; +use OCP\ILogger; +use OCP\IUserManager; /** * Class Root @@ -57,42 +59,43 @@ use OCP\Files\IRootFolder; * @package OC\Files\Node */ class Root extends Folder implements IRootFolder { - - /** - * @var \OC\Files\Mount\Manager $mountManager - */ + /** @var Manager */ private $mountManager; - - /** - * @var \OC\Hooks\PublicEmitter - */ + /** @var PublicEmitter */ private $emitter; - - /** - * @var \OC\User\User $user - */ + /** @var null|\OC\User\User */ private $user; - + /** @var CappedMemoryCache */ private $userFolderCache; - - /** - * @var IUserMountCache - */ + /** @var IUserMountCache */ private $userMountCache; + /** @var ILogger */ + private $logger; + /** @var IUserManager */ + private $userManager; /** * @param \OC\Files\Mount\Manager $manager * @param \OC\Files\View $view * @param \OC\User\User|null $user * @param IUserMountCache $userMountCache - */ - public function __construct($manager, $view, $user, IUserMountCache $userMountCache) { + * @param ILogger $logger + * @param IUserManager $userManager + */ + public function __construct($manager, + $view, + $user, + IUserMountCache $userMountCache, + ILogger $logger, + IUserManager $userManager) { 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; } /** @@ -345,8 +348,26 @@ class Root extends Folder implements IRootFolder { * * @param String $userId user ID * @return \OCP\Files\Folder + * @throws \OC\User\NoUserException */ public function getUserFolder($userId) { + $userObject = $this->userManager->get($userId); + + if (is_null($userObject)) { + $this->logger->error( + sprintf( + 'Backends provided no user object for %s', + $userId + ), + [ + 'app' => 'files', + ] + ); + throw new \OC\User\NoUserException('Backends provided no user object'); + } + + $userId = $userObject->getUID(); + if (!$this->userFolderCache->hasKey($userId)) { \OC\Files\Filesystem::initMountPoints($userId); diff --git a/lib/private/Server.php b/lib/private/Server.php index dca50c15733..9f993ade7fe 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -182,7 +182,14 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService('RootFolder', function (Server $c) { $manager = \OC\Files\Filesystem::getMountManager(null); $view = new View(); - $root = new Root($manager, $view, null, $c->getUserMountCache()); + $root = new Root( + $manager, + $view, + null, + $c->getUserMountCache(), + $this->getLogger(), + $this->getUserManager() + ); $connector = new HookConnector($root, $view); $connector->viewToNode(); return $root; diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 33801cd6347..f6da19f3bb8 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -45,6 +45,8 @@ namespace OC\Share; use OC\Files\Filesystem; use OCA\FederatedFileSharing\DiscoveryManager; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\ILogger; +use OCP\IUserManager; use OCP\IUserSession; use OCP\IDBConnection; use OCP\IConfig; @@ -128,14 +130,39 @@ class Share extends Constants { * Find which users can access a shared item * @param string $path to the file * @param string $ownerUser owner of the file + * @param IUserManager $userManager + * @param ILogger $logger * @param boolean $includeOwner include owner to the list of users with access to the file * @param boolean $returnUserPaths Return an array with the user => path map * @param boolean $recursive take all parent folders into account (default true) * @return array * @note $path needs to be relative to user data dir, e.g. 'file.txt' * not '/admin/data/file.txt' + * @throws \OC\User\NoUserException */ - public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) { + public static function getUsersSharingFile($path, + $ownerUser, + IUserManager $userManager, + ILogger $logger, + $includeOwner = false, + $returnUserPaths = false, + $recursive = true) { + $userObject = $userManager->get($ownerUser); + + if (is_null($userObject)) { + $logger->error( + sprintf( + 'Backends provided no user object for %s', + $ownerUser + ), + [ + 'app' => 'files', + ] + ); + throw new \OC\User\NoUserException('Backends provided no user object'); + } + + $ownerUser = $userObject->getUID(); Filesystem::initMountPoints($ownerUser); $shares = $sharePaths = $fileTargets = array(); diff --git a/lib/public/Share.php b/lib/public/Share.php index bc7aa828f62..ec3a7c8db1b 100644 --- a/lib/public/Share.php +++ b/lib/public/Share.php @@ -89,7 +89,15 @@ class Share extends \OC\Share\Constants { * @since 5.0.0 - $recursive was added in 9.0.0 */ public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) { - return \OC\Share\Share::getUsersSharingFile($path, $ownerUser, $includeOwner, $returnUserPaths, $recursive); + return \OC\Share\Share::getUsersSharingFile( + $path, + $ownerUser, + \OC::$server->getUserManager(), + \OC::$server->getLogger(), + $includeOwner, + $returnUserPaths, + $recursive + ); } /** diff --git a/tests/lib/AvatarManagerTest.php b/tests/lib/AvatarManagerTest.php index 8ccc51d12e0..83a5cfd9b30 100644 --- a/tests/lib/AvatarManagerTest.php +++ b/tests/lib/AvatarManagerTest.php @@ -26,6 +26,7 @@ namespace Test; use OC\Avatar; use OC\AvatarManager; +use OC\Files\AppData\AppData; use OCP\Files\IAppData; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; @@ -48,7 +49,7 @@ class AvatarManagerTest extends \Test\TestCase { private $logger; /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; - /** @var AvatarManager */ + /** @var AvatarManager | \PHPUnit_Framework_MockObject_MockObject */ private $avatarManager; public function setUp() { @@ -101,8 +102,29 @@ class AvatarManagerTest extends \Test\TestCase { ->with('valid-user') ->willReturn($folder); - $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);; + $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config); $this->assertEquals($expected, $this->avatarManager->getAvatar('valid-user')); } + public function testGetAvatarValidUserDifferentCasing() { + $user = $this->createMock(IUser::class); + $this->userManager->expects($this->once()) + ->method('get') + ->with('vaLid-USER') + ->willReturn($user); + + $user->expects($this->once()) + ->method('getUID') + ->willReturn('valid-user'); + + $folder = $this->createMock(ISimpleFolder::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('valid-user') + ->willReturn($folder); + + $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config); + $this->assertEquals($expected, $this->avatarManager->getAvatar('vaLid-USER')); + } } diff --git a/tests/lib/Files/FilesystemTest.php b/tests/lib/Files/FilesystemTest.php index 210ce4edc69..dd4785ecf09 100644 --- a/tests/lib/Files/FilesystemTest.php +++ b/tests/lib/Files/FilesystemTest.php @@ -368,6 +368,39 @@ class FilesystemTest extends \Test\TestCase { $this->assertEquals(2, $thrown); } + public function testUserNameCasing() { + $this->logout(); + $userId = $this->getUniqueID('user_'); + + \OC_User::clearBackends(); + // needed for loginName2UserName mapping + $userBackend = $this->createMock(\OC\User\Database::class); + \OC::$server->getUserManager()->registerBackend($userBackend); + + $userBackend->expects($this->once()) + ->method('userExists') + ->with(strtoupper($userId)) + ->will($this->returnValue(true)); + $userBackend->expects($this->once()) + ->method('loginName2UserName') + ->with(strtoupper($userId)) + ->will($this->returnValue($userId)); + + $view = new \OC\Files\View(); + $this->assertFalse($view->file_exists('/' . $userId)); + + \OC\Files\Filesystem::initMountPoints(strtoupper($userId)); + + list($storage1, $path1) = $view->resolvePath('/' . $userId); + list($storage2, $path2) = $view->resolvePath('/' . strtoupper($userId)); + + $this->assertTrue($storage1->instanceOfStorage('\OCP\Files\IHomeStorage')); + $this->assertEquals('', $path1); + + // not mounted, still on the local root storage + $this->assertEquals(strtoupper($userId), $path2); + } + /** * Tests that the home storage is used for the user's mount point */ diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index b7a2fa2a1a3..823e3b50249 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -10,19 +10,22 @@ namespace Test\Files\Node; use OC\Files\FileInfo; use OCP\Files\NotFoundException; +use OCP\ILogger; +use OCP\IUserManager; class FileTest extends \Test\TestCase { /** @var \OC\User\User */ private $user; - /** @var \OC\Files\Mount\Manager */ private $manager; - /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */ private $view; - /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ private $userMountCache; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; protected function setUp() { parent::setUp(); @@ -30,7 +33,6 @@ class FileTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config); - $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') ->disableOriginalConstructor() ->getMock(); @@ -40,6 +42,8 @@ class FileTest extends \Test\TestCase { $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->createMock(ILogger::class); + $this->userManager = $this->createMock(IUserManager::class); } protected function getMockStorage() { @@ -58,7 +62,7 @@ class FileTest extends \Test\TestCase { public function testDelete() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->exactly(2)) @@ -108,7 +112,14 @@ class FileTest extends \Test\TestCase { $hooksRun++; }; - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'postDelete', $postListener); @@ -138,7 +149,7 @@ class FileTest extends \Test\TestCase { public function testDeleteNotPermitted() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) @@ -157,7 +168,7 @@ class FileTest extends \Test\TestCase { public function testGetContent() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $hook = function ($file) { @@ -187,7 +198,7 @@ class FileTest extends \Test\TestCase { public function testGetContentNotPermitted() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) @@ -206,7 +217,7 @@ class FileTest extends \Test\TestCase { public function testPutContent() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) @@ -233,7 +244,7 @@ class FileTest extends \Test\TestCase { public function testPutContentNotPermitted() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->once()) @@ -248,7 +259,7 @@ class FileTest extends \Test\TestCase { public function testGetMimeType() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->once()) @@ -265,7 +276,14 @@ class FileTest extends \Test\TestCase { fwrite($stream, 'bar'); rewind($stream); - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hook = function ($file) { throw new \Exception('Hooks are not supposed to be called'); @@ -293,8 +311,14 @@ class FileTest extends \Test\TestCase { public function testFOpenWrite() { $stream = fopen('php://memory', 'w+'); - $root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user, $this->userMountCache); - + $root = new \OC\Files\Node\Root( + $this->manager, + new $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hooksCalled = 0; $hook = function ($file) use (&$hooksCalled) { $hooksCalled++; @@ -326,8 +350,14 @@ class FileTest extends \Test\TestCase { * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadNotPermitted() { - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); - + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hook = function ($file) { throw new \Exception('Hooks are not supposed to be called'); }; @@ -345,8 +375,14 @@ class FileTest extends \Test\TestCase { * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadWriteNoReadPermissions() { - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); - + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); }; @@ -364,8 +400,14 @@ class FileTest extends \Test\TestCase { * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadWriteNoWritePermissions() { - $root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user, $this->userMountCache); - + $root = new \OC\Files\Node\Root( + $this->manager, + new $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); }; @@ -382,7 +424,7 @@ class FileTest extends \Test\TestCase { public function testCopySameStorage() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->any()) @@ -415,7 +457,7 @@ class FileTest extends \Test\TestCase { public function testCopyNotPermitted() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); /** @@ -453,7 +495,7 @@ class FileTest extends \Test\TestCase { public function testCopyNoParent() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->never()) @@ -475,7 +517,7 @@ class FileTest extends \Test\TestCase { public function testCopyParentIsFile() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->never()) @@ -496,7 +538,7 @@ class FileTest extends \Test\TestCase { public function testMoveSameStorage() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->any()) @@ -526,7 +568,7 @@ class FileTest extends \Test\TestCase { public function testMoveNotPermitted() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->any()) @@ -553,7 +595,7 @@ class FileTest extends \Test\TestCase { public function testMoveNoParent() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); /** @@ -583,7 +625,7 @@ class FileTest extends \Test\TestCase { public function testMoveParentIsFile() { /** @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]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->never()) diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index e592013eb6a..dcfe6a1768c 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -18,11 +18,13 @@ use OC\Files\Node\Node; use OC\Files\Node\Root; use OC\Files\Storage\Temporary; use OC\Files\Storage\Wrapper\Jail; +use OC\User\User; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; -use OCP\Files\NotPermittedException; use OC\Files\View; use OCP\Files\Storage; +use OCP\ILogger; +use OCP\IUserManager; /** * Class FolderTest @@ -32,10 +34,14 @@ use OCP\Files\Storage; * @package Test\Files\Node */ class FolderTest extends \Test\TestCase { + /** @var User */ private $user; - /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ private $userMountCache; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; protected function setUp() { parent::setUp(); @@ -43,6 +49,8 @@ class FolderTest extends \Test\TestCase { $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->createMock(ILogger::class); + $this->userManager = $this->createMock(IUserManager::class); } protected function getMockStorage() { @@ -64,7 +72,7 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -118,7 +126,14 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = new \OC\Files\Node\Root($manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'postDelete', $postListener); @@ -150,7 +165,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -171,7 +188,7 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -202,7 +219,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -221,7 +240,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -243,7 +264,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -263,7 +286,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -293,7 +318,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -313,7 +340,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -343,7 +372,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -363,7 +394,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -383,7 +416,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -431,8 +466,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -480,7 +517,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -528,7 +567,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -576,7 +617,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -656,8 +699,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock(); @@ -707,8 +752,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock(); @@ -757,8 +804,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount1 = new MountPoint($storage, '/bar'); $mount2 = new MountPoint($storage, '/bar/foo/asd'); @@ -837,8 +886,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $view->expects($this->any()) ->method('file_exists') @@ -863,8 +914,10 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); /** @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])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') ->disableOriginalConstructor()->getMock(); @@ -922,8 +975,10 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); /** @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])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') ->disableOriginalConstructor()->getMock(); @@ -979,8 +1034,10 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); /** @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])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') ->disableOriginalConstructor()->getMock(); diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 013fcabf222..765bb647a1a 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -13,6 +13,8 @@ use OC\Files\Node\Root; use OC\Files\Storage\Temporary; use OC\Files\View; use OCP\Files\Node; +use OCP\ILogger; +use OCP\IUserManager; use Test\TestCase; use Test\Traits\MountProviderTrait; use Test\Traits\UserTrait; @@ -54,7 +56,9 @@ class HookConnectorTest extends TestCase { Filesystem::getMountManager(), $this->view, \OC::$server->getUserManager()->get($this->userId), - \OC::$server->getUserMountCache() + \OC::$server->getUserMountCache(), + $this->createMock(ILogger::class), + $this->createMock(IUserManager::class) ); } diff --git a/tests/lib/Files/Node/IntegrationTest.php b/tests/lib/Files/Node/IntegrationTest.php index da753f833c2..b5cd832d1dd 100644 --- a/tests/lib/Files/Node/IntegrationTest.php +++ b/tests/lib/Files/Node/IntegrationTest.php @@ -12,6 +12,8 @@ use OC\Files\Node\Root; use OC\Files\Storage\Temporary; use OC\Files\View; use OC\User\User; +use OCP\ILogger; +use OCP\IUserManager; /** * Class IntegrationTest @@ -47,7 +49,14 @@ class IntegrationTest extends \Test\TestCase { $this->loginAsUser($user->getUID()); $this->view = new View(); - $this->root = new Root($manager, $this->view, $user, \OC::$server->getUserMountCache()); + $this->root = new Root( + $manager, + $this->view, + $user, + \OC::$server->getUserMountCache(), + $this->createMock(ILogger::class), + $this->createMock(IUserManager::class) + ); $storage = new Temporary(array()); $subStorage = new Temporary(array()); $this->storages[] = $storage; diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index b7e2f336a60..1a3a0472e97 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -9,21 +9,24 @@ namespace Test\Files\Node; use OC\Files\FileInfo; +use OCP\ILogger; +use OCP\IUserManager; class NodeTest extends \Test\TestCase { /** @var \OC\User\User */ private $user; - /** @var \OC\Files\Mount\Manager */ private $manager; - /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */ private $view; - /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject */ private $root; /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ private $userMountCache; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; protected function setUp() { parent::setUp(); @@ -34,9 +37,7 @@ class NodeTest extends \Test\TestCase { $urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') ->disableOriginalConstructor() ->getMock(); - $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlGenerator); - $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') ->disableOriginalConstructor() ->getMock(); @@ -46,8 +47,10 @@ class NodeTest extends \Test\TestCase { $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->createMock(ILogger::class); + $this->userManager = $this->createMock(IUserManager::class); $this->root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); } @@ -273,7 +276,14 @@ class NodeTest extends \Test\TestCase { $hooksRun++; }; - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->listen('\OC\Files', 'preTouch', $preListener); $root->listen('\OC\Files', 'postTouch', $postListener); diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index f42a42c42b1..fbc33cafcd8 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -8,16 +8,31 @@ namespace Test\Files\Node; +use OC\Cache\CappedMemoryCache; use OC\Files\FileInfo; +use OC\Files\Mount\Manager; +use OC\Files\Node\Folder; +use OC\Files\View; +use OCP\ILogger; +use OCP\IUser; +use OCP\IUserManager; +/** + * Class RootTest + * + * @package Test\Files\Node + */ class RootTest extends \Test\TestCase { /** @var \OC\User\User */ private $user; - /** @var \OC\Files\Mount\Manager */ private $manager; /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ private $userMountCache; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; protected function setUp() { parent::setUp(); @@ -30,13 +45,14 @@ class RootTest extends \Test\TestCase { ->getMock(); $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlgenerator); - $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') ->disableOriginalConstructor() ->getMock(); $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->createMock(ILogger::class); + $this->userManager = $this->createMock(IUserManager::class); } protected function getFileInfo($data) { @@ -56,7 +72,14 @@ class RootTest extends \Test\TestCase { $view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); - $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $view->expects($this->once()) ->method('getFileInfo') @@ -85,7 +108,14 @@ class RootTest extends \Test\TestCase { $view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); - $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $view->expects($this->once()) ->method('getFileInfo') @@ -106,7 +136,14 @@ class RootTest extends \Test\TestCase { $view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); - $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->get('/../foo'); } @@ -121,8 +158,82 @@ class RootTest extends \Test\TestCase { $view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); - $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->get('/bar/foo'); } + + public function testGetUserFolder() { + $root = new \OC\Files\Node\Root( + $this->manager, + $this->createMock(View::class), + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); + $user = $this->createMock(IUser::class); + $user + ->expects($this->once()) + ->method('getUID') + ->willReturn('MyUserId'); + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('MyUserId') + ->willReturn($user); + /** @var CappedMemoryCache|\PHPUnit_Framework_MockObject_MockObject $cappedMemoryCache */ + $cappedMemoryCache = $this->createMock(CappedMemoryCache::class); + $cappedMemoryCache + ->expects($this->once()) + ->method('hasKey') + ->willReturn(true); + $folder = $this->createMock(Folder::class); + $cappedMemoryCache + ->expects($this->once()) + ->method('get') + ->with('MyUserId') + ->willReturn($folder); + + $this->invokePrivate($root, 'userFolderCache', [$cappedMemoryCache]); + $this->assertEquals($folder, $root->getUserFolder('MyUserId')); + } + + /** + * @expectedException \OC\User\NoUserException + * @expectedExceptionMessage Backends provided no user object + */ + public function testGetUserFolderWithNoUserObj() { + $root = new \OC\Files\Node\Root( + $this->createMock(Manager::class), + $this->createMock(View::class), + null, + $this->userMountCache, + $this->logger, + $this->userManager + ); + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('NotExistingUser') + ->willReturn(null); + $this->logger + ->expects($this->once()) + ->method('error') + ->with( + 'Backends provided no user object for NotExistingUser', + [ + 'app' => 'files', + ] + ); + + $root->getUserFolder('NotExistingUser'); + } } diff --git a/tests/lib/Share/ShareTest.php b/tests/lib/Share/ShareTest.php index 63289529843..d550ba158a9 100644 --- a/tests/lib/Share/ShareTest.php +++ b/tests/lib/Share/ShareTest.php @@ -20,6 +20,9 @@ */ namespace Test\Share; +use OC\Share\Share; +use OCP\ILogger; +use OCP\IUserManager; /** * Class Test_Share @@ -1631,6 +1634,31 @@ class ShareTest extends \Test\TestCase { $this->assertEquals('Sharing failed, because the user ' . $this->user1 . ' is the original sharer', $e->getMessage()); } } + + /** + * @expectedException \OC\User\NoUserException + * @expectedExceptionMessage Backends provided no user object + */ + public function testGetUsersSharingFileWithException() { + $userManager = $this->createMock(IUserManager::class); + $logger = $this->createMock(ILogger::class); + $userManager + ->expects($this->once()) + ->method('get') + ->with('test') + ->willReturn(null); + $logger + ->expects($this->once()) + ->method('error') + ->with( + 'Backends provided no user object for test', + [ + 'app' => 'files', + ] + ); + + Share::getUsersSharingFile('/my/file/path', 'test', $userManager, $logger); + } } class DummyShareClass extends \OC\Share\Share { |