2014-10-31 06:41:07 -04:00
|
|
|
<?php
|
2025-05-17 05:46:26 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2014-10-31 06:41:07 -04:00
|
|
|
/**
|
2024-06-06 03:55:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-10-31 06:41:07 -04:00
|
|
|
*/
|
2016-05-13 05:22:28 -04:00
|
|
|
namespace OCA\Files_External\Tests\Controller;
|
2014-10-31 06:41:07 -04:00
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Files_External\Controller\GlobalStoragesController;
|
2025-05-17 05:46:26 -04:00
|
|
|
use OCA\Files_External\Controller\UserStoragesController;
|
2017-10-24 09:26:53 -04:00
|
|
|
use OCA\Files_External\Lib\Auth\AuthMechanism;
|
2025-05-17 05:46:26 -04:00
|
|
|
use OCA\Files_External\Lib\Auth\NullMechanism;
|
2017-10-24 09:26:53 -04:00
|
|
|
use OCA\Files_External\Lib\Backend\Backend;
|
2025-05-17 05:46:26 -04:00
|
|
|
use OCA\Files_External\Lib\Backend\SMB;
|
2016-05-13 05:56:47 -04:00
|
|
|
use OCA\Files_External\Lib\StorageConfig;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\Files_External\MountConfig;
|
2016-05-13 05:56:47 -04:00
|
|
|
use OCA\Files_External\NotFoundException;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Files_External\Service\GlobalStoragesService;
|
2023-07-19 15:56:34 -04:00
|
|
|
use OCA\Files_External\Service\UserStoragesService;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\AppFramework\Http;
|
2023-07-19 15:56:34 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2014-10-31 06:41:07 -04:00
|
|
|
|
2025-05-17 05:46:26 -04:00
|
|
|
abstract class StoragesControllerTestCase extends \Test\TestCase {
|
|
|
|
|
protected GlobalStoragesController|UserStoragesController $controller;
|
|
|
|
|
protected GlobalStoragesService|UserStoragesService|MockObject $service;
|
2014-10-31 06:41:07 -04:00
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2025-05-17 05:46:26 -04:00
|
|
|
parent::setUp();
|
2024-10-10 06:40:31 -04:00
|
|
|
MountConfig::$skipTest = true;
|
2014-10-31 06:41:07 -04:00
|
|
|
}
|
|
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function tearDown(): void {
|
2024-10-10 06:40:31 -04:00
|
|
|
MountConfig::$skipTest = false;
|
2025-05-17 05:46:26 -04:00
|
|
|
parent::tearDown();
|
2014-10-31 06:41:07 -04:00
|
|
|
}
|
|
|
|
|
|
2015-12-07 07:05:27 -05:00
|
|
|
/**
|
2025-05-17 05:46:26 -04:00
|
|
|
* @return \OCA\Files_External\Lib\Backend\Backend&MockObject
|
2015-12-07 07:05:27 -05:00
|
|
|
*/
|
2025-05-17 05:46:26 -04:00
|
|
|
protected function getBackendMock($class = SMB::class, $storageClass = \OCA\Files_External\Lib\Storage\SMB::class) {
|
|
|
|
|
$backend = $this->createMock(Backend::class);
|
2015-08-11 13:45:07 -04:00
|
|
|
$backend->method('getStorageClass')
|
|
|
|
|
->willReturn($storageClass);
|
2015-08-12 15:03:11 -04:00
|
|
|
$backend->method('getIdentifier')
|
|
|
|
|
->willReturn('identifier:' . $class);
|
2020-03-13 10:33:47 -04:00
|
|
|
$backend->method('getParameters')
|
|
|
|
|
->willReturn([]);
|
2015-08-11 13:45:07 -04:00
|
|
|
return $backend;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 07:05:27 -05:00
|
|
|
/**
|
2024-10-10 06:40:31 -04:00
|
|
|
* @return AuthMechanism|MockObject
|
2015-12-07 07:05:27 -05:00
|
|
|
*/
|
2025-05-17 05:46:26 -04:00
|
|
|
protected function getAuthMechMock($scheme = 'null', $class = NullMechanism::class) {
|
|
|
|
|
$authMech = $this->createMock(AuthMechanism::class);
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$authMech->method('getScheme')
|
|
|
|
|
->willReturn($scheme);
|
2015-08-12 15:03:11 -04:00
|
|
|
$authMech->method('getIdentifier')
|
|
|
|
|
->willReturn('identifier:' . $class);
|
2020-03-13 10:33:47 -04:00
|
|
|
$authMech->method('getParameters')
|
|
|
|
|
->willReturn([]);
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
|
|
|
|
|
return $authMech;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 06:41:07 -04:00
|
|
|
public function testAddStorage(): void {
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$authMech = $this->getAuthMechMock();
|
|
|
|
|
$authMech->method('validateStorage')
|
|
|
|
|
->willReturn(true);
|
2015-09-17 05:24:19 -04:00
|
|
|
$authMech->method('isVisibleFor')
|
2015-08-28 11:15:21 -04:00
|
|
|
->willReturn(true);
|
2015-08-11 13:45:07 -04:00
|
|
|
$backend = $this->getBackendMock();
|
|
|
|
|
$backend->method('validateStorage')
|
|
|
|
|
->willReturn(true);
|
2015-09-17 05:24:19 -04:00
|
|
|
$backend->method('isVisibleFor')
|
2015-08-11 13:45:07 -04:00
|
|
|
->willReturn(true);
|
|
|
|
|
|
2014-10-31 06:41:07 -04:00
|
|
|
$storageConfig = new StorageConfig(1);
|
|
|
|
|
$storageConfig->setMountPoint('mount');
|
2015-08-11 13:45:07 -04:00
|
|
|
$storageConfig->setBackend($backend);
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$storageConfig->setAuthMechanism($authMech);
|
2015-08-11 13:45:07 -04:00
|
|
|
$storageConfig->setBackendOptions([]);
|
2014-10-31 06:41:07 -04:00
|
|
|
|
2015-08-11 13:45:07 -04:00
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('createStorage')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2014-10-31 06:41:07 -04:00
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('addStorage')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2014-10-31 06:41:07 -04:00
|
|
|
|
|
|
|
|
$response = $this->controller->create(
|
|
|
|
|
'mount',
|
2025-05-17 05:46:26 -04:00
|
|
|
\OCA\Files_External\Lib\Storage\SMB::class,
|
|
|
|
|
NullMechanism::class,
|
2020-03-26 04:30:18 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
[],
|
|
|
|
|
[],
|
2015-03-13 07:49:11 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$data = $response->getData();
|
|
|
|
|
$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
|
2023-07-13 03:58:24 -04:00
|
|
|
$this->assertEquals($storageConfig->jsonSerialize(), $data);
|
2014-10-31 06:41:07 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-06 05:18:59 -05:00
|
|
|
public function testAddLocalStorageWhenDisabled(): void {
|
|
|
|
|
$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',
|
2025-05-17 05:46:26 -04:00
|
|
|
NullMechanism::class,
|
2021-12-06 05:18:59 -05:00
|
|
|
[],
|
|
|
|
|
[],
|
|
|
|
|
[],
|
|
|
|
|
[],
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$data = $response->getData();
|
|
|
|
|
$this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 06:41:07 -04:00
|
|
|
public function testUpdateStorage(): void {
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$authMech = $this->getAuthMechMock();
|
|
|
|
|
$authMech->method('validateStorage')
|
|
|
|
|
->willReturn(true);
|
2015-09-17 05:24:19 -04:00
|
|
|
$authMech->method('isVisibleFor')
|
2015-08-28 11:15:21 -04:00
|
|
|
->willReturn(true);
|
2015-08-11 13:45:07 -04:00
|
|
|
$backend = $this->getBackendMock();
|
|
|
|
|
$backend->method('validateStorage')
|
|
|
|
|
->willReturn(true);
|
2015-09-17 05:24:19 -04:00
|
|
|
$backend->method('isVisibleFor')
|
2015-08-11 13:45:07 -04:00
|
|
|
->willReturn(true);
|
|
|
|
|
|
2014-10-31 06:41:07 -04:00
|
|
|
$storageConfig = new StorageConfig(1);
|
|
|
|
|
$storageConfig->setMountPoint('mount');
|
2015-08-11 13:45:07 -04:00
|
|
|
$storageConfig->setBackend($backend);
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$storageConfig->setAuthMechanism($authMech);
|
2015-08-11 13:45:07 -04:00
|
|
|
$storageConfig->setBackendOptions([]);
|
2014-10-31 06:41:07 -04:00
|
|
|
|
2015-08-11 13:45:07 -04:00
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('createStorage')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2014-10-31 06:41:07 -04:00
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('updateStorage')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2014-10-31 06:41:07 -04:00
|
|
|
|
|
|
|
|
$response = $this->controller->update(
|
|
|
|
|
1,
|
|
|
|
|
'mount',
|
2025-05-17 05:46:26 -04:00
|
|
|
\OCA\Files_External\Lib\Storage\SMB::class,
|
|
|
|
|
NullMechanism::class,
|
2020-03-26 04:30:18 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
[],
|
|
|
|
|
[],
|
2015-03-13 07:49:11 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$data = $response->getData();
|
|
|
|
|
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
|
2023-07-13 03:58:24 -04:00
|
|
|
$this->assertEquals($storageConfig->jsonSerialize(), $data);
|
2014-10-31 06:41:07 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-17 05:46:26 -04:00
|
|
|
public static function mountPointNamesProvider(): array {
|
2020-03-26 04:30:18 -04:00
|
|
|
return [
|
|
|
|
|
[''],
|
|
|
|
|
['/'],
|
|
|
|
|
['//'],
|
|
|
|
|
];
|
2014-10-31 06:41:07 -04:00
|
|
|
}
|
|
|
|
|
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('mountPointNamesProvider')]
|
2014-10-31 06:41:07 -04:00
|
|
|
public function testAddOrUpdateStorageInvalidMountPoint($mountPoint): void {
|
2015-08-11 13:45:07 -04:00
|
|
|
$storageConfig = new StorageConfig(1);
|
|
|
|
|
$storageConfig->setMountPoint($mountPoint);
|
|
|
|
|
$storageConfig->setBackend($this->getBackendMock());
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$storageConfig->setAuthMechanism($this->getAuthMechMock());
|
2015-08-11 13:45:07 -04:00
|
|
|
$storageConfig->setBackendOptions([]);
|
|
|
|
|
|
|
|
|
|
$this->service->expects($this->exactly(2))
|
|
|
|
|
->method('createStorage')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2014-10-31 06:41:07 -04:00
|
|
|
$this->service->expects($this->never())
|
|
|
|
|
->method('addStorage');
|
|
|
|
|
$this->service->expects($this->never())
|
|
|
|
|
->method('updateStorage');
|
|
|
|
|
|
|
|
|
|
$response = $this->controller->create(
|
|
|
|
|
$mountPoint,
|
2025-05-17 05:46:26 -04:00
|
|
|
\OCA\Files_External\Lib\Storage\SMB::class,
|
|
|
|
|
NullMechanism::class,
|
2020-03-26 04:30:18 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
[],
|
|
|
|
|
[],
|
2015-03-13 07:49:11 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
|
|
|
|
|
|
|
|
|
|
$response = $this->controller->update(
|
|
|
|
|
1,
|
|
|
|
|
$mountPoint,
|
2025-05-17 05:46:26 -04:00
|
|
|
\OCA\Files_External\Lib\Storage\SMB::class,
|
|
|
|
|
NullMechanism::class,
|
2020-03-26 04:30:18 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
[],
|
|
|
|
|
[],
|
2015-03-13 07:49:11 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAddOrUpdateStorageInvalidBackend(): void {
|
2015-08-11 13:45:07 -04:00
|
|
|
$this->service->expects($this->exactly(2))
|
|
|
|
|
->method('createStorage')
|
2025-06-30 10:56:59 -04:00
|
|
|
->willThrowException(new \InvalidArgumentException());
|
2014-10-31 06:41:07 -04:00
|
|
|
$this->service->expects($this->never())
|
|
|
|
|
->method('addStorage');
|
|
|
|
|
$this->service->expects($this->never())
|
|
|
|
|
->method('updateStorage');
|
|
|
|
|
|
|
|
|
|
$response = $this->controller->create(
|
|
|
|
|
'mount',
|
|
|
|
|
'\OC\Files\Storage\InvalidStorage',
|
2025-05-17 05:46:26 -04:00
|
|
|
NullMechanism::class,
|
2020-03-26 04:30:18 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
[],
|
|
|
|
|
[],
|
2015-03-13 07:49:11 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
|
|
|
|
|
|
|
|
|
|
$response = $this->controller->update(
|
|
|
|
|
1,
|
|
|
|
|
'mount',
|
|
|
|
|
'\OC\Files\Storage\InvalidStorage',
|
2025-05-17 05:46:26 -04:00
|
|
|
NullMechanism::class,
|
2020-03-26 04:30:18 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
[],
|
|
|
|
|
[],
|
2015-03-13 07:49:11 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUpdateStorageNonExisting(): void {
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$authMech = $this->getAuthMechMock();
|
|
|
|
|
$authMech->method('validateStorage')
|
|
|
|
|
->willReturn(true);
|
2015-09-17 05:24:19 -04:00
|
|
|
$authMech->method('isVisibleFor')
|
2015-08-28 11:15:21 -04:00
|
|
|
->willReturn(true);
|
2015-08-11 13:45:07 -04:00
|
|
|
$backend = $this->getBackendMock();
|
|
|
|
|
$backend->method('validateStorage')
|
|
|
|
|
->willReturn(true);
|
2015-09-17 05:24:19 -04:00
|
|
|
$backend->method('isVisibleFor')
|
2015-08-11 13:45:07 -04:00
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$storageConfig = new StorageConfig(255);
|
|
|
|
|
$storageConfig->setMountPoint('mount');
|
|
|
|
|
$storageConfig->setBackend($backend);
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$storageConfig->setAuthMechanism($authMech);
|
2015-08-11 13:45:07 -04:00
|
|
|
$storageConfig->setBackendOptions([]);
|
|
|
|
|
|
|
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('createStorage')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2014-10-31 06:41:07 -04:00
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('updateStorage')
|
2025-06-30 10:56:59 -04:00
|
|
|
->willThrowException(new NotFoundException());
|
2014-10-31 06:41:07 -04:00
|
|
|
|
|
|
|
|
$response = $this->controller->update(
|
|
|
|
|
255,
|
|
|
|
|
'mount',
|
2025-05-17 05:46:26 -04:00
|
|
|
\OCA\Files_External\Lib\Storage\SMB::class,
|
|
|
|
|
NullMechanism::class,
|
2020-03-26 04:30:18 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
[],
|
|
|
|
|
[],
|
2015-03-13 07:49:11 -04:00
|
|
|
[],
|
2014-10-31 06:41:07 -04:00
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDeleteStorage(): void {
|
|
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('removeStorage');
|
|
|
|
|
|
|
|
|
|
$response = $this->controller->destroy(1);
|
|
|
|
|
$this->assertEquals(Http::STATUS_NO_CONTENT, $response->getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDeleteStorageNonExisting(): void {
|
|
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('removeStorage')
|
2025-06-30 10:56:59 -04:00
|
|
|
->willThrowException(new NotFoundException());
|
2014-10-31 06:41:07 -04:00
|
|
|
|
|
|
|
|
$response = $this->controller->destroy(255);
|
|
|
|
|
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetStorage(): void {
|
2015-08-11 13:45:07 -04:00
|
|
|
$backend = $this->getBackendMock();
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$authMech = $this->getAuthMechMock();
|
2014-10-31 06:41:07 -04:00
|
|
|
$storageConfig = new StorageConfig(1);
|
|
|
|
|
$storageConfig->setMountPoint('test');
|
2015-08-11 13:45:07 -04:00
|
|
|
$storageConfig->setBackend($backend);
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 05:54:03 -04:00
|
|
|
$storageConfig->setAuthMechanism($authMech);
|
2014-10-31 06:41:07 -04:00
|
|
|
$storageConfig->setBackendOptions(['user' => 'test', 'password', 'password123']);
|
2015-03-13 07:49:11 -04:00
|
|
|
$storageConfig->setMountOptions(['priority' => false]);
|
2014-10-31 06:41:07 -04:00
|
|
|
|
|
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('getStorage')
|
|
|
|
|
->with(1)
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2014-10-31 06:41:07 -04:00
|
|
|
$response = $this->controller->show(1);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
|
2021-01-08 10:14:44 -05:00
|
|
|
$expected = $storageConfig->jsonSerialize();
|
|
|
|
|
$expected['can_edit'] = false;
|
|
|
|
|
$this->assertEquals($expected, $response->getData());
|
2014-10-31 06:41:07 -04:00
|
|
|
}
|
2015-08-12 05:00:37 -04:00
|
|
|
|
2025-05-17 05:46:26 -04:00
|
|
|
public static function validateStorageProvider(): array {
|
2015-08-12 05:00:37 -04:00
|
|
|
return [
|
|
|
|
|
[true, true, true],
|
|
|
|
|
[false, true, false],
|
|
|
|
|
[true, false, false],
|
|
|
|
|
[false, false, false]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('validateStorageProvider')]
|
2025-05-17 05:46:26 -04:00
|
|
|
public function testValidateStorage(bool $backendValidate, bool $authMechValidate, bool $expectSuccess): void {
|
2015-08-12 05:00:37 -04:00
|
|
|
$backend = $this->getBackendMock();
|
|
|
|
|
$backend->method('validateStorage')
|
|
|
|
|
->willReturn($backendValidate);
|
2015-09-17 05:24:19 -04:00
|
|
|
$backend->method('isVisibleFor')
|
2015-08-12 05:00:37 -04:00
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$authMech = $this->getAuthMechMock();
|
|
|
|
|
$authMech->method('validateStorage')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($authMechValidate);
|
2015-09-17 05:24:19 -04:00
|
|
|
$authMech->method('isVisibleFor')
|
2015-08-28 11:15:21 -04:00
|
|
|
->willReturn(true);
|
2015-08-12 05:00:37 -04:00
|
|
|
|
|
|
|
|
$storageConfig = new StorageConfig();
|
|
|
|
|
$storageConfig->setMountPoint('mount');
|
|
|
|
|
$storageConfig->setBackend($backend);
|
|
|
|
|
$storageConfig->setAuthMechanism($authMech);
|
|
|
|
|
$storageConfig->setBackendOptions([]);
|
|
|
|
|
|
|
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('createStorage')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2015-08-12 05:00:37 -04:00
|
|
|
|
|
|
|
|
if ($expectSuccess) {
|
|
|
|
|
$this->service->expects($this->once())
|
|
|
|
|
->method('addStorage')
|
|
|
|
|
->with($storageConfig)
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($storageConfig);
|
2015-08-12 05:00:37 -04:00
|
|
|
} else {
|
|
|
|
|
$this->service->expects($this->never())
|
|
|
|
|
->method('addStorage');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = $this->controller->create(
|
|
|
|
|
'mount',
|
2025-05-17 05:46:26 -04:00
|
|
|
\OCA\Files_External\Lib\Storage\SMB::class,
|
|
|
|
|
NullMechanism::class,
|
2020-03-26 04:30:18 -04:00
|
|
|
[],
|
2015-08-12 05:00:37 -04:00
|
|
|
[],
|
|
|
|
|
[],
|
|
|
|
|
[],
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($expectSuccess) {
|
|
|
|
|
$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-31 06:41:07 -04:00
|
|
|
}
|