From e3eda917ef947af04268a1e11975524de0c77c94 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 18 Jan 2016 12:04:37 +0100 Subject: [PATCH 1/3] Show the proper auth identifier when listing mounts as json --- apps/files_external/command/listcommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/command/listcommand.php b/apps/files_external/command/listcommand.php index c978ae5cfc..5a0794be4c 100644 --- a/apps/files_external/command/listcommand.php +++ b/apps/files_external/command/listcommand.php @@ -146,7 +146,7 @@ class ListCommand extends Base { $config->getId(), $config->getMountPoint(), $config->getBackend()->getStorageClass(), - $config->getAuthMechanism()->getScheme(), + $config->getAuthMechanism()->getIdentifier(), $config->getBackendOptions(), $config->getMountOptions() ]; From 71992f9d29c61c867b79d51b74e24113a8a72750 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 18 Jan 2016 12:06:10 +0100 Subject: [PATCH 2/3] update import logic for the new export logic --- apps/files_external/command/import.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_external/command/import.php b/apps/files_external/command/import.php index fe27051359..28032c207b 100644 --- a/apps/files_external/command/import.php +++ b/apps/files_external/command/import.php @@ -194,8 +194,8 @@ class Import extends Base { $mount = new StorageConfig($data['mount_id']); $mount->setMountPoint($data['mount_point']); $mount->setBackend($this->getBackendByClass($data['storage'])); - $authBackends = $this->backendService->getAuthMechanismsByScheme([$data['authentication_type']]); - $mount->setAuthMechanism(current($authBackends)); + $authBackend = $this->backendService->getAuthMechanism($data['authentication_type']); + $mount->setAuthMechanism($authBackend); $mount->setBackendOptions($data['configuration']); $mount->setMountOptions($data['options']); $mount->setApplicableUsers(isset($data['applicable_users']) ? $data['applicable_users'] : []); From 76d9586339d59f7e2aaa2aecce45df7e324e8532 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 4 Feb 2016 16:14:17 +0100 Subject: [PATCH 3/3] add tests --- .../tests/command/listcommandtest.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 apps/files_external/tests/command/listcommandtest.php diff --git a/apps/files_external/tests/command/listcommandtest.php b/apps/files_external/tests/command/listcommandtest.php new file mode 100644 index 0000000000..338ddb7593 --- /dev/null +++ b/apps/files_external/tests/command/listcommandtest.php @@ -0,0 +1,69 @@ + + * + * @copyright Copyright (c) 2016, 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\Command; + +use OCA\Files_External\Command\ListCommand; +use OCA\Files_External\Lib\Auth\NullMechanism; +use OCA\Files_External\Lib\Auth\Password\Password; +use OCA\Files_External\Lib\Auth\Password\UserProvided; +use OCA\Files_External\Lib\Backend\Local; +use OCA\Files_external\Lib\StorageConfig; +use Symfony\Component\Console\Output\BufferedOutput; + +class ListCommandTest extends CommandTest { + /** + * @return \OCA\Files_External\Command\ListCommand|\PHPUnit_Framework_MockObject_MockObject + */ + private function getInstance() { + /** @var \OCA\Files_external\Service\GlobalStoragesService|\PHPUnit_Framework_MockObject_MockObject $globalService */ + $globalService = $this->getMock('\OCA\Files_external\Service\GlobalStoragesService', null, [], '', false); + /** @var \OCA\Files_external\Service\UserStoragesService|\PHPUnit_Framework_MockObject_MockObject $userService */ + $userService = $this->getMock('\OCA\Files_external\Service\UserStoragesService', null, [], '', false); + /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */ + $userManager = $this->getMock('\OCP\IUserManager'); + /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */ + $userSession = $this->getMock('\OCP\IUserSession'); + + return new ListCommand($globalService, $userService, $userSession, $userManager); + } + + public function testListAuthIdentifier() { + $l10n = $this->getMock('\OC_L10N', null, [], '', false); + $credentialsManager = $this->getMock('\OCP\Security\ICredentialsManager'); + $instance = $this->getInstance(); + $mount1 = new StorageConfig(); + $mount1->setAuthMechanism(new Password($l10n)); + $mount1->setBackend(new Local($l10n, new NullMechanism($l10n))); + $mount2 = new StorageConfig(); + $mount2->setAuthMechanism(new UserProvided($l10n, $credentialsManager)); + $mount2->setBackend(new Local($l10n, new NullMechanism($l10n))); + $input = $this->getInput($instance, [], [ + 'output' => 'json' + ]); + $output = new BufferedOutput(); + + $instance->listMounts('', [$mount1, $mount2], $input, $output); + $output = json_decode($output->fetch(), true); + + $this->assertNotEquals($output[0]['authentication_type'], $output[1]['authentication_type']); + } +}