diff options
author | Robin Appelman <robin@icewind.nl> | 2022-03-04 13:44:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-04 13:44:05 +0000 |
commit | 8b22a463e9b16282860991004430ba54e5e75dbc (patch) | |
tree | f7f66797543781441097697c7aef7b1245e0d206 /tests | |
parent | 821a0dc87594c717e785027b81134bf8783913c9 (diff) | |
parent | ec15020777c9f0de248ced8b83fe48767c2919b6 (diff) | |
download | nextcloud-server-8b22a463e9b16282860991004430ba54e5e75dbc.tar.gz nextcloud-server-8b22a463e9b16282860991004430ba54e5e75dbc.zip |
Merge pull request #31266 from nextcloud/root-setup-mountprovider
move root mount setup to mountproviders
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Files/Mount/RootMountProviderTest.php | 141 | ||||
-rw-r--r-- | tests/lib/User/UserTest.php | 12 |
2 files changed, 153 insertions, 0 deletions
diff --git a/tests/lib/Files/Mount/RootMountProviderTest.php b/tests/lib/Files/Mount/RootMountProviderTest.php new file mode 100644 index 00000000000..e5eaabf93be --- /dev/null +++ b/tests/lib/Files/Mount/RootMountProviderTest.php @@ -0,0 +1,141 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Files\Mount; + +use OC\Files\Mount\RootMountProvider; +use OC\Files\ObjectStore\ObjectStoreStorage; +use OC\Files\ObjectStore\S3; +use OC\Files\Storage\LocalRootStorage; +use OC\Files\Storage\StorageFactory; +use OCP\IConfig; +use Psr\Log\LoggerInterface; +use Test\TestCase; + +/** + * @group DB + */ +class RootMountProviderTest extends TestCase { + private StorageFactory $loader; + + protected function setUp(): void { + parent::setUp(); + + $this->loader = new StorageFactory(); + } + + private function getConfig(array $systemConfig): IConfig { + $config = $this->createMock(IConfig::class); + $config->method('getSystemValue') + ->willReturnCallback(function (string $key, $default) use ($systemConfig) { + return $systemConfig[$key] ?? $default; + }); + return $config; + } + + private function getProvider(array $systemConfig): RootMountProvider { + $config = $this->getConfig($systemConfig); + $provider = new RootMountProvider($config, $this->createMock(LoggerInterface::class)); + return $provider; + } + + public function testLocal() { + $provider = $this->getProvider([ + 'datadirectory' => '/data', + ]); + $mounts = $provider->getRootMounts($this->loader); + $this->assertCount(1, $mounts); + $mount = $mounts[0]; + $this->assertEquals('/', $mount->getMountPoint()); + /** @var LocalRootStorage $storage */ + $storage = $mount->getStorage(); + $this->assertInstanceOf(LocalRootStorage::class, $storage); + $this->assertEquals('/data/', $storage->getSourcePath('')); + } + + public function testObjectStore() { + $provider = $this->getProvider([ + 'objectstore' => [ + "class" => "OC\Files\ObjectStore\S3", + "arguments" => [ + "bucket" => "nextcloud", + "autocreate" => true, + "key" => "minio", + "secret" => "minio123", + "hostname" => "localhost", + "port" => 9000, + "use_ssl" => false, + "use_path_style" => true, + "uploadPartSize" => 52428800, + ], + ], + ]); + $mounts = $provider->getRootMounts($this->loader); + $this->assertCount(1, $mounts); + $mount = $mounts[0]; + $this->assertEquals('/', $mount->getMountPoint()); + /** @var ObjectStoreStorage $storage */ + $storage = $mount->getStorage(); + $this->assertInstanceOf(ObjectStoreStorage::class, $storage); + + $class = new \ReflectionClass($storage); + $prop = $class->getProperty('objectStore'); + $prop->setAccessible(true); + /** @var S3 $objectStore */ + $objectStore = $prop->getValue($storage); + $this->assertEquals('nextcloud', $objectStore->getBucket()); + } + + public function testObjectStoreMultiBucket() { + $provider = $this->getProvider([ + 'objectstore_multibucket' => [ + "class" => "OC\Files\ObjectStore\S3", + "arguments" => [ + "bucket" => "nextcloud", + "autocreate" => true, + "key" => "minio", + "secret" => "minio123", + "hostname" => "localhost", + "port" => 9000, + "use_ssl" => false, + "use_path_style" => true, + "uploadPartSize" => 52428800, + ], + ], + ]); + $mounts = $provider->getRootMounts($this->loader); + $this->assertCount(1, $mounts); + $mount = $mounts[0]; + $this->assertEquals('/', $mount->getMountPoint()); + /** @var ObjectStoreStorage $storage */ + $storage = $mount->getStorage(); + $this->assertInstanceOf(ObjectStoreStorage::class, $storage); + + $class = new \ReflectionClass($storage); + $prop = $class->getProperty('objectStore'); + $prop->setAccessible(true); + /** @var S3 $objectStore */ + $objectStore = $prop->getValue($storage); + $this->assertEquals('nextcloud0', $objectStore->getBucket()); + } +} diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index aa56959d3cb..7fab7ececca 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -10,9 +10,11 @@ namespace Test\User; use OC\AllConfig; +use OC\Files\Mount\ObjectHomeMountProvider; use OC\Hooks\PublicEmitter; use OC\User\User; use OCP\Comments\ICommentsManager; +use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; use OCP\IUser; use OCP\Notification\IManager as INotificationManager; @@ -214,6 +216,16 @@ class UserTest extends TestCase { } public function testDeleteWithDifferentHome() { + + /** @var ObjectHomeMountProvider $homeProvider */ + $homeProvider = \OC::$server->get(ObjectHomeMountProvider::class); + $user = $this->createMock(IUser::class); + $user->method('getUID') + ->willReturn('foo'); + if ($homeProvider->getHomeMountForUser($user, $this->createMock(IStorageFactory::class)) !== null) { + $this->markTestSkipped("Skipping test for non local home storage"); + } + /** * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend */ |