aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-12-06 11:18:59 +0100
committerVincent Petry <vincent@nextcloud.com>2021-12-15 09:15:31 +0100
commitea302975526ba8fcb5abcca76daa6038439d053e (patch)
treef00714de6e983897719b98cb3c56ed5476156823 /apps/files_external/tests
parenta47da9722dfaec8d83e9c8543ed0c31138a909da (diff)
downloadnextcloud-server-ea302975526ba8fcb5abcca76daa6038439d053e.tar.gz
nextcloud-server-ea302975526ba8fcb5abcca76daa6038439d053e.zip
Add option to disallow creation of local storages
Introduce a new config option to prevent web UI admins to create or edit external storages of type "local". Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r--apps/files_external/tests/Controller/GlobalStoragesControllerTest.php19
-rw-r--r--apps/files_external/tests/Controller/StoragesControllerTest.php30
-rw-r--r--apps/files_external/tests/Controller/UserStoragesControllerTest.php20
3 files changed, 66 insertions, 3 deletions
diff --git a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
index f385b1f379e..0963cd06f00 100644
--- a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
@@ -28,6 +28,7 @@ namespace OCA\Files_External\Tests\Controller;
use OC\User\User;
use OCA\Files_External\Controller\GlobalStoragesController;
use OCA\Files_External\Service\BackendService;
+use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
@@ -38,6 +39,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class GlobalStoragesControllerTest extends StoragesControllerTest {
protected function setUp(): void {
parent::setUp();
+
$this->service = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService')
->disableOriginalConstructor()
->getMock();
@@ -45,11 +47,20 @@ class GlobalStoragesControllerTest extends StoragesControllerTest {
$this->service->method('getVisibilityType')
->willReturn(BackendService::VISIBILITY_ADMIN);
+ $this->controller = $this->createController(true);
+ }
+
+ private function createController($allowCreateLocal = true) {
$session = $this->createMock(IUserSession::class);
$session->method('getUser')
->willReturn(new User('test', null, $this->createMock(EventDispatcherInterface::class)));
- $this->controller = new GlobalStoragesController(
+ $config = $this->createMock(IConfig::class);
+ $config->method('getSystemValue')
+ ->with('files_external_allow_create_new_local', true)
+ ->willReturn($allowCreateLocal);
+
+ return new GlobalStoragesController(
'files_external',
$this->createMock(IRequest::class),
$this->createMock(IL10N::class),
@@ -57,6 +68,12 @@ class GlobalStoragesControllerTest extends StoragesControllerTest {
$this->createMock(ILogger::class),
$session,
$this->createMock(IGroupManager::class),
+ $config
);
}
+
+ public function testAddLocalStorageWhenDisabled() {
+ $this->controller = $this->createController(false);
+ parent::testAddLocalStorageWhenDisabled();
+ }
}
diff --git a/apps/files_external/tests/Controller/StoragesControllerTest.php b/apps/files_external/tests/Controller/StoragesControllerTest.php
index 7dc2d287b43..bb9be2f2d4a 100644
--- a/apps/files_external/tests/Controller/StoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/StoragesControllerTest.php
@@ -130,6 +130,36 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals($storageConfig, $data);
}
+ public function testAddLocalStorageWhenDisabled() {
+ $authMech = $this->getAuthMechMock();
+ $backend = $this->getBackendMock();
+
+ $storageConfig = new StorageConfig(1);
+ $storageConfig->setMountPoint('mount');
+ $storageConfig->setBackend($backend);
+ $storageConfig->setAuthMechanism($authMech);
+ $storageConfig->setBackendOptions([]);
+
+ $this->service->expects($this->never())
+ ->method('createStorage');
+ $this->service->expects($this->never())
+ ->method('addStorage');
+
+ $response = $this->controller->create(
+ 'mount',
+ 'local',
+ '\OCA\Files_External\Lib\Auth\NullMechanism',
+ [],
+ [],
+ [],
+ [],
+ null
+ );
+
+ $data = $response->getData();
+ $this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus());
+ }
+
public function testUpdateStorage() {
$authMech = $this->getAuthMechMock();
$authMech->method('validateStorage')
diff --git a/apps/files_external/tests/Controller/UserStoragesControllerTest.php b/apps/files_external/tests/Controller/UserStoragesControllerTest.php
index c9e4ec5f985..f4de39fcd2b 100644
--- a/apps/files_external/tests/Controller/UserStoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/UserStoragesControllerTest.php
@@ -31,6 +31,7 @@ use OCA\Files_External\Controller\UserStoragesController;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\BackendService;
use OCP\AppFramework\Http;
+use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
@@ -54,21 +55,36 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$this->service->method('getVisibilityType')
->willReturn(BackendService::VISIBILITY_PERSONAL);
+ $this->controller = $this->createController(true);
+ }
+
+ private function createController($allowCreateLocal = true) {
$session = $this->createMock(IUserSession::class);
$session->method('getUser')
->willReturn(new User('test', null, $this->createMock(EventDispatcherInterface::class)));
- $this->controller = new UserStoragesController(
+ $config = $this->createMock(IConfig::class);
+ $config->method('getSystemValue')
+ ->with('files_external_allow_create_new_local', true)
+ ->willReturn($allowCreateLocal);
+
+ return new UserStoragesController(
'files_external',
$this->createMock(IRequest::class),
$this->createMock(IL10N::class),
$this->service,
$this->createMock(ILogger::class),
$session,
- $this->createMock(IGroupManager::class)
+ $this->createMock(IGroupManager::class),
+ $config
);
}
+ public function testAddLocalStorageWhenDisabled() {
+ $this->controller = $this->createController(false);
+ parent::testAddLocalStorageWhenDisabled();
+ }
+
public function testAddOrUpdateStorageDisallowedBackend() {
$backend = $this->getBackendMock();
$backend->method('isVisibleFor')