2014-10-31 10:41:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2024-06-06 07:55:47 +00:00
|
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-10-31 10:41:07 +00:00
|
|
|
*/
|
2016-05-13 09:22:28 +00:00
|
|
|
namespace OCA\Files_External\Tests\Service;
|
2014-10-31 10:41:07 +00:00
|
|
|
|
2024-10-10 10:40:31 +00:00
|
|
|
use OC\Files\Cache\Storage;
|
2019-11-22 19:52:10 +00:00
|
|
|
use OC\Files\Filesystem;
|
2017-10-24 13:26:53 +00:00
|
|
|
use OCA\Files_External\Lib\Auth\AuthMechanism;
|
2017-09-06 15:11:21 +00:00
|
|
|
use OCA\Files_External\Lib\Auth\InvalidAuth;
|
2024-10-10 10:40:31 +00:00
|
|
|
|
2017-10-24 13:26:53 +00:00
|
|
|
use OCA\Files_External\Lib\Backend\Backend;
|
2017-09-06 15:11:21 +00:00
|
|
|
use OCA\Files_External\Lib\Backend\InvalidBackend;
|
2016-05-13 09:56:47 +00:00
|
|
|
use OCA\Files_External\Lib\StorageConfig;
|
2024-10-10 10:40:31 +00:00
|
|
|
use OCA\Files_External\MountConfig;
|
2019-11-22 19:52:10 +00:00
|
|
|
use OCA\Files_External\NotFoundException;
|
2015-11-02 12:13:06 +00:00
|
|
|
use OCA\Files_External\Service\BackendService;
|
|
|
|
use OCA\Files_External\Service\DBConfigService;
|
2016-05-13 09:22:28 +00:00
|
|
|
use OCA\Files_External\Service\StoragesService;
|
2016-09-02 08:37:20 +00:00
|
|
|
use OCP\AppFramework\IAppContainer;
|
2022-03-17 17:24:18 +00:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2021-05-10 15:34:10 +00:00
|
|
|
use OCP\Files\Cache\ICache;
|
2016-09-02 08:37:20 +00:00
|
|
|
use OCP\Files\Config\IUserMountCache;
|
2021-05-10 15:34:10 +00:00
|
|
|
use OCP\Files\Mount\IMountPoint;
|
|
|
|
use OCP\Files\Storage\IStorage;
|
2023-08-16 10:34:18 +00:00
|
|
|
use OCP\IDBConnection;
|
2021-05-10 15:34:10 +00:00
|
|
|
use OCP\IUser;
|
2024-02-12 15:38:08 +00:00
|
|
|
use OCP\Server;
|
2024-10-10 10:40:31 +00:00
|
|
|
use OCP\Util;
|
2014-10-31 10:41:07 +00:00
|
|
|
|
2015-11-02 12:13:06 +00:00
|
|
|
class CleaningDBConfig extends DBConfigService {
|
|
|
|
private $mountIds = [];
|
|
|
|
|
|
|
|
public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
|
|
|
|
$id = parent::addMount($mountPoint, $storageBackend, $authBackend, $priority, $type); // TODO: Change the autogenerated stub
|
|
|
|
$this->mountIds[] = $id;
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clean() {
|
|
|
|
foreach ($this->mountIds as $id) {
|
|
|
|
$this->removeMount($id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DB
|
|
|
|
*/
|
2014-10-31 10:41:07 +00:00
|
|
|
abstract class StoragesServiceTest extends \Test\TestCase {
|
|
|
|
/**
|
|
|
|
* @var StoragesService
|
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
2015-08-11 17:45:07 +00:00
|
|
|
/** @var BackendService */
|
|
|
|
protected $backendService;
|
|
|
|
|
2014-10-31 10:41:07 +00:00
|
|
|
/**
|
|
|
|
* Data directory
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $dataDir;
|
|
|
|
|
2015-11-02 12:13:06 +00:00
|
|
|
/** @var CleaningDBConfig */
|
|
|
|
protected $dbConfig;
|
|
|
|
|
2014-10-31 10:41:07 +00:00
|
|
|
/**
|
|
|
|
* Hook calls
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $hookCalls;
|
|
|
|
|
2016-01-13 14:29:53 +00:00
|
|
|
/**
|
2024-10-18 10:04:22 +00:00
|
|
|
* @var \PHPUnit\Framework\MockObject\MockObject|IUserMountCache
|
2016-01-13 14:29:53 +00:00
|
|
|
*/
|
|
|
|
protected $mountCache;
|
|
|
|
|
2022-03-17 17:24:18 +00:00
|
|
|
/**
|
|
|
|
* @var \PHPUnit\Framework\MockObject\MockObject|IEventDispatcher
|
|
|
|
*/
|
|
|
|
protected IEventDispatcher $eventDispatcher;
|
|
|
|
|
2019-11-27 14:27:18 +00:00
|
|
|
protected function setUp(): void {
|
2015-11-02 12:13:06 +00:00
|
|
|
parent::setUp();
|
2016-02-11 12:55:22 +00:00
|
|
|
$this->dbConfig = new CleaningDBConfig(\OC::$server->getDatabaseConnection(), \OC::$server->getCrypto());
|
2020-03-26 08:30:18 +00:00
|
|
|
self::$hookCalls = [];
|
2014-10-31 10:41:07 +00:00
|
|
|
$config = \OC::$server->getConfig();
|
|
|
|
$this->dataDir = $config->getSystemValue(
|
|
|
|
'datadirectory',
|
|
|
|
\OC::$SERVERROOT . '/data/'
|
|
|
|
);
|
2024-10-10 10:40:31 +00:00
|
|
|
MountConfig::$skipTest = true;
|
2014-10-31 10:41:07 +00:00
|
|
|
|
2016-09-02 08:37:20 +00:00
|
|
|
$this->mountCache = $this->createMock(IUserMountCache::class);
|
2022-03-17 17:24:18 +00:00
|
|
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
2016-01-13 14:29:53 +00:00
|
|
|
|
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 09:54:03 +00:00
|
|
|
// prepare BackendService mock
|
2015-08-11 17:45:07 +00:00
|
|
|
$this->backendService =
|
|
|
|
$this->getMockBuilder('\OCA\Files_External\Service\BackendService')
|
2015-11-02 12:13:06 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-08-11 17:45:07 +00:00
|
|
|
|
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 09:54:03 +00:00
|
|
|
$authMechanisms = [
|
2015-08-12 19:03:11 +00:00
|
|
|
'identifier:\Auth\Mechanism' => $this->getAuthMechMock('null', '\Auth\Mechanism'),
|
|
|
|
'identifier:\Other\Auth\Mechanism' => $this->getAuthMechMock('null', '\Other\Auth\Mechanism'),
|
|
|
|
'identifier:\OCA\Files_External\Lib\Auth\NullMechanism' => $this->getAuthMechMock(),
|
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 09:54:03 +00:00
|
|
|
];
|
|
|
|
$this->backendService->method('getAuthMechanism')
|
2020-03-25 21:21:27 +00:00
|
|
|
->willReturnCallback(function ($class) use ($authMechanisms) {
|
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 09:54:03 +00:00
|
|
|
if (isset($authMechanisms[$class])) {
|
|
|
|
return $authMechanisms[$class];
|
|
|
|
}
|
|
|
|
return null;
|
2020-03-25 21:21:27 +00:00
|
|
|
});
|
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 09:54:03 +00:00
|
|
|
$this->backendService->method('getAuthMechanismsByScheme')
|
2020-03-25 21:21:27 +00:00
|
|
|
->willReturnCallback(function ($schemes) use ($authMechanisms) {
|
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 09:54:03 +00:00
|
|
|
return array_filter($authMechanisms, function ($authMech) use ($schemes) {
|
|
|
|
return in_array($authMech->getScheme(), $schemes, true);
|
|
|
|
});
|
2020-03-25 21:21:27 +00:00
|
|
|
});
|
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 09:54:03 +00:00
|
|
|
$this->backendService->method('getAuthMechanisms')
|
2020-03-25 21:21:27 +00:00
|
|
|
->willReturn($authMechanisms);
|
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 09:54:03 +00:00
|
|
|
|
2016-04-13 22:18:07 +00:00
|
|
|
$sftpBackend = $this->getBackendMock('\OCA\Files_External\Lib\Backend\SFTP', '\OCA\Files_External\Lib\Storage\SFTP');
|
2015-08-11 17:45:07 +00:00
|
|
|
$backends = [
|
2018-06-21 14:00:58 +00:00
|
|
|
'identifier:\OCA\Files_External\Lib\Backend\DAV' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\DAV', '\OC\Files\Storage\DAV'),
|
2016-04-13 22:18:07 +00:00
|
|
|
'identifier:\OCA\Files_External\Lib\Backend\SMB' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SMB', '\OCA\Files_External\Lib\Storage\SMB'),
|
2015-08-12 19:03:11 +00:00
|
|
|
'identifier:\OCA\Files_External\Lib\Backend\SFTP' => $sftpBackend,
|
|
|
|
'identifier:sftp_alias' => $sftpBackend,
|
2015-08-11 17:45:07 +00:00
|
|
|
];
|
2015-08-12 19:03:11 +00:00
|
|
|
$backends['identifier:\OCA\Files_External\Lib\Backend\SFTP']->method('getLegacyAuthMechanism')
|
|
|
|
->willReturn($authMechanisms['identifier:\Other\Auth\Mechanism']);
|
2015-08-11 17:45:07 +00:00
|
|
|
$this->backendService->method('getBackend')
|
2020-03-25 21:21:27 +00:00
|
|
|
->willReturnCallback(function ($backendClass) use ($backends) {
|
2015-08-11 17:45:07 +00:00
|
|
|
if (isset($backends[$backendClass])) {
|
|
|
|
return $backends[$backendClass];
|
|
|
|
}
|
|
|
|
return null;
|
2020-03-25 21:21:27 +00:00
|
|
|
});
|
2015-08-11 17:45:07 +00:00
|
|
|
$this->backendService->method('getBackends')
|
2020-03-25 21:21:27 +00:00
|
|
|
->willReturn($backends);
|
2021-03-26 14:07:39 +00:00
|
|
|
$this->overwriteService(BackendService::class, $this->backendService);
|
2015-08-11 17:45:07 +00:00
|
|
|
|
2024-10-10 10:40:31 +00:00
|
|
|
Util::connectHook(
|
2014-10-31 10:41:07 +00:00
|
|
|
Filesystem::CLASSNAME,
|
|
|
|
Filesystem::signal_create_mount,
|
|
|
|
get_class($this), 'createHookCallback');
|
2024-10-10 10:40:31 +00:00
|
|
|
Util::connectHook(
|
2014-10-31 10:41:07 +00:00
|
|
|
Filesystem::CLASSNAME,
|
|
|
|
Filesystem::signal_delete_mount,
|
|
|
|
get_class($this), 'deleteHookCallback');
|
|
|
|
|
2016-09-02 08:37:20 +00:00
|
|
|
$containerMock = $this->createMock(IAppContainer::class);
|
2015-08-12 19:03:11 +00:00
|
|
|
$containerMock->method('query')
|
2020-03-25 21:21:27 +00:00
|
|
|
->willReturnCallback(function ($name) {
|
2015-08-12 19:03:11 +00:00
|
|
|
if ($name === 'OCA\Files_External\Service\BackendService') {
|
|
|
|
return $this->backendService;
|
|
|
|
}
|
2020-03-25 21:21:27 +00:00
|
|
|
});
|
2014-10-31 10:41:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 14:27:18 +00:00
|
|
|
protected function tearDown(): void {
|
2024-10-10 10:40:31 +00:00
|
|
|
MountConfig::$skipTest = false;
|
2020-03-26 08:30:18 +00:00
|
|
|
self::$hookCalls = [];
|
2015-11-02 12:13:06 +00:00
|
|
|
if ($this->dbConfig) {
|
|
|
|
$this->dbConfig->clean();
|
|
|
|
}
|
2014-10-31 10:41:07 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 22:18:07 +00:00
|
|
|
protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') {
|
2017-10-24 13:26:53 +00:00
|
|
|
$backend = $this->getMockBuilder(Backend::class)
|
2015-08-11 17:45:07 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$backend->method('getStorageClass')
|
|
|
|
->willReturn($storageClass);
|
2015-08-12 19:03:11 +00:00
|
|
|
$backend->method('getIdentifier')
|
2015-11-02 12:13:06 +00:00
|
|
|
->willReturn('identifier:' . $class);
|
2015-08-11 17:45:07 +00:00
|
|
|
return $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 09:54:03 +00:00
|
|
|
protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') {
|
2017-10-24 13:26:53 +00:00
|
|
|
$authMech = $this->getMockBuilder(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 09:54:03 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$authMech->method('getScheme')
|
|
|
|
->willReturn($scheme);
|
2015-08-12 19:03:11 +00:00
|
|
|
$authMech->method('getIdentifier')
|
2015-11-02 12:13:06 +00:00
|
|
|
->willReturn('identifier:' . $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 09:54:03 +00:00
|
|
|
|
|
|
|
return $authMech;
|
|
|
|
}
|
|
|
|
|
2014-10-31 10:41:07 +00:00
|
|
|
/**
|
|
|
|
* Creates a StorageConfig instance based on array data
|
|
|
|
*
|
2017-10-24 13:26:53 +00:00
|
|
|
* @param array $data
|
2014-10-31 10:41:07 +00:00
|
|
|
*
|
|
|
|
* @return StorageConfig storage config instance
|
|
|
|
*/
|
|
|
|
protected function makeStorageConfig($data) {
|
|
|
|
$storage = new StorageConfig();
|
|
|
|
if (isset($data['id'])) {
|
|
|
|
$storage->setId($data['id']);
|
|
|
|
}
|
|
|
|
$storage->setMountPoint($data['mountPoint']);
|
2015-08-11 17:45:07 +00:00
|
|
|
if (!isset($data['backend'])) {
|
|
|
|
// data providers are run before $this->backendService is initialised
|
|
|
|
// so $data['backend'] can be specified directly
|
2015-08-12 19:03:11 +00:00
|
|
|
$data['backend'] = $this->backendService->getBackend($data['backendIdentifier']);
|
|
|
|
}
|
|
|
|
if (!isset($data['backend'])) {
|
|
|
|
throw new \Exception('oops, no backend');
|
|
|
|
}
|
|
|
|
if (!isset($data['authMechanism'])) {
|
|
|
|
$data['authMechanism'] = $this->backendService->getAuthMechanism($data['authMechanismIdentifier']);
|
2015-08-11 17:45:07 +00:00
|
|
|
}
|
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 09:54:03 +00:00
|
|
|
if (!isset($data['authMechanism'])) {
|
2015-08-12 19:03:11 +00:00
|
|
|
throw new \Exception('oops, no auth mechanism');
|
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 09:54:03 +00:00
|
|
|
}
|
2015-08-11 17:45:07 +00:00
|
|
|
$storage->setBackend($data['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 09:54:03 +00:00
|
|
|
$storage->setAuthMechanism($data['authMechanism']);
|
2014-10-31 10:41:07 +00:00
|
|
|
$storage->setBackendOptions($data['backendOptions']);
|
|
|
|
if (isset($data['applicableUsers'])) {
|
|
|
|
$storage->setApplicableUsers($data['applicableUsers']);
|
|
|
|
}
|
|
|
|
if (isset($data['applicableGroups'])) {
|
|
|
|
$storage->setApplicableGroups($data['applicableGroups']);
|
|
|
|
}
|
|
|
|
if (isset($data['priority'])) {
|
|
|
|
$storage->setPriority($data['priority']);
|
|
|
|
}
|
2015-03-13 11:49:11 +00:00
|
|
|
if (isset($data['mountOptions'])) {
|
|
|
|
$storage->setMountOptions($data['mountOptions']);
|
|
|
|
}
|
2014-10-31 10:41:07 +00:00
|
|
|
return $storage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-27 12:47:39 +00:00
|
|
|
protected function ActualNonExistingStorageTest() {
|
2015-08-12 19:03:11 +00:00
|
|
|
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
|
|
|
|
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
|
2014-10-31 10:41:07 +00:00
|
|
|
$storage = new StorageConfig(255);
|
|
|
|
$storage->setMountPoint('mountpoint');
|
2015-08-11 17:45:07 +00:00
|
|
|
$storage->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 09:54:03 +00:00
|
|
|
$storage->setAuthMechanism($authMechanism);
|
2014-10-31 10:41:07 +00:00
|
|
|
$this->service->updateStorage($storage);
|
|
|
|
}
|
|
|
|
|
2019-11-27 12:47:39 +00:00
|
|
|
public function testNonExistingStorage(): void {
|
2024-10-10 10:40:31 +00:00
|
|
|
$this->expectException(NotFoundException::class);
|
2019-11-27 12:47:39 +00:00
|
|
|
|
|
|
|
$this->ActualNonExistingStorageTest();
|
|
|
|
}
|
|
|
|
|
2015-10-06 14:47:59 +00:00
|
|
|
public function deleteStorageDataProvider() {
|
|
|
|
return [
|
|
|
|
// regular case, can properly delete the oc_storages entry
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'host' => 'example.com',
|
|
|
|
'user' => 'test',
|
|
|
|
'password' => 'testPassword',
|
|
|
|
'root' => 'someroot',
|
|
|
|
],
|
2021-05-10 15:34:10 +00:00
|
|
|
'webdav::test@example.com//someroot/'
|
2015-10-06 14:47:59 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'host' => 'example.com',
|
|
|
|
'user' => '$user',
|
|
|
|
'password' => 'testPassword',
|
|
|
|
'root' => 'someroot',
|
|
|
|
],
|
2021-05-10 15:34:10 +00:00
|
|
|
'webdav::someone@example.com//someroot/'
|
2015-10-06 14:47:59 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider deleteStorageDataProvider
|
|
|
|
*/
|
2021-05-10 15:34:10 +00:00
|
|
|
public function testDeleteStorage($backendOptions, $rustyStorageId): void {
|
2018-06-21 14:00:58 +00:00
|
|
|
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\DAV');
|
2015-08-12 19:03:11 +00:00
|
|
|
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
|
2014-10-31 10:41:07 +00:00
|
|
|
$storage = new StorageConfig(255);
|
|
|
|
$storage->setMountPoint('mountpoint');
|
2015-08-11 17:45:07 +00:00
|
|
|
$storage->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 09:54:03 +00:00
|
|
|
$storage->setAuthMechanism($authMechanism);
|
2015-10-06 14:47:59 +00:00
|
|
|
$storage->setBackendOptions($backendOptions);
|
2014-10-31 10:41:07 +00:00
|
|
|
|
|
|
|
$newStorage = $this->service->addStorage($storage);
|
2015-11-02 12:13:06 +00:00
|
|
|
$id = $newStorage->getId();
|
2014-10-31 10:41:07 +00:00
|
|
|
|
2015-10-06 14:47:59 +00:00
|
|
|
// manually trigger storage entry because normally it happens on first
|
|
|
|
// access, which isn't possible within this test
|
2024-10-10 10:40:31 +00:00
|
|
|
$storageCache = new Storage($rustyStorageId, true, Server::get(IDBConnection::class));
|
2015-10-06 14:47:59 +00:00
|
|
|
|
2021-05-10 15:34:10 +00:00
|
|
|
/** @var IUserMountCache $mountCache */
|
|
|
|
$mountCache = \OC::$server->get(IUserMountCache::class);
|
|
|
|
$mountCache->clear();
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$user->method('getUID')->willReturn('test');
|
|
|
|
$cache = $this->createMock(ICache::class);
|
|
|
|
$storage = $this->createMock(IStorage::class);
|
|
|
|
$storage->method('getCache')->willReturn($cache);
|
|
|
|
$mount = $this->createMock(IMountPoint::class);
|
|
|
|
$mount->method('getStorage')
|
|
|
|
->willReturn($storage);
|
|
|
|
$mount->method('getStorageId')
|
|
|
|
->willReturn($rustyStorageId);
|
|
|
|
$mount->method('getNumericStorageId')
|
|
|
|
->willReturn($storageCache->getNumericId());
|
|
|
|
$mount->method('getStorageRootId')
|
|
|
|
->willReturn(1);
|
|
|
|
$mount->method('getMountPoint')
|
|
|
|
->willReturn('dummy');
|
|
|
|
$mount->method('getMountId')
|
|
|
|
->willReturn($id);
|
|
|
|
$mountCache->registerMounts($user, [
|
|
|
|
$mount
|
|
|
|
]);
|
|
|
|
|
2015-10-06 14:47:59 +00:00
|
|
|
// get numeric id for later check
|
|
|
|
$numericId = $storageCache->getNumericId();
|
|
|
|
|
2015-11-02 12:13:06 +00:00
|
|
|
$this->service->removeStorage($id);
|
2014-10-31 10:41:07 +00:00
|
|
|
|
|
|
|
$caught = false;
|
|
|
|
try {
|
|
|
|
$this->service->getStorage(1);
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
$caught = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue($caught);
|
2015-10-06 14:47:59 +00:00
|
|
|
|
|
|
|
// storage id was removed from oc_storages
|
|
|
|
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
|
|
|
$storageCheckQuery = $qb->select('*')
|
|
|
|
->from('storages')
|
|
|
|
->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId)));
|
2020-11-05 09:50:53 +00:00
|
|
|
|
|
|
|
$result = $storageCheckQuery->execute();
|
|
|
|
$storages = $result->fetchAll();
|
|
|
|
$result->closeCursor();
|
2021-05-10 15:34:10 +00:00
|
|
|
$this->assertCount(0, $storages, 'expected 0 storages, got ' . json_encode($storages));
|
2014-10-31 10:41:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 12:47:39 +00:00
|
|
|
protected function actualDeletedUnexistingStorageTest() {
|
|
|
|
$this->service->removeStorage(255);
|
|
|
|
}
|
|
|
|
|
2014-10-31 10:41:07 +00:00
|
|
|
public function testDeleteUnexistingStorage(): void {
|
2024-10-10 10:40:31 +00:00
|
|
|
$this->expectException(NotFoundException::class);
|
2019-11-27 14:27:18 +00:00
|
|
|
|
2019-11-27 12:47:39 +00:00
|
|
|
$this->actualDeletedUnexistingStorageTest();
|
2014-10-31 10:41:07 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 09:00:37 +00:00
|
|
|
public function testCreateStorage(): void {
|
|
|
|
$mountPoint = 'mount';
|
|
|
|
$backendIdentifier = 'identifier:\OCA\Files_External\Lib\Backend\SMB';
|
|
|
|
$authMechanismIdentifier = 'identifier:\Auth\Mechanism';
|
|
|
|
$backendOptions = ['param' => 'foo', 'param2' => 'bar'];
|
|
|
|
$mountOptions = ['option' => 'foobar'];
|
|
|
|
$applicableUsers = ['user1', 'user2'];
|
|
|
|
$applicableGroups = ['group'];
|
|
|
|
$priority = 123;
|
|
|
|
|
|
|
|
$backend = $this->backendService->getBackend($backendIdentifier);
|
|
|
|
$authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
|
|
|
|
|
|
|
|
$storage = $this->service->createStorage(
|
|
|
|
$mountPoint,
|
|
|
|
$backendIdentifier,
|
|
|
|
$authMechanismIdentifier,
|
|
|
|
$backendOptions,
|
|
|
|
$mountOptions,
|
|
|
|
$applicableUsers,
|
|
|
|
$applicableGroups,
|
|
|
|
$priority
|
|
|
|
);
|
|
|
|
|
2015-11-02 12:13:06 +00:00
|
|
|
$this->assertEquals('/' . $mountPoint, $storage->getMountPoint());
|
2015-08-12 09:00:37 +00:00
|
|
|
$this->assertEquals($backend, $storage->getBackend());
|
|
|
|
$this->assertEquals($authMechanism, $storage->getAuthMechanism());
|
|
|
|
$this->assertEquals($backendOptions, $storage->getBackendOptions());
|
|
|
|
$this->assertEquals($mountOptions, $storage->getMountOptions());
|
|
|
|
$this->assertEquals($applicableUsers, $storage->getApplicableUsers());
|
|
|
|
$this->assertEquals($applicableGroups, $storage->getApplicableGroups());
|
|
|
|
$this->assertEquals($priority, $storage->getPriority());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateStorageInvalidClass(): void {
|
2017-09-06 15:11:21 +00:00
|
|
|
$storage = $this->service->createStorage(
|
2015-08-12 09:00:37 +00:00
|
|
|
'mount',
|
|
|
|
'identifier:\OC\Not\A\Backend',
|
|
|
|
'identifier:\Auth\Mechanism',
|
|
|
|
[]
|
|
|
|
);
|
2017-09-06 15:11:21 +00:00
|
|
|
$this->assertInstanceOf(InvalidBackend::class, $storage->getBackend());
|
2015-08-12 09:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateStorageInvalidAuthMechanismClass(): void {
|
2017-09-06 15:11:21 +00:00
|
|
|
$storage = $this->service->createStorage(
|
2015-08-12 09:00:37 +00:00
|
|
|
'mount',
|
|
|
|
'identifier:\OCA\Files_External\Lib\Backend\SMB',
|
|
|
|
'identifier:\Not\An\Auth\Mechanism',
|
|
|
|
[]
|
|
|
|
);
|
2017-09-06 15:11:21 +00:00
|
|
|
$this->assertInstanceOf(InvalidAuth::class, $storage->getAuthMechanism());
|
2015-08-12 09:00:37 +00:00
|
|
|
}
|
|
|
|
|
2015-09-23 15:00:21 +00:00
|
|
|
public function testGetStoragesBackendNotVisible(): void {
|
|
|
|
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
|
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('isVisibleFor')
|
|
|
|
->with($this->service->getVisibilityType())
|
|
|
|
->willReturn(false);
|
|
|
|
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
|
|
|
|
$authMechanism->method('isVisibleFor')
|
|
|
|
->with($this->service->getVisibilityType())
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$storage = new StorageConfig(255);
|
|
|
|
$storage->setMountPoint('mountpoint');
|
|
|
|
$storage->setBackend($backend);
|
|
|
|
$storage->setAuthMechanism($authMechanism);
|
|
|
|
$storage->setBackendOptions(['password' => 'testPassword']);
|
|
|
|
|
|
|
|
$newStorage = $this->service->addStorage($storage);
|
|
|
|
|
|
|
|
$this->assertCount(1, $this->service->getAllStorages());
|
|
|
|
$this->assertEmpty($this->service->getStorages());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetStoragesAuthMechanismNotVisible(): void {
|
|
|
|
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
|
|
|
|
$backend->method('isVisibleFor')
|
|
|
|
->with($this->service->getVisibilityType())
|
|
|
|
->willReturn(true);
|
|
|
|
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
|
|
|
|
$authMechanism->expects($this->once())
|
|
|
|
->method('isVisibleFor')
|
|
|
|
->with($this->service->getVisibilityType())
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$storage = new StorageConfig(255);
|
|
|
|
$storage->setMountPoint('mountpoint');
|
|
|
|
$storage->setBackend($backend);
|
|
|
|
$storage->setAuthMechanism($authMechanism);
|
|
|
|
$storage->setBackendOptions(['password' => 'testPassword']);
|
|
|
|
|
|
|
|
$newStorage = $this->service->addStorage($storage);
|
|
|
|
|
|
|
|
$this->assertCount(1, $this->service->getAllStorages());
|
|
|
|
$this->assertEmpty($this->service->getStorages());
|
|
|
|
}
|
|
|
|
|
2014-10-31 10:41:07 +00:00
|
|
|
public static function createHookCallback($params) {
|
2020-03-26 08:30:18 +00:00
|
|
|
self::$hookCalls[] = [
|
2014-10-31 10:41:07 +00:00
|
|
|
'signal' => Filesystem::signal_create_mount,
|
|
|
|
'params' => $params
|
2020-03-26 08:30:18 +00:00
|
|
|
];
|
2014-10-31 10:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function deleteHookCallback($params) {
|
2020-03-26 08:30:18 +00:00
|
|
|
self::$hookCalls[] = [
|
2014-10-31 10:41:07 +00:00
|
|
|
'signal' => Filesystem::signal_delete_mount,
|
|
|
|
'params' => $params
|
2020-03-26 08:30:18 +00:00
|
|
|
];
|
2014-10-31 10:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asserts hook call
|
|
|
|
*
|
|
|
|
* @param array $callData hook call data to check
|
|
|
|
* @param string $signal signal name
|
|
|
|
* @param string $mountPath mount path
|
|
|
|
* @param string $mountType mount type
|
|
|
|
* @param string $applicable applicable users
|
|
|
|
*/
|
|
|
|
protected function assertHookCall($callData, $signal, $mountPath, $mountType, $applicable) {
|
|
|
|
$this->assertEquals($signal, $callData['signal']);
|
|
|
|
$params = $callData['params'];
|
|
|
|
$this->assertEquals(
|
|
|
|
$mountPath,
|
|
|
|
$params[Filesystem::signal_param_path]
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$mountType,
|
|
|
|
$params[Filesystem::signal_param_mount_type]
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$applicable,
|
|
|
|
$params[Filesystem::signal_param_users]
|
|
|
|
);
|
|
|
|
}
|
2015-12-15 12:24:30 +00:00
|
|
|
|
|
|
|
public function testUpdateStorageMountPoint(): void {
|
|
|
|
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
|
|
|
|
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
|
|
|
|
|
|
|
|
$storage = new StorageConfig();
|
|
|
|
$storage->setMountPoint('mountpoint');
|
|
|
|
$storage->setBackend($backend);
|
|
|
|
$storage->setAuthMechanism($authMechanism);
|
|
|
|
$storage->setBackendOptions(['password' => 'testPassword']);
|
|
|
|
|
|
|
|
$savedStorage = $this->service->addStorage($storage);
|
|
|
|
|
|
|
|
$newAuthMechanism = $this->backendService->getAuthMechanism('identifier:\Other\Auth\Mechanism');
|
|
|
|
|
|
|
|
$updatedStorage = new StorageConfig($savedStorage->getId());
|
|
|
|
$updatedStorage->setMountPoint('mountpoint2');
|
|
|
|
$updatedStorage->setBackend($backend);
|
|
|
|
$updatedStorage->setAuthMechanism($newAuthMechanism);
|
|
|
|
$updatedStorage->setBackendOptions(['password' => 'password2']);
|
|
|
|
|
|
|
|
$this->service->updateStorage($updatedStorage);
|
|
|
|
|
|
|
|
$savedStorage = $this->service->getStorage($updatedStorage->getId());
|
|
|
|
|
|
|
|
$this->assertEquals('/mountpoint2', $savedStorage->getMountPoint());
|
|
|
|
$this->assertEquals($newAuthMechanism, $savedStorage->getAuthMechanism());
|
|
|
|
$this->assertEquals('password2', $savedStorage->getBackendOption('password'));
|
|
|
|
}
|
2014-10-31 10:41:07 +00:00
|
|
|
}
|