- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program 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, version 3,
- * along with this program. If not, see
- *
- */
-
-require_once __DIR__ . '/../../../lib/base.php';
-
-/**
- * Class Test_Mount_Config_Dummy_Backend
- */
-class Test_Mount_Config_Dummy_Backend {
- public static $checkDependencies = true;
-
- public static function checkDependencies() {
- return self::$checkDependencies;
- }
-}
-
-/**
- * Class Test_Dynamic_Mount_Config
- */
-class Test_Dynamic_Mount_Config extends \Test\TestCase {
-
- private $backup;
-
- public function testRegistration() {
-
- // second registration shall return false
- $result = OC_Mount_Config::registerBackend('Test_Mount_Config_Dummy_Backend', array(
- 'backend' => 'Test Dummy',
- 'configuration' => array(),
- 'has_dependencies' => true));
-
- $this->assertTrue($result);
- }
-
- public function testDependencyGetBackend() {
-
- // is the backend listed?
- Test_Mount_Config_Dummy_Backend::$checkDependencies = true;
- $backEnds = OC_Mount_Config::getBackends();
- $this->assertArrayHasKey('Test_Mount_Config_Dummy_Backend', $backEnds);
-
- // backend shall not be listed
- Test_Mount_Config_Dummy_Backend::$checkDependencies = false;
-
- $backEnds = OC_Mount_Config::getBackends();
- $this->assertArrayNotHasKey('Test_Mount_Config_Dummy_Backend', $backEnds);
-
- }
-
- public function testCheckDependencies() {
-
- Test_Mount_Config_Dummy_Backend::$checkDependencies = true;
- $message = OC_Mount_Config::checkDependencies();
- $this->assertEmpty($message);
-
- // backend shall not be listed
- Test_Mount_Config_Dummy_Backend::$checkDependencies = array('dummy');
-
- $message = OC_Mount_Config::checkDependencies();
- $this->assertEquals('
Note: "dummy" is not installed. Mounting of Test Dummy is not possible. Please ask your system administrator to install it.',
- $message);
-
- }
-
- protected function setUp() {
- parent::setUp();
-
- $this->backup = OC_Mount_Config::setUp();
-
- // register dummy backend
- $result = OC_Mount_Config::registerBackend('Test_Mount_Config_Dummy_Backend', array(
- 'backend' => 'Test Dummy',
- 'configuration' => array(),
- 'has_dependencies' => true));
-
- $this->assertTrue($result);
- }
-
- protected function tearDown()
- {
- OC_Mount_Config::setUp($this->backup);
- parent::tearDown();
- }
-}
diff --git a/apps/files_external/tests/frontenddefinitiontraittest.php b/apps/files_external/tests/frontenddefinitiontraittest.php
new file mode 100644
index 000000000000..871a87d4c522
--- /dev/null
+++ b/apps/files_external/tests/frontenddefinitiontraittest.php
@@ -0,0 +1,83 @@
+
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see
+ *
+ */
+
+namespace OCA\Files_External\Tests;
+
+class FrontendDefinitionTraitTest extends \Test\TestCase {
+
+ public function testJsonSerialization() {
+ $param = $this->getMockBuilder('\OCA\Files_External\Lib\DefinitionParameter')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $param->method('getName')->willReturn('foo');
+
+ $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait');
+ $trait->setText('test');
+ $trait->addParameters([$param]);
+ $trait->setCustomJs('foo/bar.js');
+
+ $json = $trait->jsonSerializeDefinition();
+
+ $this->assertEquals('test', $json['name']);
+ $this->assertEquals('foo/bar.js', $json['custom']);
+
+ $configuration = $json['configuration'];
+ $this->assertArrayHasKey('foo', $configuration);
+ }
+
+ public function validateStorageProvider() {
+ return [
+ [true, ['foo' => true, 'bar' => true, 'baz' => true]],
+ [false, ['foo' => true, 'bar' => false]]
+ ];
+ }
+
+ /**
+ * @dataProvider validateStorageProvider
+ */
+ public function testValidateStorage($expectedSuccess, $params) {
+ $backendParams = [];
+ foreach ($params as $name => $valid) {
+ $param = $this->getMockBuilder('\OCA\Files_External\Lib\DefinitionParameter')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $param->method('getName')
+ ->willReturn($name);
+ $param->expects($this->once())
+ ->method('validateValue')
+ ->willReturn($valid);
+ $backendParams[] = $param;
+ }
+
+ $storageConfig = $this->getMockBuilder('\OCA\Files_External\Lib\StorageConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $storageConfig->expects($this->once())
+ ->method('getBackendOptions')
+ ->willReturn([]);
+
+ $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait');
+ $trait->setText('test');
+ $trait->addParameters($backendParams);
+
+ $this->assertEquals($expectedSuccess, $trait->validateStorageDefinition($storageConfig));
+ }
+}
diff --git a/apps/files_external/tests/js/settingsSpec.js b/apps/files_external/tests/js/settingsSpec.js
index 7cb86d7270b0..67a81277124c 100644
--- a/apps/files_external/tests/js/settingsSpec.js
+++ b/apps/files_external/tests/js/settingsSpec.js
@@ -39,6 +39,7 @@ describe('OCA.External.Settings tests', function() {
'' +
'' +
'' +
+ ' | ' +
' | ' +
'' +
'' +
@@ -58,6 +59,9 @@ describe('OCA.External.Settings tests', function() {
'field1': 'Display Name 1',
'field2': '&Display Name 2'
},
+ 'authSchemes': {
+ 'builtin': true,
+ },
'priority': 11
},
'\\OC\\AnotherTestBackend': {
@@ -66,10 +70,23 @@ describe('OCA.External.Settings tests', function() {
'field1': 'Display Name 1',
'field2': '&Display Name 2'
},
+ 'authSchemes': {
+ 'builtin': true,
+ },
'priority': 12
}
}
);
+
+ $('#externalStorage #addMountPoint .authentication:first').data('mechanisms', {
+ 'mechanism1': {
+ 'name': 'Mechanism 1',
+ 'configuration': {
+ },
+ 'scheme': 'builtin',
+ },
+ });
+
});
afterEach(function() {
select2Stub.restore();
@@ -80,7 +97,7 @@ describe('OCA.External.Settings tests', function() {
var view;
function selectBackend(backendName) {
- view.$el.find('.selectBackend:first').val('\\OC\\TestBackend').trigger('change');
+ view.$el.find('.selectBackend:first').val(backendName).trigger('change');
}
beforeEach(function() {
@@ -139,7 +156,8 @@ describe('OCA.External.Settings tests', function() {
var request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_external/globalstorages');
expect(JSON.parse(request.requestBody)).toEqual({
- backendClass: '\\OC\\TestBackend',
+ backend: '\\OC\\TestBackend',
+ authMechanism: 'mechanism1',
backendOptions: {
'field1': 'test',
'field2': ''
diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php
deleted file mode 100644
index b76ba0a39a69..000000000000
--- a/apps/files_external/tests/mountconfig.php
+++ /dev/null
@@ -1,1157 +0,0 @@
-
- * @author Joas Schilling
- * @author Morris Jobke
- * @author Robin Appelman
- * @author Robin McCorkell
- * @author Vincent Petry
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program 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, version 3,
- * along with this program. If not, see
- *
- */
-
-class Test_Mount_Config_Dummy_Storage extends \OC\Files\Storage\Common {
- public function __construct($params) {
- if (isset($params['simulateFail']) && $params['simulateFail'] == true) {
- throw new \Exception('Simulated config validation fail');
- }
- }
-
- public function getId() {
- return 'dummy_storage';
- }
-
- public function mkdir($path) {
- return false;
- }
-
- public function rmdir($path) {
- return false;
- }
-
- public function opendir($path) {
- return false;
- }
-
- public function filetype($path) {
- return false;
- }
-
- public function file_exists($path) {
- return false;
- }
-
- public function unlink($path) {
- return false;
- }
-
- public function fopen($path, $mode) {
- return false;
- }
-
- public function touch($path, $mtime = null) {
- return false;
- }
-
- public function stat($path) {
- return false;
- }
-
- public function test() {
- return true;
- }
-}
-
-class Test_Mount_Config_Storage_No_Personal extends Test_Mount_Config_Dummy_Storage {
-}
-
-class Test_Mount_Config_Hook_Test {
- static $signal;
- static $params;
-
- public static function setUpHooks() {
- self::clear();
- \OCP\Util::connectHook(
- \OC\Files\Filesystem::CLASSNAME,
- \OC\Files\Filesystem::signal_create_mount,
- '\Test_Mount_Config_Hook_Test', 'createHookCallback');
- \OCP\Util::connectHook(
- \OC\Files\Filesystem::CLASSNAME,
- \OC\Files\Filesystem::signal_delete_mount,
- '\Test_Mount_Config_Hook_Test', 'deleteHookCallback');
- }
-
- public static function clear() {
- self::$signal = null;
- self::$params = null;
- }
-
- public static function createHookCallback($params) {
- self::$signal = \OC\Files\Filesystem::signal_create_mount;
- self::$params = $params;
- }
-
- public static function deleteHookCallback($params) {
- self::$signal = \OC\Files\Filesystem::signal_delete_mount;
- self::$params = $params;
- }
-
- public static function getLastCall() {
- return array(self::$signal, self::$params);
- }
-}
-
-/**
- * Class Test_Mount_Config
- */
-class Test_Mount_Config extends \Test\TestCase {
-
- private $dataDir;
- private $userHome;
- private $oldAllowedBackends;
-
- const TEST_USER1 = 'user1';
- const TEST_USER2 = 'user2';
- const TEST_GROUP1 = 'group1';
- const TEST_GROUP1B = 'group1b';
- const TEST_GROUP2 = 'group2';
- const TEST_GROUP2B = 'group2b';
-
- protected function setUp() {
- parent::setUp();
-
- OC_Mount_Config::registerBackend('Test_Mount_Config_Dummy_Storage', array(
- 'backend' => 'dummy',
- 'priority' => 150,
- 'configuration' => array()
- )
- );
- OC_Mount_Config::registerBackend('Test_Mount_Config_Storage_No_Personal', array(
- 'backend' => 'dummy no personal',
- 'priority' => 150,
- 'configuration' => array()
- )
- );
-
- \OC_User::createUser(self::TEST_USER1, self::TEST_USER1);
- \OC_User::createUser(self::TEST_USER2, self::TEST_USER2);
-
- \OC_Group::createGroup(self::TEST_GROUP1);
- \OC_Group::createGroup(self::TEST_GROUP1B);
- \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1);
- \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1B);
- \OC_Group::createGroup(self::TEST_GROUP2);
- \OC_Group::createGroup(self::TEST_GROUP2B);
- \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2);
- \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2B);
-
- \OC_User::setUserId(self::TEST_USER1);
- $this->userHome = \OC_User::getHome(self::TEST_USER1);
- @mkdir($this->userHome);
-
- $this->dataDir = \OC_Config::getValue(
- 'datadirectory',
- \OC::$SERVERROOT . '/data/'
- );
- $this->oldAllowedBackends = OCP\Config::getAppValue(
- 'files_external',
- 'user_mounting_backends',
- ''
- );
- OCP\Config::setAppValue(
- 'files_external',
- 'user_mounting_backends',
- 'Test_Mount_Config_Dummy_Storage'
- );
-
- OC_Mount_Config::$skipTest = true;
- Test_Mount_Config_Hook_Test::setupHooks();
- }
-
- protected function tearDown() {
- Test_Mount_Config_Hook_Test::clear();
- OC_Mount_Config::$skipTest = false;
-
- \OC_User::deleteUser(self::TEST_USER2);
- \OC_User::deleteUser(self::TEST_USER1);
- \OC_Group::deleteGroup(self::TEST_GROUP1);
- \OC_Group::deleteGroup(self::TEST_GROUP1B);
- \OC_Group::deleteGroup(self::TEST_GROUP2);
- \OC_Group::deleteGroup(self::TEST_GROUP2B);
-
- @unlink($this->dataDir . '/mount.json');
-
- OCP\Config::setAppValue(
- 'files_external',
- 'user_mounting_backends',
- $this->oldAllowedBackends
- );
-
- parent::tearDown();
- }
-
- /**
- * Reads the global config, for checking
- */
- private function readGlobalConfig() {
- $configFile = $this->dataDir . '/mount.json';
- return json_decode(file_get_contents($configFile), true);
- }
-
- private function writeGlobalConfig($config) {
- $configFile = $this->dataDir . '/mount.json';
- file_put_contents($configFile, json_encode($config));
- }
-
- /**
- * Reads the user config, for checking
- */
- private function readUserConfig() {
- $configFile = $this->userHome . '/mount.json';
- return json_decode(file_get_contents($configFile), true);
- }
-
- /**
- * Write the user config, to simulate existing files
- */
- private function writeUserConfig($config) {
- $configFile = $this->userHome . '/mount.json';
- file_put_contents($configFile, json_encode($config));
- }
-
- /**
- * Test mount point validation
- */
- public function testAddMountPointValidation() {
- $storageClass = 'Test_Mount_Config_Dummy_Storage';
- $mountType = 'user';
- $applicable = 'all';
- $isPersonal = false;
- $this->assertFalse(OC_Mount_Config::addMountPoint('', $storageClass, array(), $mountType, $applicable, $isPersonal));
- $this->assertFalse(OC_Mount_Config::addMountPoint('/', $storageClass, array(), $mountType, $applicable, $isPersonal));
- }
-
- /**
- * Test adding a global mount point
- */
- public function testAddGlobalMountPoint() {
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $applicable = 'all';
- $isPersonal = false;
-
- $storageOptions = array(
- 'host' => 'localhost',
- 'user' => 'testuser',
- 'password' => '12345',
- );
-
- $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));
- $this->assertTrue(isset($config[$mountType]));
- $this->assertTrue(isset($config[$mountType][$applicable]));
- $this->assertTrue(isset($config[$mountType][$applicable]['/$user/files/ext']));
- $this->assertEquals(
- 'Test_Mount_Config_Dummy_Storage',
- $config[$mountType][$applicable]['/$user/files/ext']['class']
- );
- }
-
- /**
- * Test adding a personal mount point
- */
- public function testAddMountPointSingleUser() {
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $applicable = self::TEST_USER1;
- $isPersonal = true;
-
- $storageOptions = array(
- 'host' => 'localhost',
- 'user' => 'testuser',
- 'password' => '12345',
- );
-
- $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));
- $this->assertTrue(isset($config[$mountType]));
- $this->assertTrue(isset($config[$mountType][$applicable]));
- $this->assertTrue(isset($config[$mountType][$applicable]['/' . self::TEST_USER1 . '/files/ext']));
- $this->assertEquals(
- 'Test_Mount_Config_Dummy_Storage',
- $config[$mountType][$applicable]['/' . self::TEST_USER1 . '/files/ext']['class']
- );
- }
-
- /**
- * Test adding a personal mount point using disallowed backend
- */
- public function testAddDisallowedBackendMountPointSingleUser() {
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $applicable = self::TEST_USER1;
- $isPersonal = true;
-
- // local
- $this->assertFalse(OC_Mount_Config::addMountPoint('/ext', '\OC\Files\Storage\Local', array(), $mountType, $applicable, $isPersonal));
-
- $storageOptions = array(
- 'host' => 'localhost',
- 'user' => 'testuser',
- 'password' => '12345',
- );
-
- // non-local but forbidden
- $this->assertFalse(OC_Mount_Config::addMountPoint('/ext', 'Test_Mount_Config_Storage_No_Personal', $storageOptions, $mountType, $applicable, $isPersonal));
-
- $this->assertFalse(file_exists($this->userHome . '/mount.json'));
- }
-
- /**
- * Test adding a mount point with an non-existant backend
- */
- public function testAddMountPointUnexistClass() {
- $storageClass = 'Unexist_Storage';
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $applicable = self::TEST_USER1;
- $isPersonal = false;
- $this->assertFalse(OC_Mount_Config::addMountPoint('/ext', $storageClass, array(), $mountType, $applicable, $isPersonal));
-
- }
-
- /**
- * Provider for testing configurations with different
- * "applicable" values (all, user, groups)
- */
- public function applicableConfigProvider() {
- return array(
- // applicable to "all"
- array(
- OC_Mount_Config::MOUNT_TYPE_USER,
- 'all',
- array(
- 'users' => array('all'),
- 'groups' => array()
- )
- ),
- // applicable to single user
- array(
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER1,
- array(
- 'users' => array(self::TEST_USER1),
- 'groups' => array()
- )
- ),
- // applicable to single group
- array(
- OC_Mount_Config::MOUNT_TYPE_GROUP,
- self::TEST_GROUP1,
- array(
- 'users' => array(),
- 'groups' => array(self::TEST_GROUP1)
- )
- ),
- );
- }
-
- /**
- * Test reading and writing global config
- *
- * @dataProvider applicableConfigProvider
- */
- public function testReadWriteGlobalConfig($mountType, $applicable, $expectApplicableArray) {
-
- $mountType = $mountType;
- $applicable = $applicable;
- $isPersonal = false;
- $options = array(
- 'host' => 'smbhost',
- 'user' => 'smbuser',
- 'password' => 'smbpassword',
- 'share' => 'smbshare',
- 'root' => 'smbroot'
- );
-
- // write config
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $options,
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- // re-read config
- $config = OC_Mount_Config::getSystemMountPoints();
- $this->assertEquals(1, count($config));
- $this->assertEquals('Test_Mount_Config_Dummy_Storage', $config[0]['class']);
- $this->assertEquals('ext', $config[0]['mountpoint']);
- $this->assertEquals($expectApplicableArray, $config[0]['applicable']);
- $savedOptions = $config[0]['options'];
- $this->assertEquals($options, $savedOptions);
- // key order needs to be preserved for the UI...
- $this->assertEquals(array_keys($options), array_keys($savedOptions));
- }
-
- /**
- * Test reading and writing config
- */
- public function testReadWritePersonalConfig() {
-
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $applicable = self::TEST_USER1;
- $isPersonal = true;
- $options = array(
- 'host' => 'smbhost',
- 'user' => 'smbuser',
- 'password' => 'smbpassword',
- 'share' => 'smbshare',
- 'root' => 'smbroot'
- );
-
- // write config
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $options,
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- // re-read config
- $config = OC_Mount_Config::getPersonalMountPoints();
- $this->assertEquals(1, count($config));
- $this->assertEquals('Test_Mount_Config_Dummy_Storage', $config[0]['class']);
- $this->assertEquals('ext', $config[0]['mountpoint']);
- $savedOptions = $config[0]['options'];
- $this->assertEquals($options, $savedOptions);
- // key order needs to be preserved for the UI...
- $this->assertEquals(array_keys($options), array_keys($savedOptions));
- }
-
- public function testHooks() {
- $mountPoint = '/test';
- $mountType = 'user';
- $applicable = 'all';
- $isPersonal = false;
-
- $mountConfig = array(
- 'host' => 'smbhost',
- 'user' => 'smbuser',
- 'password' => 'smbpassword',
- 'share' => 'smbshare',
- 'root' => 'smbroot'
- );
-
- // write config
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- $mountPoint,
- 'Test_Mount_Config_Dummy_Storage',
- $mountConfig,
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- list($hookName, $params) = Test_Mount_Config_Hook_Test::getLastCall();
- $this->assertEquals(
- \OC\Files\Filesystem::signal_create_mount,
- $hookName
- );
- $this->assertEquals(
- $mountPoint,
- $params[\OC\Files\Filesystem::signal_param_path]
- );
- $this->assertEquals(
- $mountType,
- $params[\OC\Files\Filesystem::signal_param_mount_type]
- );
- $this->assertEquals(
- $applicable,
- $params[\OC\Files\Filesystem::signal_param_users]
- );
-
- Test_Mount_Config_Hook_Test::clear();
-
- // edit
- $mountConfig['host'] = 'anothersmbhost';
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- $mountPoint,
- 'Test_Mount_Config_Dummy_Storage',
- $mountConfig,
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- // hook must not be called on edit
- list($hookName, $params) = Test_Mount_Config_Hook_Test::getLastCall();
- $this->assertEquals(
- null,
- $hookName
- );
-
- Test_Mount_Config_Hook_Test::clear();
-
- $this->assertTrue(
- OC_Mount_Config::removeMountPoint(
- $mountPoint,
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- list($hookName, $params) = Test_Mount_Config_Hook_Test::getLastCall();
- $this->assertEquals(
- \OC\Files\Filesystem::signal_delete_mount,
- $hookName
- );
- $this->assertEquals(
- $mountPoint,
- $params[\OC\Files\Filesystem::signal_param_path]
- );
- $this->assertEquals(
- $mountType,
- $params[\OC\Files\Filesystem::signal_param_mount_type]
- );
- $this->assertEquals(
- $applicable,
- $params[\OC\Files\Filesystem::signal_param_users]
- );
- }
-
- /**
- * Test password obfuscation
- */
- public function testPasswordObfuscation() {
-
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $applicable = self::TEST_USER1;
- $isPersonal = true;
- $mountConfig = array(
- 'host' => 'smbhost',
- 'user' => 'smbuser',
- 'password' => 'smbpassword',
- 'share' => 'smbshare',
- 'root' => 'smbroot'
- );
-
- // write config
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $mountConfig,
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- // note: password re-reading is covered by testReadWritePersonalConfig
-
- // check that password inside the file is NOT in plain text
- $config = $this->readUserConfig();
- $savedConfig = $config[$mountType][$applicable]['/' . self::TEST_USER1 . '/files/ext']['options'];
-
- // no more clear text password in file (kept because of key order)
- $this->assertEquals('', $savedConfig['password']);
-
- // encrypted password is present
- $this->assertNotEquals($mountConfig['password'], $savedConfig['password_encrypted']);
- }
-
- /**
- * Test read legacy passwords
- */
- public function testReadLegacyPassword() {
-
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $applicable = self::TEST_USER1;
- $isPersonal = true;
- $mountConfig = array(
- 'host' => 'smbhost',
- 'user' => 'smbuser',
- 'password' => 'smbpassword',
- 'share' => 'smbshare',
- 'root' => 'smbroot'
- );
-
- // write config
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $mountConfig,
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- $config = $this->readUserConfig();
- // simulate non-encrypted password situation
- $config[$mountType][$applicable]['/' . self::TEST_USER1 . '/files/ext']['options']['password'] = 'smbpasswd';
-
- $this->writeUserConfig($config);
-
- // re-read config, password was read correctly
- $config = OC_Mount_Config::getPersonalMountPoints();
- $savedMountConfig = $config[0]['options'];
- $this->assertEquals($mountConfig, $savedMountConfig);
- }
-
- public function testVariableSubstitution() {
- $legacyBackendOptions = [
- 'user' => 'someuser',
- 'password' => 'somepassword',
- 'replacethis' => '$user',
- ];
- $legacyBackendOptions = \OC_Mount_Config::encryptPasswords($legacyBackendOptions);
-
- $legacyConfig = [
- 'class' => '\OC\Files\Storage\SMB',
- 'options' => $legacyBackendOptions,
- 'mountOptions' => ['preview' => false, 'int' => 1],
- ];
- // different mount options
- $legacyConfig2 = [
- 'class' => '\OC\Files\Storage\SMB',
- 'options' => $legacyBackendOptions,
- 'mountOptions' => ['preview' => true, 'string' => 'abc'],
- ];
-
- $json = [
- 'user' => [
- self::TEST_USER1 => [
- '/$user/files/somemount' => $legacyConfig,
- '/$user/files/anothermount' => $legacyConfig2,
- ],
- ],
- ];
-
- $this->writeGlobalConfig($json);
-
- // re-read config, password was read correctly
- $config = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
-
- $config1 = $config['/' . self::TEST_USER1 . '/files/somemount'];
- $config2 = $config['/' . self::TEST_USER1 . '/files/anothermount'];
-
- $this->assertSame(self::TEST_USER1, $config1['options']['replacethis']);
- $this->assertSame(self::TEST_USER1, $config1['options']['replacethis']);
- $this->assertSame(1, $config1['mountOptions']['int']);
- $this->assertSame(true, $config2['mountOptions']['preview']);
- $this->assertSame('abc', $config2['mountOptions']['string']);
- }
-
-
- public function mountDataProvider() {
- return array(
- // Tests for visible mount points
- // system mount point for all users
- array(
- false,
- OC_Mount_Config::MOUNT_TYPE_USER,
- 'all',
- self::TEST_USER1,
- true,
- ),
- // system mount point for a specific user
- array(
- false,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER1,
- self::TEST_USER1,
- true,
- ),
- // system mount point for a specific group
- array(
- false,
- OC_Mount_Config::MOUNT_TYPE_GROUP,
- self::TEST_GROUP1,
- self::TEST_USER1,
- true,
- ),
- // user mount point
- array(
- true,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER1,
- self::TEST_USER1,
- true,
- ),
-
- // Tests for non-visible mount points
- // system mount point for another user
- array(
- false,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER2,
- self::TEST_USER1,
- false,
- ),
- // system mount point for a specific group
- array(
- false,
- OC_Mount_Config::MOUNT_TYPE_GROUP,
- self::TEST_GROUP2,
- self::TEST_USER1,
- false,
- ),
- // user mount point
- array(
- true,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER1,
- self::TEST_USER2,
- false,
- ),
- );
- }
-
- /**
- * Test mount points used at mount time, making sure
- * the configuration is prepared properly.
- *
- * @dataProvider mountDataProvider
- * @param bool $isPersonal true for personal mount point, false for system mount point
- * @param string $mountType mount type
- * @param string $applicable target user/group or "all"
- * @param string $testUser user for which to retrieve the mount points
- * @param bool $expectVisible whether to expect the mount point to be visible for $testUser
- */
- public function testMount($isPersonal, $mountType, $applicable, $testUser, $expectVisible) {
-
- $mountConfig = array(
- 'host' => 'someost',
- 'user' => 'someuser',
- 'password' => 'somepassword',
- 'root' => 'someroot',
- 'share' => '',
- );
-
- // add mount point as "test" user
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $mountConfig,
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- // check mount points in the perspective of user $testUser
- \OC_User::setUserId($testUser);
-
- $mountPoints = OC_Mount_Config::getAbsoluteMountPoints($testUser);
- if ($expectVisible) {
- $this->assertEquals(1, count($mountPoints));
- $this->assertTrue(isset($mountPoints['/' . self::TEST_USER1 . '/files/ext']));
- $this->assertEquals('Test_Mount_Config_Dummy_Storage', $mountPoints['/' . self::TEST_USER1 . '/files/ext']['class']);
- $this->assertEquals($mountConfig, $mountPoints['/' . self::TEST_USER1 . '/files/ext']['options']);
- }
- else {
- $this->assertEquals(0, count($mountPoints));
- }
- }
-
- /**
- * Test the same config for multiple users.
- * The config will be merged by getSystemMountPoints().
- */
- public function testConfigMerging() {
-
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $isPersonal = false;
- $options = array(
- 'host' => 'smbhost',
- 'user' => 'smbuser',
- 'password' => 'smbpassword',
- 'share' => 'smbshare',
- 'root' => 'smbroot'
- );
-
- // write config
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $options,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER1,
- $isPersonal
- )
- );
-
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $options,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER2,
- $isPersonal
- )
- );
-
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $options,
- OC_Mount_Config::MOUNT_TYPE_GROUP,
- self::TEST_GROUP2,
- $isPersonal
- )
- );
-
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $options,
- OC_Mount_Config::MOUNT_TYPE_GROUP,
- self::TEST_GROUP1,
- $isPersonal
- )
- );
-
- // re-read config
- $config = OC_Mount_Config::getSystemMountPoints();
- $this->assertEquals(1, count($config));
- $this->assertEquals('Test_Mount_Config_Dummy_Storage', $config[0]['class']);
- $this->assertEquals('ext', $config[0]['mountpoint']);
- $this->assertEquals($options, $config[0]['options']);
- $this->assertEquals(array(self::TEST_USER1, self::TEST_USER2), $config[0]['applicable']['users']);
- $this->assertEquals(array(self::TEST_GROUP2, self::TEST_GROUP1), $config[0]['applicable']['groups']);
- }
-
- /**
- * Create then re-read mount points configs where the mount points
- * have the same path, the config must NOT be merged.
- */
- public function testRereadMountpointWithSamePath() {
-
- $mountType = OC_Mount_Config::MOUNT_TYPE_USER;
- $isPersonal = false;
- $options1 = array(
- 'host' => 'smbhost',
- 'user' => 'smbuser',
- 'password' => 'smbpassword',
- 'share' => 'smbshare',
- 'root' => 'smbroot'
- );
-
- // write config
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $options1,
- $mountType,
- self::TEST_USER1,
- $isPersonal
- )
- );
-
- $options2 = array(
- 'host' => 'anothersmbhost',
- 'user' => 'anothersmbuser',
- 'password' => 'anothersmbpassword',
- 'share' => 'anothersmbshare',
- 'root' => 'anothersmbroot'
- );
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $options2,
- $mountType,
- self::TEST_USER2,
- $isPersonal
- )
- );
-
- // re-read config
- $config = OC_Mount_Config::getSystemMountPoints();
- $this->assertEquals(2, count($config));
- $this->assertEquals('Test_Mount_Config_Dummy_Storage', $config[0]['class']);
- $this->assertEquals('ext', $config[0]['mountpoint']);
- $this->assertEquals($options1, $config[0]['options']);
- $this->assertEquals('Test_Mount_Config_Dummy_Storage', $config[1]['class']);
- $this->assertEquals('ext', $config[1]['mountpoint']);
- $this->assertEquals($options2, $config[1]['options']);
- }
-
- public function priorityDataProvider() {
- return array(
-
- // test 1 - group vs group
- array(
- array(
- array(
- 'isPersonal' => false,
- 'mountType' => OC_Mount_Config::MOUNT_TYPE_GROUP,
- 'applicable' => self::TEST_GROUP1,
- 'priority' => 50
- ),
- array(
- 'isPersonal' => false,
- 'mountType' => OC_Mount_Config::MOUNT_TYPE_GROUP,
- 'applicable' => self::TEST_GROUP1B,
- 'priority' => 60
- )
- ),
- 1
- ),
- // test 2 - user vs personal
- array(
- array(
- array(
- 'isPersonal' => false,
- 'mountType' => OC_Mount_Config::MOUNT_TYPE_USER,
- 'applicable' => self::TEST_USER1,
- 'priority' => 2000
- ),
- array(
- 'isPersonal' => true,
- 'mountType' => OC_Mount_Config::MOUNT_TYPE_USER,
- 'applicable' => self::TEST_USER1,
- 'priority' => null
- )
- ),
- 1
- ),
- // test 3 - all vs group vs user
- array(
- array(
- array(
- 'isPersonal' => false,
- 'mountType' => OC_Mount_Config::MOUNT_TYPE_USER,
- 'applicable' => 'all',
- 'priority' => 70
- ),
- array(
- 'isPersonal' => false,
- 'mountType' => OC_Mount_Config::MOUNT_TYPE_GROUP,
- 'applicable' => self::TEST_GROUP1,
- 'priority' => 60
- ),
- array(
- 'isPersonal' => false,
- 'mountType' => OC_Mount_Config::MOUNT_TYPE_USER,
- 'applicable' => self::TEST_USER1,
- 'priority' => 50
- )
- ),
- 2
- )
-
- );
- }
-
- /**
- * Ensure priorities are being respected
- * Test user is self::TEST_USER1
- *
- * @dataProvider priorityDataProvider
- * @param array[] $mounts array of associative array of mount parameters:
- * bool $isPersonal
- * string $mountType
- * string $applicable
- * int|null $priority null for personal
- * @param int $expected index of expected visible mount
- */
- public function testPriority($mounts, $expected) {
-
- $mountConfig = array(
- 'host' => 'somehost',
- 'user' => 'someuser',
- 'password' => 'somepassword',
- 'root' => 'someroot',
- 'share' => '',
- );
-
- // Add mount points
- foreach($mounts as $i => $mount) {
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $mountConfig + array('id' => $i),
- $mount['mountType'],
- $mount['applicable'],
- $mount['isPersonal'],
- $mount['priority']
- )
- );
- }
-
- // Get mount points for user
- $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
-
- $this->assertEquals(1, count($mountPoints));
- $this->assertEquals($expected, $mountPoints['/'.self::TEST_USER1.'/files/ext']['options']['id']);
- }
-
- /**
- * Test for persistence of priority when changing mount options
- */
- public function testPriorityPersistence() {
-
- $class = 'Test_Mount_Config_Dummy_Storage';
- $priority = 123;
- $mountConfig = array(
- 'host' => 'somehost',
- 'user' => 'someuser',
- 'password' => 'somepassword',
- 'root' => 'someroot',
- 'share' => '',
- );
-
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- $class,
- $mountConfig,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER1,
- false,
- $priority
- )
- );
-
- // Check for correct priority
- $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
- $this->assertEquals($priority,
- $mountPoints['/'.self::TEST_USER1.'/files/ext']['priority']);
-
- // Simulate changed mount options (without priority set)
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- $class,
- $mountConfig,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER1,
- false
- )
- );
-
- // Check for correct priority
- $mountPoints = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
- $this->assertEquals($priority,
- $mountPoints['/'.self::TEST_USER1.'/files/ext']['priority']);
- }
-
- /*
- * Test for correct personal configuration loading in file sharing scenarios
- */
- public function testMultiUserPersonalConfigLoading() {
- $mountConfig = array(
- 'host' => 'somehost',
- 'user' => 'someuser',
- 'password' => 'somepassword',
- 'root' => 'someroot',
- 'share' => '',
- );
-
- // Create personal mount point
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- 'Test_Mount_Config_Dummy_Storage',
- $mountConfig,
- OC_Mount_Config::MOUNT_TYPE_USER,
- self::TEST_USER1,
- true
- )
- );
-
- // Ensure other user can read mount points
- \OC_User::setUserId(self::TEST_USER2);
- $mountPointsMe = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER2);
- $mountPointsOther = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
-
- $this->assertEquals(0, count($mountPointsMe));
- $this->assertEquals(1, count($mountPointsOther));
- $this->assertTrue(isset($mountPointsOther['/'.self::TEST_USER1.'/files/ext']));
- $this->assertEquals('Test_Mount_Config_Dummy_Storage',
- $mountPointsOther['/'.self::TEST_USER1.'/files/ext']['class']);
- $this->assertEquals($mountConfig,
- $mountPointsOther['/'.self::TEST_USER1.'/files/ext']['options']);
- }
-
- public function testAllowWritingIncompleteConfigIfStorageContructorFails() {
- $storageClass = 'Test_Mount_Config_Dummy_Storage';
- $mountType = 'user';
- $applicable = 'all';
- $isPersonal = false;
-
- $this->assertEquals(
- 0,
- OC_Mount_Config::addMountPoint(
- '/ext',
- $storageClass,
- array('simulateFail' => true),
- $mountType,
- $applicable,
- $isPersonal
- )
- );
-
- // config can be retrieved afterwards
- $mounts = OC_Mount_Config::getSystemMountPoints();
- $this->assertEquals(1, count($mounts));
-
- // no storage id was set
- $this->assertFalse(isset($mounts[0]['storage_id']));
- }
-}
diff --git a/apps/files_external/tests/service/backendservicetest.php b/apps/files_external/tests/service/backendservicetest.php
new file mode 100644
index 000000000000..08f6b9bf988c
--- /dev/null
+++ b/apps/files_external/tests/service/backendservicetest.php
@@ -0,0 +1,152 @@
+
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see
+ *
+ */
+namespace OCA\Files_External\Tests\Service;
+
+use \OCA\Files_External\Service\BackendService;
+
+class BackendServiceTest extends \Test\TestCase {
+
+ /** @var \OCP\IConfig */
+ protected $config;
+
+ /** @var \OCP\IL10N */
+ protected $l10n;
+
+ protected function setUp() {
+ $this->config = $this->getMock('\OCP\IConfig');
+ $this->l10n = $this->getMock('\OCP\IL10N');
+ }
+
+ protected function getBackendMock($class) {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend->method('getIdentifier')->will($this->returnValue('identifier:'.$class));
+ $backend->method('getIdentifierAliases')->will($this->returnValue(['identifier:'.$class]));
+ return $backend;
+ }
+
+ public function testRegisterBackend() {
+ $service = new BackendService($this->config, $this->l10n);
+
+ $backend = $this->getBackendMock('\Foo\Bar');
+
+ $backendAlias = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backendAlias->method('getIdentifierAliases')
+ ->willReturn(['identifier_real', 'identifier_alias']);
+ $backendAlias->method('getIdentifier')
+ ->willReturn('identifier_real');
+
+ $service->registerBackend($backend);
+ $service->registerBackend($backendAlias);
+
+ $this->assertEquals($backend, $service->getBackend('identifier:\Foo\Bar'));
+ $this->assertEquals($backendAlias, $service->getBackend('identifier_real'));
+ $this->assertEquals($backendAlias, $service->getBackend('identifier_alias'));
+
+ $backends = $service->getBackends();
+ $this->assertCount(2, $backends);
+ $this->assertArrayHasKey('identifier:\Foo\Bar', $backends);
+ $this->assertArrayHasKey('identifier_real', $backends);
+ $this->assertArrayNotHasKey('identifier_alias', $backends);
+ }
+
+ public function testUserMountingBackends() {
+ $this->config->expects($this->exactly(2))
+ ->method('getAppValue')
+ ->will($this->returnValueMap([
+ ['files_external', 'allow_user_mounting', 'yes', 'yes'],
+ ['files_external', 'user_mounting_backends', '', 'identifier:\User\Mount\Allowed,identifier_alias']
+ ]));
+
+ $service = new BackendService($this->config, $this->l10n);
+
+ $backendAllowed = $this->getBackendMock('\User\Mount\Allowed');
+ $backendAllowed->expects($this->never())
+ ->method('removeVisibility');
+ $backendNotAllowed = $this->getBackendMock('\User\Mount\NotAllowed');
+ $backendNotAllowed->expects($this->once())
+ ->method('removeVisibility')
+ ->with(BackendService::VISIBILITY_PERSONAL);
+
+ $backendAlias = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backendAlias->method('getIdentifierAliases')
+ ->willReturn(['identifier_real', 'identifier_alias']);
+ $backendAlias->expects($this->never())
+ ->method('removeVisibility');
+
+ $service->registerBackend($backendAllowed);
+ $service->registerBackend($backendNotAllowed);
+ $service->registerBackend($backendAlias);
+ }
+
+ public function testGetAvailableBackends() {
+ $service = new BackendService($this->config, $this->l10n);
+
+ $backendAvailable = $this->getBackendMock('\Backend\Available');
+ $backendAvailable->expects($this->once())
+ ->method('checkDependencies')
+ ->will($this->returnValue([]));
+ $backendNotAvailable = $this->getBackendMock('\Backend\NotAvailable');
+ $backendNotAvailable->expects($this->once())
+ ->method('checkDependencies')
+ ->will($this->returnValue([
+ $this->getMockBuilder('\OCA\Files_External\Lib\MissingDependency')
+ ->disableOriginalConstructor()
+ ->getMock()
+ ]));
+
+ $service->registerBackend($backendAvailable);
+ $service->registerBackend($backendNotAvailable);
+
+ $availableBackends = $service->getAvailableBackends();
+ $this->assertArrayHasKey('identifier:\Backend\Available', $availableBackends);
+ $this->assertArrayNotHasKey('identifier:\Backend\NotAvailable', $availableBackends);
+ }
+
+ public function testGetUserBackends() {
+ $service = new BackendService($this->config, $this->l10n);
+
+ $backendAllowed = $this->getBackendMock('\User\Mount\Allowed');
+ $backendAllowed->expects($this->once())
+ ->method('isVisibleFor')
+ ->with(BackendService::VISIBILITY_PERSONAL)
+ ->will($this->returnValue(true));
+ $backendNotAllowed = $this->getBackendMock('\User\Mount\NotAllowed');
+ $backendNotAllowed->expects($this->once())
+ ->method('isVisibleFor')
+ ->with(BackendService::VISIBILITY_PERSONAL)
+ ->will($this->returnValue(false));
+
+ $service->registerBackend($backendAllowed);
+ $service->registerBackend($backendNotAllowed);
+
+ $userBackends = $service->getBackendsVisibleFor(BackendService::VISIBILITY_PERSONAL);
+ $this->assertArrayHasKey('identifier:\User\Mount\Allowed', $userBackends);
+ $this->assertArrayNotHasKey('identifier:\User\Mount\NotAllowed', $userBackends);
+ }
+
+}
+
diff --git a/apps/files_external/tests/service/globalstoragesservicetest.php b/apps/files_external/tests/service/globalstoragesservicetest.php
index ac25f58b1d1d..05585d2c065e 100644
--- a/apps/files_external/tests/service/globalstoragesservicetest.php
+++ b/apps/files_external/tests/service/globalstoragesservicetest.php
@@ -29,7 +29,7 @@
class GlobalStoragesServiceTest extends StoragesServiceTest {
public function setUp() {
parent::setUp();
- $this->service = new GlobalStoragesService();
+ $this->service = new GlobalStoragesService($this->backendService);
}
public function tearDown() {
@@ -40,7 +40,8 @@ public function tearDown() {
protected function makeTestStorageData() {
return $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -59,9 +60,10 @@ function storageDataProvider() {
return [
// all users
[
- $this->makeStorageConfig([
+ [
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -70,13 +72,14 @@ function storageDataProvider() {
'applicableUsers' => [],
'applicableGroups' => [],
'priority' => 15,
- ]),
+ ],
],
// some users
[
- $this->makeStorageConfig([
+ [
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -85,13 +88,14 @@ function storageDataProvider() {
'applicableUsers' => ['user1', 'user2'],
'applicableGroups' => [],
'priority' => 15,
- ]),
+ ],
],
// some groups
[
- $this->makeStorageConfig([
+ [
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -100,13 +104,14 @@ function storageDataProvider() {
'applicableUsers' => [],
'applicableGroups' => ['group1', 'group2'],
'priority' => 15,
- ]),
+ ],
],
// both users and groups
[
- $this->makeStorageConfig([
+ [
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -115,7 +120,7 @@ function storageDataProvider() {
'applicableUsers' => ['user1', 'user2'],
'applicableGroups' => ['group1', 'group2'],
'priority' => 15,
- ]),
+ ],
],
];
}
@@ -123,7 +128,8 @@ function storageDataProvider() {
/**
* @dataProvider storageDataProvider
*/
- public function testAddStorage($storage) {
+ public function testAddStorage($storageParams) {
+ $storage = $this->makeStorageConfig($storageParams);
$newStorage = $this->service->addStorage($storage);
$this->assertEquals(1, $newStorage->getId());
@@ -132,7 +138,8 @@ public function testAddStorage($storage) {
$newStorage = $this->service->getStorage(1);
$this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
- $this->assertEquals($storage->getBackendClass(), $newStorage->getBackendClass());
+ $this->assertEquals($storage->getBackend(), $newStorage->getBackend());
+ $this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism());
$this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
$this->assertEquals($storage->getApplicableUsers(), $newStorage->getApplicableUsers());
$this->assertEquals($storage->getApplicableGroups(), $newStorage->getApplicableGroups());
@@ -148,10 +155,12 @@ public function testAddStorage($storage) {
/**
* @dataProvider storageDataProvider
*/
- public function testUpdateStorage($updatedStorage) {
+ public function testUpdateStorage($updatedStorageParams) {
+ $updatedStorage = $this->makeStorageConfig($updatedStorageParams);
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -638,7 +647,8 @@ public function testLegacyConfigConversionApplicableAll() {
$mountPointOptions = current($mountPointData);
$this->assertEquals(1, $mountPointOptions['id']);
- $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
+ $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']);
@@ -678,7 +688,8 @@ public function testLegacyConfigConversionApplicableUserAndGroup() {
$mountPointOptions = current($mountPointData);
$this->assertEquals(1, $mountPointOptions['id']);
- $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
+ $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']);
@@ -695,7 +706,8 @@ public function testLegacyConfigConversionApplicableUserAndGroup() {
$mountPointOptions = current($mountPointData);
$this->assertEquals(1, $mountPointOptions['id']);
- $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
+ $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']);
@@ -720,13 +732,15 @@ public function testReadLegacyConfigAndGenerateConfigId() {
$legacyBackendOptions = \OC_Mount_Config::encryptPasswords($legacyBackendOptions);
$legacyConfig = [
- 'class' => '\OC\Files\Storage\SMB',
+ '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',
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
'options' => $legacyBackendOptions,
'mountOptions' => ['preview' => true],
];
@@ -737,7 +751,8 @@ public function testReadLegacyConfigAndGenerateConfigId() {
// different config
$legacyConfig3 = [
- 'class' => '\OC\Files\Storage\SMB',
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
'options' => $legacyBackendOptions2,
'mountOptions' => ['preview' => true],
];
@@ -811,4 +826,85 @@ public function testReadLegacyConfigAndGenerateConfigId() {
$this->assertEquals([], $storage4->getApplicableGroups());
$this->assertEquals(['preview' => true], $storage4->getMountOptions());
}
+
+ public function testReadLegacyConfigNoAuthMechanism() {
+ $configFile = $this->dataDir . '/mount.json';
+
+ $json = [
+ 'user' => [
+ 'user1' => [
+ '/$user/files/somemount' => [
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SFTP',
+ 'authMechanism' => 'identifier:\Auth\Mechanism',
+ 'options' => [],
+ 'mountOptions' => [],
+ ],
+ '/$user/files/othermount' => [
+ 'backend' => 'identifier:\OCA\Files_External\Lib\Backend\SFTP',
+ // no authMechanism
+ '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:\Other\Auth\Mechanism', $storage2->getAuthMechanism()->getIdentifier());
+ }
+
+ 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 36f68a83b111..07286106c7bb 100644
--- a/apps/files_external/tests/service/storagesservicetest.php
+++ b/apps/files_external/tests/service/storagesservicetest.php
@@ -1,6 +1,7 @@
+ * @author Robin McCorkell
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
@@ -24,6 +25,7 @@
use \OCA\Files_external\NotFoundException;
use \OCA\Files_external\Lib\StorageConfig;
+use \OCA\Files_External\Lib\BackendService;
abstract class StoragesServiceTest extends \Test\TestCase {
@@ -32,6 +34,9 @@ abstract class StoragesServiceTest extends \Test\TestCase {
*/
protected $service;
+ /** @var BackendService */
+ protected $backendService;
+
/**
* Data directory
*
@@ -55,6 +60,51 @@ public function setUp() {
);
\OC_Mount_Config::$skipTest = true;
+ // prepare BackendService mock
+ $this->backendService =
+ $this->getMockBuilder('\OCA\Files_External\Service\BackendService')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $authMechanisms = [
+ '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) {
+ if (isset($authMechanisms[$class])) {
+ return $authMechanisms[$class];
+ }
+ return null;
+ }));
+ $this->backendService->method('getAuthMechanismsByScheme')
+ ->will($this->returnCallback(function($schemes) use ($authMechanisms) {
+ return array_filter($authMechanisms, function ($authMech) use ($schemes) {
+ return in_array($authMech->getScheme(), $schemes, true);
+ });
+ }));
+ $this->backendService->method('getAuthMechanisms')
+ ->will($this->returnValue($authMechanisms));
+
+ $sftpBackend = $this->getBackendMock('\OCA\Files_External\Lib\Backend\SFTP', '\OC\Files\Storage\SFTP');
+ $backends = [
+ '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['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])) {
+ return $backends[$backendClass];
+ }
+ return null;
+ }));
+ $this->backendService->method('getBackends')
+ ->will($this->returnValue($backends));
+
\OCP\Util::connectHook(
Filesystem::CLASSNAME,
Filesystem::signal_create_mount,
@@ -64,6 +114,14 @@ public function setUp() {
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() {
@@ -71,6 +129,29 @@ public function tearDown() {
self::$hookCalls = array();
}
+ protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OC\Files\Storage\SMB') {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend->method('getStorageClass')
+ ->willReturn($storageClass);
+ $backend->method('getIdentifier')
+ ->willReturn('identifier:'.$class);
+ return $backend;
+ }
+
+ protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') {
+ $authMech = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $authMech->method('getScheme')
+ ->willReturn($scheme);
+ $authMech->method('getIdentifier')
+ ->willReturn('identifier:'.$class);
+
+ return $authMech;
+ }
+
/**
* Creates a StorageConfig instance based on array data
*
@@ -84,7 +165,22 @@ protected function makeStorageConfig($data) {
$storage->setId($data['id']);
}
$storage->setMountPoint($data['mountPoint']);
- $storage->setBackendClass($data['backendClass']);
+ 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['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'])) {
+ throw new \Exception('oops, no auth mechanism');
+ }
+ $storage->setBackend($data['backend']);
+ $storage->setAuthMechanism($data['authMechanism']);
$storage->setBackendOptions($data['backendOptions']);
if (isset($data['applicableUsers'])) {
$storage->setApplicableUsers($data['applicableUsers']);
@@ -106,16 +202,22 @@ protected function makeStorageConfig($data) {
* @expectedException \OCA\Files_external\NotFoundException
*/
public function testNonExistingStorage() {
+ $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->setBackendClass('\OC\Files\Storage\SMB');
+ $storage->setBackend($backend);
+ $storage->setAuthMechanism($authMechanism);
$this->service->updateStorage($storage);
}
public function testDeleteStorage() {
+ $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->setBackendClass('\OC\Files\Storage\SMB');
+ $storage->setBackend($backend);
+ $storage->setAuthMechanism($authMechanism);
$storage->setBackendOptions(['password' => 'testPassword']);
$newStorage = $this->service->addStorage($storage);
@@ -140,6 +242,64 @@ public function testDeleteUnexistingStorage() {
$this->service->removeStorage(255);
}
+ public function testCreateStorage() {
+ $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
+ );
+
+ $this->assertEquals('/'.$mountPoint, $storage->getMountPoint());
+ $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());
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testCreateStorageInvalidClass() {
+ $this->service->createStorage(
+ 'mount',
+ 'identifier:\OC\Not\A\Backend',
+ 'identifier:\Auth\Mechanism',
+ []
+ );
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testCreateStorageInvalidAuthMechanismClass() {
+ $this->service->createStorage(
+ 'mount',
+ 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'identifier:\Not\An\Auth\Mechanism',
+ []
+ );
+ }
+
public static function createHookCallback($params) {
self::$hookCalls[] = array(
'signal' => Filesystem::signal_create_mount,
diff --git a/apps/files_external/tests/service/userglobalstoragesservicetest.php b/apps/files_external/tests/service/userglobalstoragesservicetest.php
new file mode 100644
index 000000000000..49a02453840f
--- /dev/null
+++ b/apps/files_external/tests/service/userglobalstoragesservicetest.php
@@ -0,0 +1,215 @@
+
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see
+ *
+ */
+namespace OCA\Files_External\Tests\Service;
+
+use \OCA\Files_External\Service\UserGlobalStoragesService;
+use \OCP\IGroupManager;
+
+use \OCA\Files_External\Lib\StorageConfig;
+
+class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
+
+ protected $groupManager;
+
+ protected $globalStoragesService;
+
+ protected $user;
+
+ const USER_ID = 'test_user';
+ const GROUP_ID = 'test_group';
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->globalStoragesService = $this->service;
+
+ $this->user = new \OC\User\User(self::USER_ID, null);
+ $userSession = $this->getMock('\OCP\IUserSession');
+ $userSession
+ ->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+
+ $this->groupManager = $this->getMock('\OCP\IGroupManager');
+ $this->groupManager->method('isInGroup')
+ ->will($this->returnCallback(function($userId, $groupId) {
+ if ($userId === self::USER_ID && $groupId === self::GROUP_ID) {
+ return true;
+ }
+ return false;
+ }));
+
+ $this->service = new UserGlobalStoragesService(
+ $this->backendService,
+ $userSession,
+ $this->groupManager
+ );
+ }
+
+ public function applicableStorageProvider() {
+ return [
+ [[], [], true],
+
+ // not applicable cases
+ [['user1'], [], false],
+ [[], ['group1'], false],
+ [['user1'], ['group1'], false],
+
+ // applicable cases
+ [[self::USER_ID], [], true],
+ [[], [self::GROUP_ID], true],
+ [[self::USER_ID], ['group1'], true],
+ [['user1'], [self::GROUP_ID], true],
+
+ // sanity checks
+ [['user1', 'user2', self::USER_ID, 'user3'], [], true],
+ ];
+ }
+
+ /**
+ * @dataProvider applicableStorageProvider
+ */
+ public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible) {
+ $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']);
+ $storage->setApplicableUsers($applicableUsers);
+ $storage->setApplicableGroups($applicableGroups);
+
+ $newStorage = $this->globalStoragesService->addStorage($storage);
+
+ $storages = $this->service->getAllStorages();
+ if ($isVisible) {
+ $this->assertEquals(1, count($storages));
+ $retrievedStorage = $this->service->getStorage($newStorage->getId());
+ $this->assertEquals('/mountpoint', $retrievedStorage->getMountPoint());
+ } else {
+ $this->assertEquals(0, count($storages));
+ }
+
+ }
+
+ /**
+ * @expectedException \DomainException
+ */
+ public function testAddStorage($storageParams = null) {
+ $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);
+ $storage->setAuthMechanism($authMechanism);
+ $storage->setBackendOptions(['password' => 'testPassword']);
+
+ $this->service->addStorage($storage);
+ }
+
+ /**
+ * @expectedException \DomainException
+ */
+ public function testUpdateStorage($storageParams = null) {
+ $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);
+ $storage->setAuthMechanism($authMechanism);
+ $storage->setBackendOptions(['password' => 'testPassword']);
+
+ $newStorage = $this->globalStoragesService->addStorage($storage);
+
+ $retrievedStorage = $this->service->getStorage($newStorage->getId());
+ $retrievedStorage->setMountPoint('abc');
+ $this->service->updateStorage($retrievedStorage);
+ }
+
+ /**
+ * @expectedException \DomainException
+ */
+ public function testDeleteStorage() {
+ $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);
+ $storage->setAuthMechanism($authMechanism);
+ $storage->setBackendOptions(['password' => 'testPassword']);
+
+ $newStorage = $this->globalStoragesService->addStorage($storage);
+ $this->assertEquals(1, $newStorage->getId());
+
+ $this->service->removeStorage(1);
+ }
+
+ public function testHooksAddStorage($a = null, $b = null, $c = null) {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+ public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null) {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+ public function testHooksRenameMountPoint() {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+ public function testHooksDeleteStorage($a = null, $b = null, $c = null) {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+ public function testLegacyConfigConversionApplicableAll() {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+ public function testLegacyConfigConversionApplicableUserAndGroup() {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+ public function testReadLegacyConfigAndGenerateConfigId() {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+ public function testReadLegacyConfigNoAuthMechanism() {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+ public function testReadLegacyConfigClass() {
+ // we don't test this here
+ $this->assertTrue(true);
+ }
+
+}
diff --git a/apps/files_external/tests/service/userstoragesservicetest.php b/apps/files_external/tests/service/userstoragesservicetest.php
index ab102741ee2c..0d5b82e2f8c8 100644
--- a/apps/files_external/tests/service/userstoragesservicetest.php
+++ b/apps/files_external/tests/service/userstoragesservicetest.php
@@ -40,7 +40,7 @@ public function setUp() {
->method('getUser')
->will($this->returnValue($this->user));
- $this->service = new UserStoragesService($userSession);
+ $this->service = new UserStoragesService($this->backendService, $userSession);
// create home folder
mkdir($this->dataDir . '/' . $this->userId . '/');
@@ -54,7 +54,8 @@ public function tearDown() {
private function makeTestStorageData() {
return $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -76,7 +77,8 @@ public function testAddStorage() {
$newStorage = $this->service->getStorage(1);
$this->assertEquals($storage->getMountPoint(), $newStorage->getMountPoint());
- $this->assertEquals($storage->getBackendClass(), $newStorage->getBackendClass());
+ $this->assertEquals($storage->getBackend(), $newStorage->getBackend());
+ $this->assertEquals($storage->getAuthMechanism(), $newStorage->getAuthMechanism());
$this->assertEquals($storage->getBackendOptions(), $newStorage->getBackendOptions());
$this->assertEquals(1, $newStorage->getId());
$this->assertEquals(0, $newStorage->getStatus());
@@ -98,7 +100,8 @@ public function testAddStorage() {
public function testUpdateStorage() {
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
- 'backendClass' => '\OC\Files\Storage\SMB',
+ 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
+ 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism',
'backendOptions' => [
'option1' => 'value1',
'option2' => 'value2',
@@ -191,7 +194,8 @@ public function testLegacyConfigConversion() {
$mountPointOptions = current($mountPointData);
$this->assertEquals(1, $mountPointOptions['id']);
- $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']);
+ $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'];
@@ -214,13 +218,15 @@ public function testReadLegacyConfigAndGenerateConfigId() {
$legacyBackendOptions = \OC_Mount_Config::encryptPasswords($legacyBackendOptions);
$legacyConfig = [
- 'class' => '\OC\Files\Storage\SMB',
+ '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',
+ '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 c30a4935ce17..dba5105d7db8 100644
--- a/apps/files_external/tests/storageconfigtest.php
+++ b/apps/files_external/tests/storageconfigtest.php
@@ -26,9 +26,22 @@
class StorageConfigTest extends \Test\TestCase {
public function testJsonSerialization() {
+ $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $backend->method('getIdentifier')
+ ->willReturn('storage::identifier');
+
+ $authMech = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $authMech->method('getIdentifier')
+ ->willReturn('auth::identifier');
+
$storageConfig = new StorageConfig(1);
$storageConfig->setMountPoint('test');
- $storageConfig->setBackendClass('\OC\Files\Storage\SMB');
+ $storageConfig->setBackend($backend);
+ $storageConfig->setAuthMechanism($authMech);
$storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123']);
$storageConfig->setPriority(128);
$storageConfig->setApplicableUsers(['user1', 'user2']);
@@ -39,7 +52,8 @@ public function testJsonSerialization() {
$this->assertEquals(1, $json['id']);
$this->assertEquals('/test', $json['mountPoint']);
- $this->assertEquals('\OC\Files\Storage\SMB', $json['backendClass']);
+ $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']);
diff --git a/lib/private/files/mount/mountpoint.php b/lib/private/files/mount/mountpoint.php
index 5e4949aa9ddb..2871bbd90835 100644
--- a/lib/private/files/mount/mountpoint.php
+++ b/lib/private/files/mount/mountpoint.php
@@ -29,7 +29,6 @@
use \OC\Files\Filesystem;
use OC\Files\Storage\StorageFactory;
use OC\Files\Storage\Storage;
-use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files\Mount\IMountPoint;
class MountPoint implements IMountPoint {
@@ -93,11 +92,7 @@ public function __construct($storage, $mountpoint, $arguments = null, $loader =
$this->mountPoint = $mountpoint;
if ($storage instanceof Storage) {
$this->class = get_class($storage);
- $this->storage = $storage;
- // only wrap if not already wrapped
- if (!($this->storage instanceof Wrapper)) {
- $this->storage = $this->loader->wrap($this, $this->storage);
- }
+ $this->storage = $this->loader->wrap($this, $storage);
} else {
// Update old classes to new namespace
if (strpos($storage, 'OC_Filestorage_') !== false) {
diff --git a/lib/private/files/storage/wrapper/permissionsmask.php b/lib/private/files/storage/wrapper/permissionsmask.php
index 993936321d02..50c3f2a62682 100644
--- a/lib/private/files/storage/wrapper/permissionsmask.php
+++ b/lib/private/files/storage/wrapper/permissionsmask.php
@@ -65,6 +65,10 @@ public function isDeletable($path) {
return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path);
}
+ public function isSharable($path) {
+ return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($parm);
+ }
+
public function getPermissions($path) {
return $this->storage->getPermissions($path) & $this->mask;
}
diff --git a/settings/css/settings.css b/settings/css/settings.css
index 0af63821627b..4432bbd966b3 100644
--- a/settings/css/settings.css
+++ b/settings/css/settings.css
@@ -432,14 +432,16 @@ table.grid td.date{
}
span.success {
- background: #37ce02;
- border-radius: 3px;
+ background: #37ce02;
+ border-radius: 3px;
}
-
span.error {
- background: #ce3702;
+ background: #ce3702;
+}
+span.indeterminate {
+ background: #e6db00;
+ border-radius: 40% 0;
}
-
/* PASSWORD */
.strengthify-wrapper {
diff --git a/settings/personal.php b/settings/personal.php
index 203c9f68af83..bbbba3b5b8dd 100644
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -108,10 +108,7 @@
$enableCertImport = false;
$externalStorageEnabled = \OC::$server->getAppManager()->isEnabledForUser('files_external');
if ($externalStorageEnabled) {
- $backends = OC_Mount_Config::getPersonalBackends();
- if (!empty($backends)) {
- $enableCertImport = true;
- }
+ $enableCertImport = true;
}
diff --git a/tests/lib/files/mount/mountpoint.php b/tests/lib/files/mount/mountpoint.php
index d758c1b8d4d7..29610e6058da 100644
--- a/tests/lib/files/mount/mountpoint.php
+++ b/tests/lib/files/mount/mountpoint.php
@@ -70,25 +70,4 @@ public function testInvalidStorage() {
// storage wrapper never called
$this->assertFalse($called);
}
-
- public function testWrappedStorage() {
- $storage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Wrapper')
- ->disableOriginalConstructor()
- ->getMock();
-
- $loader = $this->getMock('\OCP\Files\Storage\IStorageFactory');
- $loader->expects($this->never())
- ->method('getInstance');
- $loader->expects($this->never())
- ->method('wrap');
-
- $mountPoint = new \OC\Files\Mount\MountPoint(
- $storage,
- '/mountpoint',
- null,
- $loader
- );
-
- $this->assertEquals($storage, $mountPoint->getStorage());
- }
}
|