summaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-08-12 20:03:11 +0100
committerRobin McCorkell <rmccorkell@owncloud.com>2015-08-19 10:05:11 +0100
commit1eeca031f863a652d07ebfa2f75339232bf60dc1 (patch)
tree2f4b046e3506d4e9e385415bf01961f9b9978d97 /apps/files_external/tests
parent272a46ebe1a5e195a078dde74f5f2ad941923d9e (diff)
downloadnextcloud-server-1eeca031f863a652d07ebfa2f75339232bf60dc1.tar.gz
nextcloud-server-1eeca031f863a652d07ebfa2f75339232bf60dc1.zip
Split backend identifiers from the class name
Prior to this, the storage class name was stored in mount.json under the "class" parameter, and the auth mechanism class name under the "authMechanism" parameter. This decouples the class name from the identifier used to retrieve the backend or auth mechanism. Now, backends/auth mechanisms have a unique identifier, which is saved in the "backend" or "authMechanism" parameter in mount.json respectively. An identifier is considered unique for the object it references, but the underlying class may change (e.g. files_external gets pulled into core and namespaces are modified).
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r--apps/files_external/tests/controller/storagescontrollertest.php8
-rw-r--r--apps/files_external/tests/service/globalstoragesservicetest.php89
-rw-r--r--apps/files_external/tests/service/storagesservicetest.php50
-rw-r--r--apps/files_external/tests/service/userstoragesservicetest.php20
-rw-r--r--apps/files_external/tests/storageconfigtest.php12
5 files changed, 118 insertions, 61 deletions
diff --git a/apps/files_external/tests/controller/storagescontrollertest.php b/apps/files_external/tests/controller/storagescontrollertest.php
index 735e760c098..5a9683306c7 100644
--- a/apps/files_external/tests/controller/storagescontrollertest.php
+++ b/apps/files_external/tests/controller/storagescontrollertest.php
@@ -53,8 +53,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
->getMock();
$backend->method('getStorageClass')
->willReturn($storageClass);
- $backend->method('getClass')
- ->willReturn($storageClass);
+ $backend->method('getIdentifier')
+ ->willReturn('identifier:'.$class);
return $backend;
}
@@ -64,8 +64,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
->getMock();
$authMech->method('getScheme')
->willReturn($scheme);
- $authMech->method('getClass')
- ->willReturn($class);
+ $authMech->method('getIdentifier')
+ ->willReturn('identifier:'.$class);
return $authMech;
}
diff --git a/apps/files_external/tests/service/globalstoragesservicetest.php b/apps/files_external/tests/service/globalstoragesservicetest.php
index d5f99431a55..f6ed9f1422a 100644
--- a/apps/files_external/tests/service/globalstoragesservicetest.php
+++ b/apps/files_external/tests/service/globalstoragesservicetest.php
@@ -40,8 +40,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
protected function makeTestStorageData() {
return $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
- 'authMechanismClass' => '\Auth\Mechanism',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -62,8 +62,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
- 'authMechanismClass' => '\Auth\Mechanism',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -78,8 +78,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
- 'authMechanismClass' => '\Auth\Mechanism',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -94,8 +94,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
- 'authMechanismClass' => '\Auth\Mechanism',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -110,8 +110,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
- 'authMechanismClass' => '\Auth\Mechanism',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -159,8 +159,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$updatedStorage = $this->makeStorageConfig($updatedStorageParams);
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
- 'authMechanismClass' => '\Auth\Mechanism',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -647,8 +647,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$mountPointOptions = current($mountPointData);
$this->assertEquals(1, $mountPointOptions['id']);
- $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
- $this->assertEquals('\Auth\Mechanism', $mountPointOptions['authMechanism']);
+ $this->assertEquals('identifier:\OCA\Files_External\Lib\Backend\SMB', $mountPointOptions['backend']);
+ $this->assertEquals('identifier:\Auth\Mechanism', $mountPointOptions['authMechanism']);
$this->assertEquals(15, $mountPointOptions['priority']);
$this->assertEquals(false, $mountPointOptions['mountOptions']['preview']);
@@ -688,8 +688,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$mountPointOptions = current($mountPointData);
$this->assertEquals(1, $mountPointOptions['id']);
- $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
- $this->assertEquals('\Auth\Mechanism', $mountPointOptions['authMechanism']);
+ $this->assertEquals('identifier:\OCA\Files_External\Lib\Backend\SMB', $mountPointOptions['backend']);
+ $this->assertEquals('identifier:\Auth\Mechanism', $mountPointOptions['authMechanism']);
$this->assertEquals(15, $mountPointOptions['priority']);
$this->assertEquals(false, $mountPointOptions['mountOptions']['preview']);
@@ -706,8 +706,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$mountPointOptions = current($mountPointData);
$this->assertEquals(1, $mountPointOptions['id']);
- $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
- $this->assertEquals('\Auth\Mechanism', $mountPointOptions['authMechanism']);
+ $this->assertEquals('identifier:\OCA\Files_External\Lib\Backend\SMB', $mountPointOptions['backend']);
+ $this->assertEquals('identifier:\Auth\Mechanism', $mountPointOptions['authMechanism']);
$this->assertEquals(15, $mountPointOptions['priority']);
$this->assertEquals(false, $mountPointOptions['mountOptions']['preview']);
@@ -732,15 +732,15 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$legacyBackendOptions = \OC_Mount_Config::encryptPasswords($legacyBackendOptions);
$legacyConfig = [
- 'class' => '\OC\Files\Storage\SMB',
- 'authMechanism' => '\Auth\Mechanism',
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
'options' => $legacyBackendOptions,
'mountOptions' => ['preview' => false],
];
// different mount options
$legacyConfig2 = [
- 'class' => '\OC\Files\Storage\SMB',
- 'authMechanism' => '\Auth\Mechanism',
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
'options' => $legacyBackendOptions,
'mountOptions' => ['preview' => true],
];
@@ -751,8 +751,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
// different config
$legacyConfig3 = [
- 'class' => '\OC\Files\Storage\SMB',
- 'authMechanism' => '\Auth\Mechanism',
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
'options' => $legacyBackendOptions2,
'mountOptions' => ['preview' => true],
];
@@ -826,4 +826,45 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$this->assertEquals([], $storage4->getApplicableGroups());
$this->assertEquals(['preview' => true], $storage4->getMountOptions());
}
+
+ public function testReadLegacyConfigClass() {
+ $configFile = $this->dataDir . '/mount.json';
+
+ $json = [
+ 'user' => [
+ 'user1' => [
+ '/$user/files/somemount' => [
+ 'class' => 'identifier:\OCA\Files_External\Lib\Backend\SFTP',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
+ 'options' => [],
+ 'mountOptions' => [],
+ ],
+ '/$user/files/othermount' => [
+ 'class' => 'identifier:sftp_alias',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
+ 'options' => [],
+ 'mountOptions' => [],
+ ],
+ ]
+ ]
+ ];
+
+ file_put_contents($configFile, json_encode($json));
+
+ $allStorages = $this->service->getAllStorages();
+
+ $this->assertCount(2, $allStorages);
+
+ $storage1 = $allStorages[1];
+ $storage2 = $allStorages[2];
+
+ $this->assertEquals('/somemount', $storage1->getMountPoint());
+ $this->assertEquals('identifier:\OCA\Files_External\Lib\Backend\SFTP', $storage1->getBackend()->getIdentifier());
+ $this->assertEquals('identifier:\Auth\Mechanism', $storage1->getAuthMechanism()->getIdentifier());
+
+ $this->assertEquals('/othermount', $storage2->getMountPoint());
+ $this->assertEquals('identifier:\OCA\Files_External\Lib\Backend\SFTP', $storage2->getBackend()->getIdentifier());
+ $this->assertEquals('identifier:\Auth\Mechanism', $storage2->getAuthMechanism()->getIdentifier());
+ }
+
}
diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php
index 1429fb1818b..397f2a2e5c5 100644
--- a/apps/files_external/tests/service/storagesservicetest.php
+++ b/apps/files_external/tests/service/storagesservicetest.php
@@ -66,9 +66,9 @@ abstract class StoragesServiceTest extends \Test\TestCase {
->getMock();
$authMechanisms = [
- '\Auth\Mechanism' => $this->getAuthMechMock('null', '\Auth\Mechanism'),
- '\Other\Auth\Mechanism' => $this->getAuthMechMock('null', '\Other\Auth\Mechanism'),
- '\OCA\Files_External\Lib\Auth\NullMechanism' => $this->getAuthMechMock(),
+ '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(),
];
$this->backendService->method('getAuthMechanism')
->will($this->returnCallback(function($class) use ($authMechanisms) {
@@ -86,12 +86,14 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->backendService->method('getAuthMechanisms')
->will($this->returnValue($authMechanisms));
+ $sftpBackend = $this->getBackendMock('\OCA\Files_External\Lib\Backend\SFTP', '\OC\Files\Storage\SFTP');
$backends = [
- '\OC\Files\Storage\SMB' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SMB', '\OC\Files\Storage\SMB'),
- '\OC\Files\Storage\SFTP' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SFTP', '\OC\Files\Storage\SFTP'),
+ 'identifier:\OCA\Files_External\Lib\Backend\SMB' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SMB', '\OC\Files\Storage\SMB'),
+ 'identifier:\OCA\Files_External\Lib\Backend\SFTP' => $sftpBackend,
+ 'identifier:sftp_alias' => $sftpBackend,
];
- $backends['\OC\Files\Storage\SFTP']->method('getLegacyAuthMechanism')
- ->willReturn($authMechanisms['\Other\Auth\Mechanism']);
+ $backends['identifier:\OCA\Files_External\Lib\Backend\SFTP']->method('getLegacyAuthMechanism')
+ ->willReturn($authMechanisms['identifier:\Other\Auth\Mechanism']);
$this->backendService->method('getBackend')
->will($this->returnCallback(function($backendClass) use ($backends) {
if (isset($backends[$backendClass])) {
@@ -111,6 +113,14 @@ abstract class StoragesServiceTest extends \Test\TestCase {
Filesystem::signal_delete_mount,
get_class($this), 'deleteHookCallback');
+ $containerMock = $this->getMock('\OCP\AppFramework\IAppContainer');
+ $containerMock->method('query')
+ ->will($this->returnCallback(function($name) {
+ if ($name === 'OCA\Files_External\Service\BackendService') {
+ return $this->backendService;
+ }
+ }));
+ \OC_Mount_Config::initApp($containerMock);
}
public function tearDown() {
@@ -124,8 +134,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
->getMock();
$backend->method('getStorageClass')
->willReturn($storageClass);
- $backend->method('getClass')
- ->willReturn($storageClass);
+ $backend->method('getIdentifier')
+ ->willReturn('identifier:'.$class);
return $backend;
}
@@ -135,8 +145,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
->getMock();
$authMech->method('getScheme')
->willReturn($scheme);
- $authMech->method('getClass')
- ->willReturn($class);
+ $authMech->method('getIdentifier')
+ ->willReturn('identifier:'.$class);
return $authMech;
}
@@ -157,10 +167,16 @@ abstract class StoragesServiceTest extends \Test\TestCase {
if (!isset($data['backend'])) {
// data providers are run before $this->backendService is initialised
// so $data['backend'] can be specified directly
- $data['backend'] = $this->backendService->getBackend($data['backendClass']);
+ $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']);
}
if (!isset($data['authMechanism'])) {
- $data['authMechanism'] = $this->backendService->getAuthMechanism($data['authMechanismClass']);
+ throw new \Exception('oops, no auth mechanism');
}
$storage->setBackend($data['backend']);
$storage->setAuthMechanism($data['authMechanism']);
@@ -185,8 +201,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
* @expectedException \OCA\Files_external\NotFoundException
*/
public function testNonExistingStorage() {
- $backend = $this->backendService->getBackend('\OC\Files\Storage\SMB');
- $authMechanism = $this->backendService->getAuthMechanism('\Auth\Mechanism');
+ $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
+ $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
$storage = new StorageConfig(255);
$storage->setMountPoint('mountpoint');
$storage->setBackend($backend);
@@ -195,8 +211,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
}
public function testDeleteStorage() {
- $backend = $this->backendService->getBackend('\OC\Files\Storage\SMB');
- $authMechanism = $this->backendService->getAuthMechanism('\Auth\Mechanism');
+ $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
+ $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
$storage = new StorageConfig(255);
$storage->setMountPoint('mountpoint');
$storage->setBackend($backend);
diff --git a/apps/files_external/tests/service/userstoragesservicetest.php b/apps/files_external/tests/service/userstoragesservicetest.php
index 1e57eedd320..0d5b82e2f8c 100644
--- a/apps/files_external/tests/service/userstoragesservicetest.php
+++ b/apps/files_external/tests/service/userstoragesservicetest.php
@@ -54,8 +54,8 @@ class UserStoragesServiceTest extends StoragesServiceTest {
private function makeTestStorageData() {
return $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
- 'authMechanismClass' => '\Auth\Mechanism',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -100,8 +100,8 @@ class UserStoragesServiceTest extends StoragesServiceTest {
public function testUpdateStorage() {
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
- 'authMechanismClass' => '\Auth\Mechanism',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -194,8 +194,8 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$mountPointOptions = current($mountPointData);
$this->assertEquals(1, $mountPointOptions['id']);
- $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
- $this->assertEquals('\Auth\Mechanism', $mountPointOptions['authMechanism']);
+ $this->assertEquals('identifier:\OCA\Files_External\Lib\Backend\SMB', $mountPointOptions['backend']);
+ $this->assertEquals('identifier:\Auth\Mechanism', $mountPointOptions['authMechanism']);
$this->assertEquals(false, $mountPointOptions['mountOptions']['preview']);
$backendOptions = $mountPointOptions['options'];
@@ -218,15 +218,15 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$legacyBackendOptions = \OC_Mount_Config::encryptPasswords($legacyBackendOptions);
$legacyConfig = [
- 'class' => '\OC\Files\Storage\SMB',
- 'authMechanism' => '\Auth\Mechanism',
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
'options' => $legacyBackendOptions,
'mountOptions' => ['preview' => false],
];
// different mount options
$legacyConfig2 = [
- 'class' => '\OC\Files\Storage\SMB',
- 'authMechanism' => '\Auth\Mechanism',
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
'options' => $legacyBackendOptions,
'mountOptions' => ['preview' => true],
];
diff --git a/apps/files_external/tests/storageconfigtest.php b/apps/files_external/tests/storageconfigtest.php
index 8039990999c..dba5105d7db 100644
--- a/apps/files_external/tests/storageconfigtest.php
+++ b/apps/files_external/tests/storageconfigtest.php
@@ -29,14 +29,14 @@ class StorageConfigTest extends \Test\TestCase {
$backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
->disableOriginalConstructor()
->getMock();
- $backend->method('getClass')
- ->willReturn('\OC\Files\Storage\SMB');
+ $backend->method('getIdentifier')
+ ->willReturn('storage::identifier');
$authMech = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism')
->disableOriginalConstructor()
->getMock();
- $authMech->method('getClass')
- ->willReturn('\Auth\Mechanism');
+ $authMech->method('getIdentifier')
+ ->willReturn('auth::identifier');
$storageConfig = new StorageConfig(1);
$storageConfig->setMountPoint('test');
@@ -52,8 +52,8 @@ class StorageConfigTest extends \Test\TestCase {
$this->assertEquals(1, $json['id']);
$this->assertEquals('/test', $json['mountPoint']);
- $this->assertEquals('\OC\Files\Storage\SMB', $json['backendClass']);
- $this->assertEquals('\Auth\Mechanism', $json['authMechanismClass']);
+ $this->assertEquals('storage::identifier', $json['backend']);
+ $this->assertEquals('auth::identifier', $json['authMechanism']);
$this->assertEquals('test', $json['backendOptions']['user']);
$this->assertEquals('password123', $json['backendOptions']['password']);
$this->assertEquals(128, $json['priority']);