data-id="">
-
-
-
+
|
|
- |
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see .
+ *
+ */
+namespace OCA\Files_external\Tests\Controller;
+
+use \OCA\Files_external\Controller\GlobalStoragesController;
+use \OCA\Files_external\Service\GlobalStoragesService;
+use \OCP\AppFramework\Http;
+use \OCA\Files_external\NotFoundException;
+
+class GlobalStoragesControllerTest extends StoragesControllerTest {
+ public function setUp() {
+ parent::setUp();
+ $this->service = $this->getMock('\OCA\Files_external\Service\GlobalStoragesService');
+
+ $this->controller = new GlobalStoragesController(
+ 'files_external',
+ $this->getMock('\OCP\IRequest'),
+ $this->getMock('\OCP\IL10N'),
+ $this->service
+ );
+ }
+}
diff --git a/apps/files_external/tests/controller/storagescontrollertest.php b/apps/files_external/tests/controller/storagescontrollertest.php
new file mode 100644
index 00000000000..853b4a86f03
--- /dev/null
+++ b/apps/files_external/tests/controller/storagescontrollertest.php
@@ -0,0 +1,225 @@
+
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see .
+ *
+ */
+namespace OCA\Files_external\Tests\Controller;
+
+use \OCP\AppFramework\Http;
+
+use \OCA\Files_external\Controller\GlobalStoragesController;
+use \OCA\Files_external\Service\GlobalStoragesService;
+use \OCA\Files_external\Lib\StorageConfig;
+use \OCA\Files_external\NotFoundException;
+
+abstract class StoragesControllerTest extends \Test\TestCase {
+
+ /**
+ * @var GlobalStoragesController
+ */
+ protected $controller;
+
+ /**
+ * @var GlobalStoragesService
+ */
+ protected $service;
+
+ public function setUp() {
+ \OC_Mount_Config::$skipTest = true;
+ }
+
+ public function tearDown() {
+ \OC_Mount_Config::$skipTest = false;
+ }
+
+ public function testAddStorage() {
+ $storageConfig = new StorageConfig(1);
+ $storageConfig->setMountPoint('mount');
+
+ $this->service->expects($this->once())
+ ->method('addStorage')
+ ->will($this->returnValue($storageConfig));
+
+ $response = $this->controller->create(
+ 'mount',
+ '\OC\Files\Storage\SMB',
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $data = $response->getData();
+ $this->assertEquals($storageConfig, $data);
+ $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
+ }
+
+ public function testUpdateStorage() {
+ $storageConfig = new StorageConfig(1);
+ $storageConfig->setMountPoint('mount');
+
+ $this->service->expects($this->once())
+ ->method('updateStorage')
+ ->will($this->returnValue($storageConfig));
+
+ $response = $this->controller->update(
+ 1,
+ 'mount',
+ '\OC\Files\Storage\SMB',
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $data = $response->getData();
+ $this->assertEquals($storageConfig, $data);
+ $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ }
+
+ function mountPointNamesProvider() {
+ return array(
+ array(''),
+ array('/'),
+ array('//'),
+ );
+ }
+
+ /**
+ * @dataProvider mountPointNamesProvider
+ */
+ public function testAddOrUpdateStorageInvalidMountPoint($mountPoint) {
+ $this->service->expects($this->never())
+ ->method('addStorage');
+ $this->service->expects($this->never())
+ ->method('updateStorage');
+
+ $response = $this->controller->create(
+ $mountPoint,
+ '\OC\Files\Storage\SMB',
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
+
+ $response = $this->controller->update(
+ 1,
+ $mountPoint,
+ '\OC\Files\Storage\SMB',
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
+ }
+
+ public function testAddOrUpdateStorageInvalidBackend() {
+ $this->service->expects($this->never())
+ ->method('addStorage');
+ $this->service->expects($this->never())
+ ->method('updateStorage');
+
+ $response = $this->controller->create(
+ 'mount',
+ '\OC\Files\Storage\InvalidStorage',
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
+
+ $response = $this->controller->update(
+ 1,
+ 'mount',
+ '\OC\Files\Storage\InvalidStorage',
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
+ }
+
+ public function testUpdateStorageNonExisting() {
+ $this->service->expects($this->once())
+ ->method('updateStorage')
+ ->will($this->throwException(new NotFoundException()));
+
+ $response = $this->controller->update(
+ 255,
+ 'mount',
+ '\OC\Files\Storage\SMB',
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+ }
+
+ public function testDeleteStorage() {
+ $this->service->expects($this->once())
+ ->method('removeStorage');
+
+ $response = $this->controller->destroy(1);
+ $this->assertEquals(Http::STATUS_NO_CONTENT, $response->getStatus());
+ }
+
+ public function testDeleteStorageNonExisting() {
+ $this->service->expects($this->once())
+ ->method('removeStorage')
+ ->will($this->throwException(new NotFoundException()));
+
+ $response = $this->controller->destroy(255);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+ }
+
+ public function testGetStorage() {
+ $storageConfig = new StorageConfig(1);
+ $storageConfig->setMountPoint('test');
+ $storageConfig->setBackendClass('\OC\Files\Storage\SMB');
+ $storageConfig->setBackendOptions(['user' => 'test', 'password', 'password123']);
+ $storageConfig->setMountOptions(['priority' => false]);
+
+ $this->service->expects($this->once())
+ ->method('getStorage')
+ ->with(1)
+ ->will($this->returnValue($storageConfig));
+ $response = $this->controller->show(1);
+
+ $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ $this->assertEquals($storageConfig, $response->getData());
+ }
+}
diff --git a/apps/files_external/tests/controller/userstoragescontrollertest.php b/apps/files_external/tests/controller/userstoragescontrollertest.php
new file mode 100644
index 00000000000..0ba413f6959
--- /dev/null
+++ b/apps/files_external/tests/controller/userstoragescontrollertest.php
@@ -0,0 +1,114 @@
+
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see .
+ *
+ */
+namespace OCA\Files_external\Tests\Controller;
+
+use \OCA\Files_external\Controller\UserStoragesController;
+use \OCA\Files_external\Service\UserStoragesService;
+use \OCP\AppFramework\Http;
+use \OCA\Files_external\NotFoundException;
+
+class UserStoragesControllerTest extends StoragesControllerTest {
+
+ /**
+ * @var array
+ */
+ private $oldAllowedBackends;
+
+ public function setUp() {
+ parent::setUp();
+ $this->service = $this->getMockBuilder('\OCA\Files_external\Service\UserStoragesService')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->controller = new UserStoragesController(
+ 'files_external',
+ $this->getMock('\OCP\IRequest'),
+ $this->getMock('\OCP\IL10N'),
+ $this->service
+ );
+
+ $config = \OC::$server->getConfig();
+
+ $this->oldAllowedBackends = $config->getAppValue(
+ 'files_external',
+ 'user_mounting_backends',
+ ''
+ );
+ $config->setAppValue(
+ 'files_external',
+ 'user_mounting_backends',
+ '\OC\Files\Storage\SMB'
+ );
+ }
+
+ public function tearDown() {
+ $config = \OC::$server->getConfig();
+ $config->setAppValue(
+ 'files_external',
+ 'user_mounting_backends',
+ $this->oldAllowedBackends
+ );
+ parent::tearDown();
+ }
+
+ function disallowedBackendClassProvider() {
+ return array(
+ array('\OC\Files\Storage\Local'),
+ array('\OC\Files\Storage\FTP'),
+ );
+ }
+ /**
+ * @dataProvider disallowedBackendClassProvider
+ */
+ public function testAddOrUpdateStorageDisallowedBackend($backendClass) {
+ $this->service->expects($this->never())
+ ->method('addStorage');
+ $this->service->expects($this->never())
+ ->method('updateStorage');
+
+ $response = $this->controller->create(
+ 'mount',
+ $backendClass,
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
+
+ $response = $this->controller->update(
+ 1,
+ 'mount',
+ $backendClass,
+ array(),
+ [],
+ [],
+ [],
+ null
+ );
+
+ $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
+ }
+
+}
diff --git a/apps/files_external/tests/js/settingsSpec.js b/apps/files_external/tests/js/settingsSpec.js
new file mode 100644
index 00000000000..5a3ee2cb5f1
--- /dev/null
+++ b/apps/files_external/tests/js/settingsSpec.js
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2015 Vincent Petry
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+describe('OCA.External.Settings tests', function() {
+ var clock;
+ var select2Stub;
+ var select2ApplicableUsers;
+
+ beforeEach(function() {
+ clock = sinon.useFakeTimers();
+ select2Stub = sinon.stub($.fn, 'select2', function(args) {
+ if (args === 'val') {
+ return select2ApplicableUsers;
+ }
+ return {
+ on: function() {}
+ };
+ });
+
+ // view still requires an existing DOM table
+ $('#testArea').append(
+ ''
+ );
+ // these are usually appended into the data attribute
+ // within the DOM by the server template
+ $('#externalStorage .selectBackend:first').data('configurations', {
+ '\\OC\\TestBackend': {
+ 'backend': 'Test Backend Name',
+ 'configuration': {
+ 'field1': 'Display Name 1',
+ 'field2': '&Display Name 2'
+ },
+ 'priority': 11
+ },
+ '\\OC\\AnotherTestBackend': {
+ 'backend': 'Another Test Backend Name',
+ 'configuration': {
+ 'field1': 'Display Name 1',
+ 'field2': '&Display Name 2'
+ },
+ 'priority': 12
+ }
+ }
+ );
+ });
+ afterEach(function() {
+ select2Stub.restore();
+ clock.restore();
+ });
+
+ describe('storage configuration', function() {
+ var view;
+
+ function selectBackend(backendName) {
+ view.$el.find('.selectBackend:first').val('\\OC\\TestBackend').trigger('change');
+ }
+
+ beforeEach(function() {
+ var $el = $('#externalStorage');
+ view = new OCA.External.Settings.MountConfigListView($el);
+ });
+ afterEach(function() {
+ view = null;
+ });
+ describe('selecting backend', function() {
+ it('populates the row and creates a new empty one', function() {
+ var $firstRow = view.$el.find('tr:first');
+ selectBackend('\\OC\\TestBackend');
+ expect($firstRow.find('.backend').text()).toEqual('Test Backend');
+ expect($firstRow.find('.selectBackend').length).toEqual(0);
+
+ // TODO: check "remove" button visibility
+
+ // the suggested mount point name
+ expect($firstRow.find('[name=mountPoint]').val()).toEqual('TestBackend');
+
+ // TODO: check that the options have been created
+
+ // TODO: check select2 call on the ".applicableUsers" element
+
+ var $emptyRow = $firstRow.next('tr');
+ expect($emptyRow.length).toEqual(1);
+ expect($emptyRow.find('.selectBackend').length).toEqual(1);
+ expect($emptyRow.find('.applicable select').length).toEqual(0);
+
+ // TODO: check "remove" button visibility
+ });
+ // TODO: test with personal mounts (no applicable fields)
+ // TODO: test suggested mount point logic
+ });
+ describe('saving storages', function() {
+ it('saves storage after editing config', function() {
+ var $tr = view.$el.find('tr:first');
+ selectBackend('\\OC\\TestBackend');
+
+ var $field1 = $tr.find('input[data-parameter=field1]');
+ expect($field1.length).toEqual(1);
+ $field1.val('test');
+ $field1.trigger(new $.Event('keyup', {keyCode: 97}));
+
+ clock.tick(4000);
+
+ expect(fakeServer.requests.length).toEqual(1);
+ var request = fakeServer.requests[0];
+ expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_external/globalstorages');
+ expect(OC.parseQueryString(request.requestBody)).toEqual({
+ backendClass: '\\OC\\TestBackend',
+ 'backendOptions[field1]': 'test',
+ 'backendOptions[field2]': '',
+ mountPoint: 'TestBackend',
+ priority: '11'
+ });
+
+ // TODO: respond and check data-id
+ });
+ // TODO: tests with "applicableUsers" and "applicableGroups"
+ // TODO: test with non-optional config parameters
+ // TODO: test with missing mount point value
+ // TODO: test with personal mounts (no applicable fields)
+ // TODO: test save triggers: paste, keyup, checkbox
+ // TODO: test "custom" field with addScript
+ // TODO: status indicator
+ });
+ describe('update storage', function() {
+ // TODO
+ });
+ describe('delete storage', function() {
+ // TODO
+ });
+ describe('recheck storages', function() {
+ // TODO
+ });
+ });
+ describe('applicable user list', function() {
+ // TODO: test select2 retrieval logic
+ });
+ describe('allow user mounts section', function() {
+ // TODO: test allowUserMounting section
+ });
+});
diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php
index f00812c5671..645f0c64e11 100644
--- a/apps/files_external/tests/mountconfig.php
+++ b/apps/files_external/tests/mountconfig.php
@@ -252,7 +252,7 @@ class Test_Mount_Config extends \Test\TestCase {
'password' => '12345',
);
- $this->assertEquals(true, OC_Mount_Config::addMountPoint('/ext', 'Test_Mount_Config_Dummy_Storage', $storageOptions, $mountType, $applicable, $isPersonal));
+ $this->assertEquals(0, OC_Mount_Config::addMountPoint('/ext', 'Test_Mount_Config_Dummy_Storage', $storageOptions, $mountType, $applicable, $isPersonal));
$config = $this->readGlobalConfig();
$this->assertEquals(1, count($config));
@@ -279,7 +279,7 @@ class Test_Mount_Config extends \Test\TestCase {
'password' => '12345',
);
- $this->assertEquals(true, OC_Mount_Config::addMountPoint('/ext', 'Test_Mount_Config_Dummy_Storage', $storageOptions, $mountType, $applicable, $isPersonal));
+ $this->assertEquals(0, OC_Mount_Config::addMountPoint('/ext', 'Test_Mount_Config_Dummy_Storage', $storageOptions, $mountType, $applicable, $isPersonal));
$config = $this->readUserConfig();
$this->assertEquals(1, count($config));
@@ -382,7 +382,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// write config
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -422,7 +423,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// write config
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -459,7 +461,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// write config
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
$mountPoint,
'Test_Mount_Config_Dummy_Storage',
@@ -492,7 +495,8 @@ class Test_Mount_Config extends \Test\TestCase {
// edit
$mountConfig['host'] = 'anothersmbhost';
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
$mountPoint,
'Test_Mount_Config_Dummy_Storage',
@@ -557,7 +561,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// write config
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -598,7 +603,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// write config
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -707,7 +713,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// add mount point as "test" user
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -750,7 +757,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// write config
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -761,7 +769,8 @@ class Test_Mount_Config extends \Test\TestCase {
)
);
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -772,7 +781,8 @@ class Test_Mount_Config extends \Test\TestCase {
)
);
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -783,7 +793,8 @@ class Test_Mount_Config extends \Test\TestCase {
)
);
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -821,7 +832,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// write config
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -839,7 +851,8 @@ class Test_Mount_Config extends \Test\TestCase {
'share' => 'anothersmbshare',
'root' => 'anothersmbroot'
);
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -952,7 +965,8 @@ class Test_Mount_Config extends \Test\TestCase {
// Add mount points
foreach($mounts as $i => $mount) {
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -987,7 +1001,8 @@ class Test_Mount_Config extends \Test\TestCase {
'share' => '',
);
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
$class,
@@ -1005,7 +1020,8 @@ class Test_Mount_Config extends \Test\TestCase {
$mountPoints['/'.self::TEST_USER1.'/files/ext']['priority']);
// Simulate changed mount options (without priority set)
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
$class,
@@ -1035,7 +1051,8 @@ class Test_Mount_Config extends \Test\TestCase {
);
// Create personal mount point
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
'Test_Mount_Config_Dummy_Storage',
@@ -1066,7 +1083,8 @@ class Test_Mount_Config extends \Test\TestCase {
$applicable = 'all';
$isPersonal = false;
- $this->assertTrue(
+ $this->assertEquals(
+ 0,
OC_Mount_Config::addMountPoint(
'/ext',
$storageClass,
diff --git a/apps/files_external/tests/service/globalstoragesservicetest.php b/apps/files_external/tests/service/globalstoragesservicetest.php
new file mode 100644
index 00000000000..4c038bc489e
--- /dev/null
+++ b/apps/files_external/tests/service/globalstoragesservicetest.php
@@ -0,0 +1,815 @@
+
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see .
+ *
+ */
+namespace OCA\Files_external\Tests\Service;
+
+use \OC\Files\Filesystem;
+
+use \OCA\Files_external\Service\GlobalStoragesService;
+use \OCA\Files_external\NotFoundException;
+use \OCA\Files_external\Lib\StorageConfig;
+
+class GlobalStoragesServiceTest extends StoragesServiceTest {
+ public function setUp() {
+ parent::setUp();
+ $this->service = new GlobalStoragesService();
+ }
+
+ public function tearDown() {
+ @unlink($this->dataDir . '/mount.json');
+ parent::tearDown();
+ }
+
+ protected function makeTestStorageData() {
+ return $this->makeStorageConfig([
+ 'mountPoint' => 'mountpoint',
+ 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendOptions' => [
+ 'option1' => 'value1',
+ 'option2' => 'value2',
+ 'password' => 'testPassword',
+ ],
+ 'applicableUsers' => [],
+ 'applicableGroups' => [],
+ 'priority' => 15,
+ 'mountOptions' => [
+ 'preview' => false,
+ ]
+ ]);
+ }
+
+ function storageDataProvider() {
+ return [
+ // all users
+ [
+ $this->makeStorageConfig([
+ 'mountPoint' => 'mountpoint',
+ 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendOptions' => [
+ 'option1' => 'value1',
+ 'option2' => 'value2',
+ 'password' => 'testPassword',
+ ],
+ 'applicableUsers' => [],
+ 'applicableGroups' => [],
+ 'priority' => 15,
+ ]),
+ ],
+ // some users
+ [
+ $this->makeStorageConfig([
+ 'mountPoint' => 'mountpoint',
+ 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendOptions' => [
+ 'option1' => 'value1',
+ 'option2' => 'value2',
+ 'password' => 'testPassword',
+ ],
+ 'applicableUsers' => ['user1', 'user2'],
+ 'applicableGroups' => [],
+ 'priority' => 15,
+ ]),
+ ],
+ // some groups
+ [
+ $this->makeStorageConfig([
+ 'mountPoint' => 'mountpoint',
+ 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendOptions' => [
+ 'option1' => 'value1',
+ 'option2' => 'value2',
+ 'password' => 'testPassword',
+ ],
+ 'applicableUsers' => [],
+ 'applicableGroups' => ['group1', 'group2'],
+ 'priority' => 15,
+ ]),
+ ],
+ // both users and groups
+ [
+ $this->makeStorageConfig([
+ 'mountPoint' => 'mountpoint',
+ 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendOptions' => [
+ 'option1' => 'value1',
+ 'option2' => 'value2',
+ 'password' => 'testPassword',
+ ],
+ 'applicableUsers' => ['user1', 'user2'],
+ 'applicableGroups' => ['group1', 'group2'],
+ 'priority' => 15,
+ ]),
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider storageDataProvider
+ */
+ public function testAddStorage($storage) {
+ $newStorage = $this->service->addStorage($storage);
+
+ $this->assertEquals(1, $newStorage->getId());
+
+
+ $newStorage = $this->service->getStorage(1);
+
+ $this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
+ $this->assertEquals($storage->getBackendClass(), $newStorage->getBackendClass());
+ $this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
+ $this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers());
+ $this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups());
+ $this->assertEquals($storage->getPriority(), $newStorage->getPriority());
+ $this->assertEquals(1, $newStorage->getId());
+ $this->assertEquals(0, $newStorage->getStatus());
+
+ // next one gets id 2
+ $nextStorage = $this->service->addStorage($storage);
+ $this->assertEquals(2, $nextStorage->getId());
+ }
+
+ /**
+ * @dataProvider storageDataProvider
+ */
+ public function testUpdateStorage($updatedStorage) {
+ $storage = $this->makeStorageConfig([
+ 'mountPoint' => 'mountpoint',
+ 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendOptions' => [
+ 'option1' => 'value1',
+ 'option2' => 'value2',
+ 'password' => 'testPassword',
+ ],
+ 'applicableUsers' => [],
+ 'applicableGroups' => [],
+ 'priority' => 15,
+ ]);
+
+ $newStorage = $this->service->addStorage($storage);
+ $this->assertEquals(1, $newStorage->getId());
+
+ $updatedStorage->setId(1);
+
+ $this->service->updateStorage($updatedStorage);
+ $newStorage = $this->service->getStorage(1);
+
+ $this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint());
+ $this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']);
+ $this->assertEquals($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
+ $this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups());
+ $this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority());
+ $this->assertEquals(1, $newStorage->getId());
+ $this->assertEquals(0, $newStorage->getStatus());
+ }
+
+ function hooksAddStorageDataProvider() {
+ return [
+ // applicable all
+ [
+ [],
+ [],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'all'
+ ],
+ ],
+ ],
+ // single user
+ [
+ ['user1'],
+ [],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user1',
+ ],
+ ],
+ ],
+ // single group
+ [
+ [],
+ ['group1'],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group1',
+ ],
+ ],
+ ],
+ // multiple users
+ [
+ ['user1', 'user2'],
+ [],
+ [
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user1',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user2',
+ ],
+ ],
+ ],
+ // multiple groups
+ [
+ [],
+ ['group1', 'group2'],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group1'
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group2'
+ ],
+ ],
+ ],
+ // mixed groups and users
+ [
+ ['user1', 'user2'],
+ ['group1', 'group2'],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user1',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user2',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group1'
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group2'
+ ],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider hooksAddStorageDataProvider
+ */
+ public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls) {
+ $storage = $this->makeTestStorageData();
+ $storage->setApplicableUsers($applicableUsers);
+ $storage->setApplicableGroups($applicableGroups);
+ $this->service->addStorage($storage);
+
+ $this->assertCount(count($expectedCalls), self::$hookCalls);
+
+ foreach ($expectedCalls as $index => $call) {
+ $this->assertHookCall(
+ self::$hookCalls[$index],
+ $call[0],
+ $storage->getMountPoint(),
+ $call[1],
+ $call[2]
+ );
+ }
+ }
+
+ function hooksUpdateStorageDataProvider() {
+ return [
+ [
+ // nothing to multiple users and groups
+ [],
+ [],
+ ['user1', 'user2'],
+ ['group1', 'group2'],
+ // expected hook calls
+ [
+ // delete the "all entry"
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'all',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user1',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user2',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group1'
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group2'
+ ],
+ ],
+ ],
+ [
+ // adding a user and a group
+ ['user1'],
+ ['group1'],
+ ['user1', 'user2'],
+ ['group1', 'group2'],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user2',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group2'
+ ],
+ ],
+ ],
+ [
+ // removing a user and a group
+ ['user1', 'user2'],
+ ['group1', 'group2'],
+ ['user1'],
+ ['group1'],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user2',
+ ],
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group2'
+ ],
+ ],
+ ],
+ [
+ // removing all
+ ['user1'],
+ ['group1'],
+ [],
+ [],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user1',
+ ],
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group1'
+ ],
+ // create the "all" entry
+ [
+ Filesystem::signal_create_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'all'
+ ],
+ ],
+ ],
+ [
+ // no changes
+ ['user1'],
+ ['group1'],
+ ['user1'],
+ ['group1'],
+ // no hook calls
+ []
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider hooksUpdateStorageDataProvider
+ */
+ public function testHooksUpdateStorage(
+ $sourceApplicableUsers,
+ $sourceApplicableGroups,
+ $updatedApplicableUsers,
+ $updatedApplicableGroups,
+ $expectedCalls) {
+
+ $storage = $this->makeTestStorageData();
+ $storage->setApplicableUsers($sourceApplicableUsers);
+ $storage->setApplicableGroups($sourceApplicableGroups);
+ $storage = $this->service->addStorage($storage);
+
+ $storage->setapplicableUsers($updatedApplicableUsers);
+ $storage->setapplicableGroups($updatedApplicableGroups);
+
+ // reset calls
+ self::$hookCalls = [];
+
+ $this->service->updateStorage($storage);
+
+ $this->assertCount(count($expectedCalls), self::$hookCalls);
+
+ foreach ($expectedCalls as $index => $call) {
+ $this->assertHookCall(
+ self::$hookCalls[$index],
+ $call[0],
+ '/mountpoint',
+ $call[1],
+ $call[2]
+ );
+ }
+ }
+
+ /**
+ */
+ public function testHooksRenameMountPoint() {
+ $storage = $this->makeTestStorageData();
+ $storage->setApplicableUsers(['user1', 'user2']);
+ $storage->setApplicableGroups(['group1', 'group2']);
+ $storage = $this->service->addStorage($storage);
+
+ $storage->setMountPoint('renamedMountpoint');
+
+ // reset calls
+ self::$hookCalls = [];
+
+ $this->service->updateStorage($storage);
+
+ $expectedCalls = [
+ // deletes old mount
+ [
+ Filesystem::signal_delete_mount,
+ '/mountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user1',
+ ],
+ [
+ Filesystem::signal_delete_mount,
+ '/mountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user2',
+ ],
+ [
+ Filesystem::signal_delete_mount,
+ '/mountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group1',
+ ],
+ [
+ Filesystem::signal_delete_mount,
+ '/mountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group2',
+ ],
+ // creates new one
+ [
+ Filesystem::signal_create_mount,
+ '/renamedMountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user1',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ '/renamedMountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user2',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ '/renamedMountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group1',
+ ],
+ [
+ Filesystem::signal_create_mount,
+ '/renamedMountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group2',
+ ],
+ ];
+
+ $this->assertCount(count($expectedCalls), self::$hookCalls);
+
+ foreach ($expectedCalls as $index => $call) {
+ $this->assertHookCall(
+ self::$hookCalls[$index],
+ $call[0],
+ $call[1],
+ $call[2],
+ $call[3]
+ );
+ }
+ }
+
+ function hooksDeleteStorageDataProvider() {
+ return [
+ [
+ ['user1', 'user2'],
+ ['group1', 'group2'],
+ // expected hook calls
+ [
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user1',
+ ],
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'user2',
+ ],
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group1'
+ ],
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_GROUP,
+ 'group2'
+ ],
+ ],
+ ],
+ [
+ // deleting "all" entry
+ [],
+ [],
+ [
+ [
+ Filesystem::signal_delete_mount,
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ 'all',
+ ],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider hooksDeleteStorageDataProvider
+ */
+ public function testHooksDeleteStorage(
+ $sourceApplicableUsers,
+ $sourceApplicableGroups,
+ $expectedCalls) {
+
+ $storage = $this->makeTestStorageData();
+ $storage->setApplicableUsers($sourceApplicableUsers);
+ $storage->setApplicableGroups($sourceApplicableGroups);
+ $storage = $this->service->addStorage($storage);
+
+ // reset calls
+ self::$hookCalls = [];
+
+ $this->service->removeStorage($storage->getId());
+
+ $this->assertCount(count($expectedCalls), self::$hookCalls);
+
+ foreach ($expectedCalls as $index => $call) {
+ $this->assertHookCall(
+ self::$hookCalls[$index],
+ $call[0],
+ '/mountpoint',
+ $call[1],
+ $call[2]
+ );
+ }
+ }
+
+ /**
+ * Make sure it uses the correct format when reading/writing
+ * the legacy config
+ */
+ public function testLegacyConfigConversionApplicableAll() {
+ $configFile = $this->dataDir . '/mount.json';
+
+ $storage = $this->makeTestStorageData();
+ $storage = $this->service->addStorage($storage);
+
+ $json = json_decode(file_get_contents($configFile), true);
+
+ $this->assertCount(1, $json);
+
+ $this->assertEquals([\OC_Mount_Config::MOUNT_TYPE_USER], array_keys($json));
+ $this->assertEquals(['all'], array_keys($json[\OC_Mount_config::MOUNT_TYPE_USER]));
+
+ $mountPointData = $json[\OC_Mount_config::MOUNT_TYPE_USER]['all'];
+ $this->assertEquals(['/$user/files/mountpoint'], array_keys($mountPointData));
+
+ $mountPointOptions = current($mountPointData);
+ $this->assertEquals(1, $mountPointOptions['id']);
+ $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
+ $this->assertEquals(15, $mountPointOptions['priority']);
+ $this->assertEquals(false, $mountPointOptions['mountOptions']['preview']);
+
+ $backendOptions = $mountPointOptions['options'];
+ $this->assertEquals('value1', $backendOptions['option1']);
+ $this->assertEquals('value2', $backendOptions['option2']);
+ $this->assertEquals('', $backendOptions['password']);
+ $this->assertNotEmpty($backendOptions['password_encrypted']);
+ }
+
+ /**
+ * Make sure it uses the correct format when reading/writing
+ * the legacy config
+ */
+ public function testLegacyConfigConversionApplicableUserAndGroup() {
+ $configFile = $this->dataDir . '/mount.json';
+
+ $storage = $this->makeTestStorageData();
+ $storage->setApplicableUsers(['user1', 'user2']);
+ $storage->setApplicableGroups(['group1', 'group2']);
+
+ $storage = $this->service->addStorage($storage);
+
+ $json = json_decode(file_get_contents($configFile), true);
+
+ $this->assertCount(2, $json);
+
+ $this->assertTrue(isset($json[\OC_Mount_Config::MOUNT_TYPE_USER]));
+ $this->assertTrue(isset($json[\OC_Mount_Config::MOUNT_TYPE_GROUP]));
+ $this->assertEquals(['user1', 'user2'], array_keys($json[\OC_Mount_config::MOUNT_TYPE_USER]));
+ $this->assertEquals(['group1', 'group2'], array_keys($json[\OC_Mount_config::MOUNT_TYPE_GROUP]));
+
+ // check that all options are the same for both users and both groups
+ foreach ($json[\OC_Mount_Config::MOUNT_TYPE_USER] as $mountPointData) {
+ $this->assertEquals(['/$user/files/mountpoint'], array_keys($mountPointData));
+
+ $mountPointOptions = current($mountPointData);
+
+ $this->assertEquals(1, $mountPointOptions['id']);
+ $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
+ $this->assertEquals(15, $mountPointOptions['priority']);
+ $this->assertEquals(false, $mountPointOptions['mountOptions']['preview']);
+
+ $backendOptions = $mountPointOptions['options'];
+ $this->assertEquals('value1', $backendOptions['option1']);
+ $this->assertEquals('value2', $backendOptions['option2']);
+ $this->assertEquals('', $backendOptions['password']);
+ $this->assertNotEmpty($backendOptions['password_encrypted']);
+ }
+
+ foreach ($json[\OC_Mount_Config::MOUNT_TYPE_GROUP] as $mountPointData) {
+ $this->assertEquals(['/$user/files/mountpoint'], array_keys($mountPointData));
+
+ $mountPointOptions = current($mountPointData);
+
+ $this->assertEquals(1, $mountPointOptions['id']);
+ $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
+ $this->assertEquals(15, $mountPointOptions['priority']);
+ $this->assertEquals(false, $mountPointOptions['mountOptions']['preview']);
+
+ $backendOptions = $mountPointOptions['options'];
+ $this->assertEquals('value1', $backendOptions['option1']);
+ $this->assertEquals('value2', $backendOptions['option2']);
+ $this->assertEquals('', $backendOptions['password']);
+ $this->assertNotEmpty($backendOptions['password_encrypted']);
+ }
+ }
+
+ /**
+ * Test reading in a legacy config and generating config ids.
+ */
+ public function testReadLegacyConfigAndGenerateConfigId() {
+ $configFile = $this->dataDir . '/mount.json';
+
+ $legacyBackendOptions = [
+ 'user' => 'someuser',
+ 'password' => 'somepassword',
+ ];
+ $legacyBackendOptions = \OC_Mount_Config::encryptPasswords($legacyBackendOptions);
+
+ $legacyConfig = [
+ 'class' => '\OC\Files\Storage\SMB',
+ 'options' => $legacyBackendOptions,
+ 'mountOptions' => ['preview' => false],
+ ];
+ // different mount options
+ $legacyConfig2 = [
+ 'class' => '\OC\Files\Storage\SMB',
+ 'options' => $legacyBackendOptions,
+ 'mountOptions' => ['preview' => true],
+ ];
+
+ $legacyBackendOptions2 = $legacyBackendOptions;
+ $legacyBackendOptions2 = ['user' => 'someuser2', 'password' => 'somepassword2'];
+ $legacyBackendOptions2 = \OC_Mount_Config::encryptPasswords($legacyBackendOptions2);
+
+ // different config
+ $legacyConfig3 = [
+ 'class' => '\OC\Files\Storage\SMB',
+ 'options' => $legacyBackendOptions2,
+ 'mountOptions' => ['preview' => true],
+ ];
+
+ $json = [
+ 'user' => [
+ 'user1' => [
+ '/$user/files/somemount' => $legacyConfig,
+ ],
+ // same config
+ 'user2' => [
+ '/$user/files/somemount' => $legacyConfig,
+ ],
+ // different mountOptions
+ 'user3' => [
+ '/$user/files/somemount' => $legacyConfig2,
+ ],
+ // different mount point
+ 'user4' => [
+ '/$user/files/anothermount' => $legacyConfig,
+ ],
+ // different storage config
+ 'user5' => [
+ '/$user/files/somemount' => $legacyConfig3,
+ ],
+ ],
+ 'group' => [
+ 'group1' => [
+ // will get grouped with user configs
+ '/$user/files/somemount' => $legacyConfig,
+ ],
+ ],
+ ];
+
+ file_put_contents($configFile, json_encode($json));
+
+ $allStorages = $this->service->getAllStorages();
+
+ $this->assertCount(4, $allStorages);
+
+ $storage1 = $allStorages[1];
+ $storage2 = $allStorages[2];
+ $storage3 = $allStorages[3];
+ $storage4 = $allStorages[4];
+
+ $this->assertEquals('/somemount', $storage1->getMountPoint());
+ $this->assertEquals('someuser', $storage1->getBackendOptions()['user']);
+ $this->assertEquals('somepassword', $storage1->getBackendOptions()['password']);
+ $this->assertEquals(['user1', 'user2'], $storage1->getApplicableUsers());
+ $this->assertEquals(['group1'], $storage1->getApplicableGroups());
+ $this->assertEquals(['preview' => false], $storage1->getMountOptions());
+
+ $this->assertEquals('/somemount', $storage2->getMountPoint());
+ $this->assertEquals('someuser', $storage2->getBackendOptions()['user']);
+ $this->assertEquals('somepassword', $storage2->getBackendOptions()['password']);
+ $this->assertEquals(['user3'], $storage2->getApplicableUsers());
+ $this->assertEquals([], $storage2->getApplicableGroups());
+ $this->assertEquals(['preview' => true], $storage2->getMountOptions());
+
+ $this->assertEquals('/anothermount', $storage3->getMountPoint());
+ $this->assertEquals('someuser', $storage3->getBackendOptions()['user']);
+ $this->assertEquals('somepassword', $storage3->getBackendOptions()['password']);
+ $this->assertEquals(['user4'], $storage3->getApplicableUsers());
+ $this->assertEquals([], $storage3->getApplicableGroups());
+ $this->assertEquals(['preview' => false], $storage3->getMountOptions());
+
+ $this->assertEquals('/somemount', $storage4->getMountPoint());
+ $this->assertEquals('someuser2', $storage4->getBackendOptions()['user']);
+ $this->assertEquals('somepassword2', $storage4->getBackendOptions()['password']);
+ $this->assertEquals(['user5'], $storage4->getApplicableUsers());
+ $this->assertEquals([], $storage4->getApplicableGroups());
+ $this->assertEquals(['preview' => true], $storage4->getMountOptions());
+ }
+}
diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php
new file mode 100644
index 00000000000..445e86d4117
--- /dev/null
+++ b/apps/files_external/tests/service/storagesservicetest.php
@@ -0,0 +1,183 @@
+
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see .
+ *
+ */
+namespace OCA\Files_external\Tests\Service;
+
+use \OC\Files\Filesystem;
+
+use \OCA\Files_external\NotFoundException;
+use \OCA\Files_external\Lib\StorageConfig;
+
+abstract class StoragesServiceTest extends \Test\TestCase {
+
+ /**
+ * @var StoragesService
+ */
+ protected $service;
+
+ /**
+ * Data directory
+ *
+ * @var string
+ */
+ protected $dataDir;
+
+ /**
+ * Hook calls
+ *
+ * @var array
+ */
+ protected static $hookCalls;
+
+ public function setUp() {
+ self::$hookCalls = array();
+ $config = \OC::$server->getConfig();
+ $this->dataDir = $config->getSystemValue(
+ 'datadirectory',
+ \OC::$SERVERROOT . '/data/'
+ );
+ \OC_Mount_Config::$skipTest = true;
+
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_create_mount,
+ get_class($this), 'createHookCallback');
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_delete_mount,
+ get_class($this), 'deleteHookCallback');
+
+ }
+
+ public function tearDown() {
+ \OC_Mount_Config::$skipTest = false;
+ self::$hookCalls = array();
+ }
+
+ /**
+ * Creates a StorageConfig instance based on array data
+ *
+ * @param array data
+ *
+ * @return StorageConfig storage config instance
+ */
+ protected function makeStorageConfig($data) {
+ $storage = new StorageConfig();
+ if (isset($data['id'])) {
+ $storage->setId($data['id']);
+ }
+ $storage->setMountPoint($data['mountPoint']);
+ $storage->setBackendClass($data['backendClass']);
+ $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']);
+ }
+ if (isset($data['mountOptions'])) {
+ $storage->setMountOptions($data['mountOptions']);
+ }
+ return $storage;
+ }
+
+
+ /**
+ * @expectedException \OCA\Files_external\NotFoundException
+ */
+ public function testNonExistingStorage() {
+ $storage = new StorageConfig(255);
+ $storage->setMountPoint('mountpoint');
+ $storage->setBackendClass('\OC\Files\Storage\SMB');
+ $this->service->updateStorage($storage);
+ }
+
+ public function testDeleteStorage() {
+ $storage = new StorageConfig(255);
+ $storage->setMountPoint('mountpoint');
+ $storage->setBackendClass('\OC\Files\Storage\SMB');
+ $storage->setBackendOptions(['password' => 'testPassword']);
+
+ $newStorage = $this->service->addStorage($storage);
+ $this->assertEquals(1, $newStorage->getId());
+
+ $newStorage = $this->service->removeStorage(1);
+
+ $caught = false;
+ try {
+ $this->service->getStorage(1);
+ } catch (NotFoundException $e) {
+ $caught = true;
+ }
+
+ $this->assertTrue($caught);
+ }
+
+ /**
+ * @expectedException \OCA\Files_external\NotFoundException
+ */
+ public function testDeleteUnexistingStorage() {
+ $this->service->removeStorage(255);
+ }
+
+ public static function createHookCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_create_mount,
+ 'params' => $params
+ );
+ }
+
+ public static function deleteHookCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_delete_mount,
+ 'params' => $params
+ );
+ }
+
+ /**
+ * 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]
+ );
+ }
+}
diff --git a/apps/files_external/tests/service/userstoragesservicetest.php b/apps/files_external/tests/service/userstoragesservicetest.php
new file mode 100644
index 00000000000..dd3f9e1b92c
--- /dev/null
+++ b/apps/files_external/tests/service/userstoragesservicetest.php
@@ -0,0 +1,254 @@
+
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see .
+ *
+ */
+namespace OCA\Files_external\Tests\Service;
+
+use \OC\Files\Filesystem;
+
+use \OCA\Files_external\Service\UserStoragesService;
+use \OCA\Files_external\NotFoundException;
+use \OCA\Files_external\Lib\StorageConfig;
+
+class UserStoragesServiceTest extends StoragesServiceTest {
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->userId = $this->getUniqueID('user_');
+
+ $this->user = new \OC\User\User($this->userId, null);
+ $userSession = $this->getMock('\OCP\IUserSession');
+ $userSession
+ ->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+
+ $this->service = new UserStoragesService($userSession);
+
+ // create home folder
+ mkdir($this->dataDir . '/' . $this->userId . '/');
+ }
+
+ public function tearDown() {
+ @unlink($this->dataDir . '/' . $this->userId . '/mount.json');
+ parent::tearDown();
+ }
+
+ private function makeTestStorageData() {
+ return $this->makeStorageConfig([
+ 'mountPoint' => 'mountpoint',
+ 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendOptions' => [
+ 'option1' => 'value1',
+ 'option2' => 'value2',
+ 'password' => 'testPassword',
+ ],
+ 'mountOptions' => [
+ 'preview' => false,
+ ]
+ ]);
+ }
+
+ public function testAddStorage() {
+ $storage = $this->makeTestStorageData();
+
+ $newStorage = $this->service->addStorage($storage);
+
+ $this->assertEquals(1, $newStorage->getId());
+
+ $newStorage = $this->service->getStorage(1);
+
+ $this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
+ $this->assertEquals($storage->getBackendClass(), $newStorage->getBackendClass());
+ $this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
+ $this->assertEquals(1, $newStorage->getId());
+ $this->assertEquals(0, $newStorage->getStatus());
+
+ // hook called once for user
+ $this->assertHookCall(
+ current(self::$hookCalls),
+ Filesystem::signal_create_mount,
+ $storage->getMountPoint(),
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ $this->userId
+ );
+
+ // next one gets id 2
+ $nextStorage = $this->service->addStorage($storage);
+ $this->assertEquals(2, $nextStorage->getId());
+ }
+
+ public function testUpdateStorage() {
+ $storage = $this->makeStorageConfig([
+ 'mountPoint' => 'mountpoint',
+ 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendOptions' => [
+ 'option1' => 'value1',
+ 'option2' => 'value2',
+ 'password' => 'testPassword',
+ ],
+ ]);
+
+ $newStorage = $this->service->addStorage($storage);
+ $this->assertEquals(1, $newStorage->getId());
+
+ $backendOptions = $newStorage->getBackendOptions();
+ $backendOptions['password'] = 'anotherPassword';
+ $newStorage->setBackendOptions($backendOptions);
+
+ self::$hookCalls = [];
+
+ $newStorage = $this->service->updateStorage($newStorage);
+
+ $this->assertEquals('anotherPassword', $newStorage->getBackendOptions()['password']);
+ // these attributes are unused for user storages
+ $this->assertEmpty($newStorage->getApplicableUsers());
+ $this->assertEmpty($newStorage->getApplicableGroups());
+ $this->assertEquals(1, $newStorage->getId());
+ $this->assertEquals(0, $newStorage->getStatus());
+
+ // no hook calls
+ $this->assertEmpty(self::$hookCalls);
+ }
+
+ public function testDeleteStorage() {
+ parent::testDeleteStorage();
+
+ // hook called once for user (first one was during test creation)
+ $this->assertHookCall(
+ self::$hookCalls[1],
+ Filesystem::signal_delete_mount,
+ '/mountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ $this->userId
+ );
+ }
+
+ public function testHooksRenameMountPoint() {
+ $storage = $this->makeTestStorageData();
+ $storage = $this->service->addStorage($storage);
+
+ $storage->setMountPoint('renamedMountpoint');
+
+ // reset calls
+ self::$hookCalls = [];
+
+ $this->service->updateStorage($storage);
+
+ // hook called twice
+ $this->assertHookCall(
+ self::$hookCalls[0],
+ Filesystem::signal_delete_mount,
+ '/mountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ $this->userId
+ );
+ $this->assertHookCall(
+ self::$hookCalls[1],
+ Filesystem::signal_create_mount,
+ '/renamedMountpoint',
+ \OC_Mount_Config::MOUNT_TYPE_USER,
+ $this->userId
+ );
+ }
+
+ /**
+ * Make sure it uses the correct format when reading/writing
+ * the legacy config
+ */
+ public function testLegacyConfigConversion() {
+ $configFile = $this->dataDir . '/' . $this->userId . '/mount.json';
+
+ $storage = $this->makeTestStorageData();
+ $storage = $this->service->addStorage($storage);
+
+ $json = json_decode(file_get_contents($configFile), true);
+
+ $this->assertCount(1, $json);
+
+ $this->assertEquals([\OC_Mount_Config::MOUNT_TYPE_USER], array_keys($json));
+ $this->assertEquals([$this->userId], array_keys($json[\OC_Mount_config::MOUNT_TYPE_USER]));
+
+ $mountPointData = $json[\OC_Mount_config::MOUNT_TYPE_USER][$this->userId];
+ $this->assertEquals(['/' . $this->userId . '/files/mountpoint'], array_keys($mountPointData));
+
+ $mountPointOptions = current($mountPointData);
+ $this->assertEquals(1, $mountPointOptions['id']);
+ $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
+ $this->assertEquals(false, $mountPointOptions['mountOptions']['preview']);
+
+ $backendOptions = $mountPointOptions['options'];
+ $this->assertEquals('value1', $backendOptions['option1']);
+ $this->assertEquals('value2', $backendOptions['option2']);
+ $this->assertEquals('', $backendOptions['password']);
+ $this->assertNotEmpty($backendOptions['password_encrypted']);
+ }
+
+ /**
+ * Test reading in a legacy config and generating config ids.
+ */
+ public function testReadLegacyConfigAndGenerateConfigId() {
+ $configFile = $this->dataDir . '/' . $this->userId . '/mount.json';
+
+ $legacyBackendOptions = [
+ 'user' => 'someuser',
+ 'password' => 'somepassword',
+ ];
+ $legacyBackendOptions = \OC_Mount_Config::encryptPasswords($legacyBackendOptions);
+
+ $legacyConfig = [
+ 'class' => '\OC\Files\Storage\SMB',
+ 'options' => $legacyBackendOptions,
+ 'mountOptions' => ['preview' => false],
+ ];
+ // different mount options
+ $legacyConfig2 = [
+ 'class' => '\OC\Files\Storage\SMB',
+ 'options' => $legacyBackendOptions,
+ 'mountOptions' => ['preview' => true],
+ ];
+
+ $json = ['user' => []];
+ $json['user'][$this->userId] = [
+ '/$user/files/somemount' => $legacyConfig,
+ '/$user/files/anothermount' => $legacyConfig2,
+ ];
+
+ 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('someuser', $storage1->getBackendOptions()['user']);
+ $this->assertEquals('somepassword', $storage1->getBackendOptions()['password']);
+ $this->assertEquals(['preview' => false], $storage1->getMountOptions());
+
+ $this->assertEquals('/anothermount', $storage2->getMountPoint());
+ $this->assertEquals('someuser', $storage2->getBackendOptions()['user']);
+ $this->assertEquals('somepassword', $storage2->getBackendOptions()['password']);
+ $this->assertEquals(['preview' => true], $storage2->getMountOptions());
+ }
+}
diff --git a/apps/files_external/tests/storageconfigtest.php b/apps/files_external/tests/storageconfigtest.php
new file mode 100644
index 00000000000..ec79b1bf306
--- /dev/null
+++ b/apps/files_external/tests/storageconfigtest.php
@@ -0,0 +1,52 @@
+
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see .
+ *
+ */
+
+namespace OCA\Files_external\Tests;
+
+use \OCA\Files_external\Lib\StorageConfig;
+
+class StorageConfigTest extends \Test\TestCase {
+
+ public function testJsonSerialization() {
+ $storageConfig = new StorageConfig(1);
+ $storageConfig->setMountPoint('test');
+ $storageConfig->setBackendClass('\OC\Files\Storage\SMB');
+ $storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123']);
+ $storageConfig->setPriority(128);
+ $storageConfig->setApplicableUsers(['user1', 'user2']);
+ $storageConfig->setApplicableGroups(['group1', 'group2']);
+ $storageConfig->setMountOptions(['preview' => false]);
+
+ $json = $storageConfig->jsonSerialize();
+
+ $this->assertEquals(1, $json['id']);
+ $this->assertEquals('/test', $json['mountPoint']);
+ $this->assertEquals('\OC\Files\Storage\SMB', $json['backendClass']);
+ $this->assertEquals('test', $json['backendOptions']['user']);
+ $this->assertEquals('password123', $json['backendOptions']['password']);
+ $this->assertEquals(128, $json['priority']);
+ $this->assertEquals(['user1', 'user2'], $json['applicableUsers']);
+ $this->assertEquals(['group1', 'group2'], $json['applicableGroups']);
+ $this->assertEquals(['preview' => false], $json['mountOptions']);
+ }
+
+}
diff --git a/core/js/tests/specHelper.js b/core/js/tests/specHelper.js
index 59c2a99645f..29293e89bcb 100644
--- a/core/js/tests/specHelper.js
+++ b/core/js/tests/specHelper.js
@@ -123,6 +123,9 @@ window.isPhantom = /phantom/i.test(navigator.userAgent);
// reset plugins
OC.Plugins._plugins = [];
+
+ // dummy select2 (which isn't loaded during the tests)
+ $.fn.select2 = function() {};
});
afterEach(function() {
@@ -131,6 +134,8 @@ window.isPhantom = /phantom/i.test(navigator.userAgent);
fakeServer.restore();
$testArea.remove();
+
+ delete($.fn.select2);
});
})();
diff --git a/tests/karma.config.js b/tests/karma.config.js
index e5febb15aaa..997da4bcb26 100644
--- a/tests/karma.config.js
+++ b/tests/karma.config.js
@@ -64,7 +64,8 @@ module.exports = function(config) {
// only test these files, others are not ready and mess
// up with the global namespace/classes/state
'apps/files_external/js/app.js',
- 'apps/files_external/js/mountsfilelist.js'
+ 'apps/files_external/js/mountsfilelist.js',
+ 'apps/files_external/js/settings.js'
],
testFiles: ['apps/files_external/tests/js/*.js']
},
|