From 689df9a843dd0505088143de039af775a3f92612 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 18 Jan 2017 21:13:23 +0100 Subject: [PATCH 01/12] LDAP OCS Api for create config Signed-off-by: Arthur Schiwon --- apps/user_ldap/appinfo/routes.php | 7 + .../lib/Command/CreateEmptyConfig.php | 28 ++-- apps/user_ldap/lib/Configuration.php | 9 +- .../lib/Controller/ConfigAPIController.php | 126 ++++++++++++++++++ apps/user_ldap/lib/Helper.php | 19 +++ build/integration/features/ldap-ocs.feature | 7 + 6 files changed, 177 insertions(+), 19 deletions(-) create mode 100644 apps/user_ldap/lib/Controller/ConfigAPIController.php create mode 100644 build/integration/features/ldap-ocs.feature diff --git a/apps/user_ldap/appinfo/routes.php b/apps/user_ldap/appinfo/routes.php index c01a3c11472..e4e0db48d19 100644 --- a/apps/user_ldap/appinfo/routes.php +++ b/apps/user_ldap/appinfo/routes.php @@ -36,3 +36,10 @@ $this->create('user_ldap_ajax_testConfiguration', 'ajax/testConfiguration.php') ->actionInclude('user_ldap/ajax/testConfiguration.php'); $this->create('user_ldap_ajax_wizard', 'ajax/wizard.php') ->actionInclude('user_ldap/ajax/wizard.php'); + +$application = new \OCP\AppFramework\App('user_ldap'); +$application->registerRoutes($this, [ + 'ocs' => [ + ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], + ] +]); diff --git a/apps/user_ldap/lib/Command/CreateEmptyConfig.php b/apps/user_ldap/lib/Command/CreateEmptyConfig.php index 28d3a1d8bff..38d3192058c 100644 --- a/apps/user_ldap/lib/Command/CreateEmptyConfig.php +++ b/apps/user_ldap/lib/Command/CreateEmptyConfig.php @@ -29,6 +29,7 @@ use OCA\User_LDAP\Configuration; use OCA\User_LDAP\Helper; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class CreateEmptyConfig extends Command { @@ -47,29 +48,24 @@ class CreateEmptyConfig extends Command { $this ->setName('ldap:create-empty-config') ->setDescription('creates an empty LDAP configuration') + ->addOption( + 'only-print-prefix', + 'p', + InputOption::VALUE_NONE, + 'outputs only the prefix' + ) ; } protected function execute(InputInterface $input, OutputInterface $output) { - $configPrefix = $this->getNewConfigurationPrefix(); - $output->writeln("Created new configuration with configID '{$configPrefix}'"); - + $configPrefix = $this->helper->getNextServerConfigurationPrefix(); $configHolder = new Configuration($configPrefix); $configHolder->saveConfiguration(); - } - protected function getNewConfigurationPrefix() { - $serverConnections = $this->helper->getServerConfigurationPrefixes(); - - // first connection uses no prefix - if(sizeof($serverConnections) == 0) { - return ''; + $prose = ''; + if(!$input->getOption('only-print-prefix')) { + $prose = 'Created new configuration with configID '; } - - sort($serverConnections); - $lastKey = array_pop($serverConnections); - $lastNumber = intval(str_replace('s', '', $lastKey)); - $nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT); - return $nextPrefix; + $output->writeln($prose . "{$configPrefix}"); } } diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index eb4fcd3fbe6..65ee9c70807 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -393,9 +393,12 @@ class Configuration { * @return bool */ protected function saveValue($varName, $value) { - return \OCP\Config::setAppValue('user_ldap', - $this->configPrefix.$varName, - $value); + \OC::$server->getConfig()->setAppValue( + 'user_ldap', + $this->configPrefix.$varName, + $value + ); + return true; } /** diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php new file mode 100644 index 00000000000..e136b56cda9 --- /dev/null +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -0,0 +1,126 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +namespace OCA\User_LDAP\Controller; + +use OC\CapabilitiesManager; +use OC\Core\Controller\OCSController; +use OC\Security\Bruteforce\Throttler; +use OC\Security\IdentityProof\Manager; +use OCA\User_LDAP\Configuration; +use OCA\User_LDAP\Helper; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCS\OCSException; +use OCP\ILogger; +use OCP\IRequest; +use OCP\IUserManager; +use OCP\IUserSession; + +class ConfigAPIController extends OCSController { + + /** @var Helper */ + private $ldapHelper; + + /** @var ILogger */ + private $logger; + + public function __construct( + $appName, + IRequest $request, + CapabilitiesManager $capabilitiesManager, + IUserSession $userSession, + IUserManager $userManager, + Throttler $throttler, + Manager $keyManager, + Helper $ldapHelper, + ILogger $logger + ) { + parent::__construct( + $appName, + $request, + $capabilitiesManager, + $userSession, + $userManager, + $throttler, + $keyManager + ); + + + $this->ldapHelper = $ldapHelper; + $this->logger = $logger; + } + + /** + * creates a new (empty) configuration and returns the resulting prefix + * + * Example: curl -X POST -H "OCS-APIREQUEST: true" -u $admin:$password \ + * https://nextcloud.server/ocs/v1.php/apps/user_ldap/api/v1/config + * + * results in: + * + * + * + * + * ok + * 100 + * OK + * + * + * + * + * s40 + * + * + * + * Failing example: if an exception is thrown (e.g. Database connection lost) + * the detailed error will be logged. The output will then look like: + * + * + * + * + * failure + * 999 + * An issue occurred when creating the new config. + * + * + * + * + * + * + * For JSON output provide the format=json parameter + * + * @return DataResponse + * @throws OCSException + */ + public function create() { + try { + $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix(); + $configHolder = new Configuration($configPrefix); + $configHolder->saveConfiguration(); + } catch (\Exception $e) { + $this->logger->logException($e); + throw new OCSException('An issue occurred when creating the new config.'); + } + return new DataResponse(['prefix' => $configPrefix]); + } +} diff --git a/apps/user_ldap/lib/Helper.php b/apps/user_ldap/lib/Helper.php index b48b4001f9d..f1186ffa310 100644 --- a/apps/user_ldap/lib/Helper.php +++ b/apps/user_ldap/lib/Helper.php @@ -105,6 +105,25 @@ class Helper { return $result; } + /** + * return the next available configuration prefix + * + * @return string + */ + public function getNextServerConfigurationPrefix() { + $serverConnections = $this->getServerConfigurationPrefixes(); + + if(count($serverConnections) === 0) { + return 's01'; + } + + sort($serverConnections); + $lastKey = array_pop($serverConnections); + $lastNumber = intval(str_replace('s', '', $lastKey)); + $nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT); + return $nextPrefix; + } + private function getServersConfig($value) { $regex = '/' . $value . '$/S'; diff --git a/build/integration/features/ldap-ocs.feature b/build/integration/features/ldap-ocs.feature new file mode 100644 index 00000000000..d8586bb75bf --- /dev/null +++ b/build/integration/features/ldap-ocs.feature @@ -0,0 +1,7 @@ +Feature: LDAP + + Scenario: Creating an new, empty configuration + Given As an "admin" + When sending "POST" to "/apps/user_ldap/api/v1/config" + Then the OCS status code should be "100" + And the HTTP status code should be "200" From a515de54e7d88c0d82bb9287f2a63ccdcc96b0fb Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 18 Jan 2017 23:17:58 +0100 Subject: [PATCH 02/12] LDAP OCS Api for delete config Signed-off-by: Arthur Schiwon --- apps/user_ldap/appinfo/routes.php | 1 + .../lib/Controller/ConfigAPIController.php | 51 +++++++++++++++++++ build/integration/features/ldap-ocs.feature | 14 +++++ 3 files changed, 66 insertions(+) diff --git a/apps/user_ldap/appinfo/routes.php b/apps/user_ldap/appinfo/routes.php index e4e0db48d19..c80d6af76eb 100644 --- a/apps/user_ldap/appinfo/routes.php +++ b/apps/user_ldap/appinfo/routes.php @@ -41,5 +41,6 @@ $application = new \OCP\AppFramework\App('user_ldap'); $application->registerRoutes($this, [ 'ocs' => [ ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], + ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], ] ]); diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index e136b56cda9..5a18b138c3f 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -30,7 +30,9 @@ use OC\Security\IdentityProof\Manager; use OCA\User_LDAP\Configuration; use OCA\User_LDAP\Helper; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; +use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\ILogger; use OCP\IRequest; use OCP\IUserManager; @@ -123,4 +125,53 @@ class ConfigAPIController extends OCSController { } return new DataResponse(['prefix' => $configPrefix]); } + + /** + * Deletes a LDAP configuration, if present. + * + * Example: + * curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \ + * https://nextcloud.server/ocs/v1.php/apps/user_ldap/api/v1/config/s60 + * + * + * + * + * ok + * 100 + * OK + * + * + * + * + * + * + * @param $configID + * @return DataResponse + * @throws OCSBadRequestException + * @throws OCSException + */ + public function delete($configID) { + $initial = substr($configID, 0, 1); + $number = substr($configID, 1); + if($initial !== 's' || $number !== strval(intval($number))) { + throw new OCSBadRequestException('Not a valid config ID'); + } + + try { + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); + if(!in_array($configID, $prefixes)) { + throw new OCSNotFoundException('Config ID not found'); + } + if(!$this->ldapHelper->deleteServerConfiguration($configID)) { + throw new OCSException('Could not delete configuration'); + } + } catch(OCSException $e) { + throw $e; + } catch(\Exception $e) { + $this->logger->logException($e); + throw new OCSException('An issue occurred when deleting the config.'); + } + + return new DataResponse(); + } } diff --git a/build/integration/features/ldap-ocs.feature b/build/integration/features/ldap-ocs.feature index d8586bb75bf..6e1c77e24c9 100644 --- a/build/integration/features/ldap-ocs.feature +++ b/build/integration/features/ldap-ocs.feature @@ -5,3 +5,17 @@ Feature: LDAP When sending "POST" to "/apps/user_ldap/api/v1/config" Then the OCS status code should be "100" And the HTTP status code should be "200" + + Scenario: Delete a non-existing configuration + Given As an "admin" + When sending "DELETE" to "/apps/user_ldap/api/v1/config/s666" + Then the OCS status code should be "404" + And the HTTP status code should be "200" + + Scenario: Delete an invalid configuration + Given As an "admin" + When sending "DELETE" to "/apps/user_ldap/api/v1/config/hack0r" + Then the OCS status code should be "400" + And the HTTP status code should be "200" + + # TODO: Scenario deleting an existing config ID (needs to be created before) From 18a75bec0d87b847790e0c5b695e3d02993ca710 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 19 Jan 2017 10:04:15 +0100 Subject: [PATCH 03/12] fix and extend behat tests Signed-off-by: Arthur Schiwon --- .../lib/Controller/ConfigAPIController.php | 4 +- build/integration/config/behat.yml | 10 ++++ .../features/bootstrap/LDAPContext.php | 58 +++++++++++++++++++ .../ldap-ocs.feature | 8 ++- 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 build/integration/features/bootstrap/LDAPContext.php rename build/integration/{features => ldap_features}/ldap-ocs.feature (68%) diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index 5a18b138c3f..bfdce302af5 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -90,7 +90,7 @@ class ConfigAPIController extends OCSController { * * * - * s40 + * s40 * * * @@ -123,7 +123,7 @@ class ConfigAPIController extends OCSController { $this->logger->logException($e); throw new OCSException('An issue occurred when creating the new config.'); } - return new DataResponse(['prefix' => $configPrefix]); + return new DataResponse(['configID' => $configPrefix]); } /** diff --git a/build/integration/config/behat.yml b/build/integration/config/behat.yml index 82ad6eaa170..3573f9d6a6b 100644 --- a/build/integration/config/behat.yml +++ b/build/integration/config/behat.yml @@ -75,6 +75,16 @@ default: - admin - admin regular_user_password: 123456 + ldap: + paths: + - %paths.base%/../ldap_features + contexts: + - LDAPContext: + baseUrl: http://localhost:8080 + admin: + - admin + - admin + regular_user_password: what_for extensions: jarnaiz\JUnitFormatter\JUnitFormatterExtension: diff --git a/build/integration/features/bootstrap/LDAPContext.php b/build/integration/features/bootstrap/LDAPContext.php new file mode 100644 index 00000000000..92e21715cd4 --- /dev/null +++ b/build/integration/features/bootstrap/LDAPContext.php @@ -0,0 +1,58 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +use Behat\Behat\Context\Context; + +class LDAPContext implements Context { + use BasicStructure; + + protected $configID; + + protected $apiUrl; + + /** + * @Given /^the response should contain a tag "([^"]*)"$/ + */ + public function theResponseShouldContainATag($arg1) { + $configID = $this->response->xml()->data[0]->$arg1; + PHPUnit_Framework_Assert::assertInstanceOf(SimpleXMLElement::class, $configID[0]); + } + + /** + * @Given /^creating a configuration at "([^"]*)"$/ + */ + public function creatingAConfigurationAt($apiUrl) { + $this->apiUrl = $apiUrl; + $this->sendingToWith('POST', $this->apiUrl, null); + $configElements = $this->response->xml()->data[0]->configID; + $this->configID = $configElements[0]; + } + + /** + * @When /^deleting the configuration$/ + */ + public function deletingTheConfiguration() { + $this->sendingToWith('DELETE', $this->apiUrl . '/' . $this->configID, null); + } +} diff --git a/build/integration/features/ldap-ocs.feature b/build/integration/ldap_features/ldap-ocs.feature similarity index 68% rename from build/integration/features/ldap-ocs.feature rename to build/integration/ldap_features/ldap-ocs.feature index 6e1c77e24c9..8498ce2094b 100644 --- a/build/integration/features/ldap-ocs.feature +++ b/build/integration/ldap_features/ldap-ocs.feature @@ -5,6 +5,7 @@ Feature: LDAP When sending "POST" to "/apps/user_ldap/api/v1/config" Then the OCS status code should be "100" And the HTTP status code should be "200" + And the response should contain a tag "configID" Scenario: Delete a non-existing configuration Given As an "admin" @@ -18,4 +19,9 @@ Feature: LDAP Then the OCS status code should be "400" And the HTTP status code should be "200" - # TODO: Scenario deleting an existing config ID (needs to be created before) + Scenario: Create and delete a configuration + Given As an "admin" + And creating a configuration at "/apps/user_ldap/api/v1/config" + When deleting the configuration + Then the OCS status code should be "100" + And the HTTP status code should be "200" From 01d469dfea5c3a3db4ddd449b322f3f9f5ae98b9 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 19 Jan 2017 11:09:04 +0100 Subject: [PATCH 04/12] add LDAP OCS Api for modifying a configuration Signed-off-by: Arthur Schiwon --- apps/user_ldap/appinfo/routes.php | 1 + .../lib/Controller/ConfigAPIController.php | 69 +++++++++++++++++-- .../features/bootstrap/LDAPContext.php | 19 +++-- .../ldap_features/ldap-ocs.feature | 23 ++++++- 4 files changed, 101 insertions(+), 11 deletions(-) diff --git a/apps/user_ldap/appinfo/routes.php b/apps/user_ldap/appinfo/routes.php index c80d6af76eb..f08ec195add 100644 --- a/apps/user_ldap/appinfo/routes.php +++ b/apps/user_ldap/appinfo/routes.php @@ -41,6 +41,7 @@ $application = new \OCP\AppFramework\App('user_ldap'); $application->registerRoutes($this, [ 'ocs' => [ ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], + ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], ] ]); diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index bfdce302af5..8aeb771608d 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -145,7 +145,7 @@ class ConfigAPIController extends OCSController { * * * - * @param $configID + * @param string $configID * @return DataResponse * @throws OCSBadRequestException * @throws OCSException @@ -158,10 +158,7 @@ class ConfigAPIController extends OCSController { } try { - $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); - if(!in_array($configID, $prefixes)) { - throw new OCSNotFoundException('Config ID not found'); - } + $this->ensureConfigIDExists($configID); if(!$this->ldapHelper->deleteServerConfiguration($configID)) { throw new OCSException('Could not delete configuration'); } @@ -174,4 +171,66 @@ class ConfigAPIController extends OCSController { return new DataResponse(); } + + /** + * modifies a configuration + * + * Example: + * curl -X PUT -d "key=ldapHost&value=ldaps://my.ldap.server" \ + * -H "OCS-APIREQUEST: true" -u $admin:$password \ + * https://nextcloud.server/ocs/v1.php/apps/user_ldap/api/v1/config/s60 + * + * + * + * + * ok + * 100 + * OK + * + * + * + * + * + * + * @param string $configID + * @param string $key + * @param string $value + * @return DataResponse + * @throws OCSException + */ + public function modify($configID, $key, $value) { + $this->ensureConfigIDExists($configID); + + try { + $config = new Configuration($configID); + + $configKeys = $config->getConfigTranslationArray(); + if(!isset($configKeys[$key]) && !in_array($key, $configKeys, true)) { + throw new OCSBadRequestException('Invalid config key'); + } + + $config->$key = $value; + $config->saveConfiguration(); + } catch(OCSException $e) { + throw $e; + } catch (\Exception $e) { + $this->logger->logException($e); + throw new OCSException('An issue occurred when modifying the config.'); + } + + return new DataResponse(); + } + + /** + * if the given config ID is not available, an exception is thrown + * + * @param string $configID + * @throws OCSNotFoundException + */ + private function ensureConfigIDExists($configID) { + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); + if(!in_array($configID, $prefixes)) { + throw new OCSNotFoundException('Config ID not found'); + } + } } diff --git a/build/integration/features/bootstrap/LDAPContext.php b/build/integration/features/bootstrap/LDAPContext.php index 92e21715cd4..3a66641685a 100644 --- a/build/integration/features/bootstrap/LDAPContext.php +++ b/build/integration/features/bootstrap/LDAPContext.php @@ -40,9 +40,9 @@ class LDAPContext implements Context { } /** - * @Given /^creating a configuration at "([^"]*)"$/ + * @Given /^creating an LDAP configuration at "([^"]*)"$/ */ - public function creatingAConfigurationAt($apiUrl) { + public function creatingAnLDAPConfigurationAt($apiUrl) { $this->apiUrl = $apiUrl; $this->sendingToWith('POST', $this->apiUrl, null); $configElements = $this->response->xml()->data[0]->configID; @@ -50,9 +50,20 @@ class LDAPContext implements Context { } /** - * @When /^deleting the configuration$/ + * @When /^deleting the LDAP configuration$/ */ - public function deletingTheConfiguration() { + public function deletingTheLDAPConfiguration() { $this->sendingToWith('DELETE', $this->apiUrl . '/' . $this->configID, null); } + + /** + * @When /^setting "([^"]*)" of the LDAP configuration to "([^"]*)"$/ + */ + public function settingOfTheLDAPConfigurationTo($key, $value) { + $this->sendingToWith( + 'PUT', + $this->apiUrl . '/' . $this->configID, + new \Behat\Gherkin\Node\TableNode([['key', $key], ['value', $value]]) + ); + } } diff --git a/build/integration/ldap_features/ldap-ocs.feature b/build/integration/ldap_features/ldap-ocs.feature index 8498ce2094b..7d3a4fd9491 100644 --- a/build/integration/ldap_features/ldap-ocs.feature +++ b/build/integration/ldap_features/ldap-ocs.feature @@ -21,7 +21,26 @@ Feature: LDAP Scenario: Create and delete a configuration Given As an "admin" - And creating a configuration at "/apps/user_ldap/api/v1/config" - When deleting the configuration + And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" + When deleting the LDAP configuration Then the OCS status code should be "100" And the HTTP status code should be "200" + + Scenario: Create and modify a configuration + Given As an "admin" + And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" + When setting "ldapHost" of the LDAP configuration to "ldaps://my.ldap.server" + Then the OCS status code should be "100" + And the HTTP status code should be "200" + # Testing an invalid config key + When setting "crack0r" of the LDAP configuration to "foobar" + Then the OCS status code should be "400" + And the HTTP status code should be "200" + + Scenario: Modiying a non-existing configuration + Given As an "admin" + When sending "PUT" to "/apps/user_ldap/api/v1/config/s666" with + | key | ldapHost | + | value | ldaps://my.ldap.server | + Then the OCS status code should be "404" + And the HTTP status code should be "200" From f2c9d04eac7c0875040b3e46cc1dccc7d290789f Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 19 Jan 2017 12:48:50 +0100 Subject: [PATCH 05/12] test against OCS v2 instead Signed-off-by: Arthur Schiwon --- .../lib/Controller/ConfigAPIController.php | 16 ++++------------ build/integration/ldap_features/ldap-ocs.feature | 16 +++++++++------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index 8aeb771608d..371ca899c26 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -76,7 +76,7 @@ class ConfigAPIController extends OCSController { * creates a new (empty) configuration and returns the resulting prefix * * Example: curl -X POST -H "OCS-APIREQUEST: true" -u $admin:$password \ - * https://nextcloud.server/ocs/v1.php/apps/user_ldap/api/v1/config + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config * * results in: * @@ -84,10 +84,8 @@ class ConfigAPIController extends OCSController { * * * ok - * 100 + * 200 * OK - * - * * * * s40 @@ -103,8 +101,6 @@ class ConfigAPIController extends OCSController { * failure * 999 * An issue occurred when creating the new config. - * - * * * * @@ -131,7 +127,7 @@ class ConfigAPIController extends OCSController { * * Example: * curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \ - * https://nextcloud.server/ocs/v1.php/apps/user_ldap/api/v1/config/s60 + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 * * * @@ -139,8 +135,6 @@ class ConfigAPIController extends OCSController { * ok * 100 * OK - * - * * * * @@ -178,7 +172,7 @@ class ConfigAPIController extends OCSController { * Example: * curl -X PUT -d "key=ldapHost&value=ldaps://my.ldap.server" \ * -H "OCS-APIREQUEST: true" -u $admin:$password \ - * https://nextcloud.server/ocs/v1.php/apps/user_ldap/api/v1/config/s60 + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 * * * @@ -186,8 +180,6 @@ class ConfigAPIController extends OCSController { * ok * 100 * OK - * - * * * * diff --git a/build/integration/ldap_features/ldap-ocs.feature b/build/integration/ldap_features/ldap-ocs.feature index 7d3a4fd9491..d925df3256d 100644 --- a/build/integration/ldap_features/ldap-ocs.feature +++ b/build/integration/ldap_features/ldap-ocs.feature @@ -1,9 +1,11 @@ Feature: LDAP + Background: + Given using api version "2" Scenario: Creating an new, empty configuration Given As an "admin" When sending "POST" to "/apps/user_ldap/api/v1/config" - Then the OCS status code should be "100" + Then the OCS status code should be "200" And the HTTP status code should be "200" And the response should contain a tag "configID" @@ -11,31 +13,31 @@ Feature: LDAP Given As an "admin" When sending "DELETE" to "/apps/user_ldap/api/v1/config/s666" Then the OCS status code should be "404" - And the HTTP status code should be "200" + And the HTTP status code should be "404" Scenario: Delete an invalid configuration Given As an "admin" When sending "DELETE" to "/apps/user_ldap/api/v1/config/hack0r" Then the OCS status code should be "400" - And the HTTP status code should be "200" + And the HTTP status code should be "400" Scenario: Create and delete a configuration Given As an "admin" And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" When deleting the LDAP configuration - Then the OCS status code should be "100" + Then the OCS status code should be "200" And the HTTP status code should be "200" Scenario: Create and modify a configuration Given As an "admin" And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" When setting "ldapHost" of the LDAP configuration to "ldaps://my.ldap.server" - Then the OCS status code should be "100" + Then the OCS status code should be "200" And the HTTP status code should be "200" # Testing an invalid config key When setting "crack0r" of the LDAP configuration to "foobar" Then the OCS status code should be "400" - And the HTTP status code should be "200" + And the HTTP status code should be "400" Scenario: Modiying a non-existing configuration Given As an "admin" @@ -43,4 +45,4 @@ Feature: LDAP | key | ldapHost | | value | ldaps://my.ldap.server | Then the OCS status code should be "404" - And the HTTP status code should be "200" + And the HTTP status code should be "404" From 1f7b08bd19dd37bec73903679b3e0bfdaed71927 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 19 Jan 2017 15:19:20 +0100 Subject: [PATCH 06/12] LDAP OCS Api for show config Signed-off-by: Arthur Schiwon --- apps/user_ldap/appinfo/routes.php | 1 + .../lib/Controller/ConfigAPIController.php | 94 +++++++++++++++++++ .../features/bootstrap/LDAPContext.php | 19 ++++ .../ldap_features/ldap-ocs.feature | 22 +++++ 4 files changed, 136 insertions(+) diff --git a/apps/user_ldap/appinfo/routes.php b/apps/user_ldap/appinfo/routes.php index f08ec195add..45b43c21409 100644 --- a/apps/user_ldap/appinfo/routes.php +++ b/apps/user_ldap/appinfo/routes.php @@ -41,6 +41,7 @@ $application = new \OCP\AppFramework\App('user_ldap'); $application->registerRoutes($this, [ 'ocs' => [ ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], + ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], ] diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index 371ca899c26..5256b0d8aad 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -213,6 +213,100 @@ class ConfigAPIController extends OCSController { return new DataResponse(); } + /** + * retrieves a configuration + * + * + * + * + * ok + * 200 + * OK + * + * + * ldaps://my.ldap.server + * 7770 + * + * + * ou=small,dc=my,dc=ldap,dc=server + * ou=users,ou=small,dc=my,dc=ldap,dc=server + * ou=small,dc=my,dc=ldap,dc=server + * cn=root,dc=my,dc=ldap,dc=server + * clearTextWithShowPassword=1 + * 1 + * 0 + * + * displayname + * uid + * inetOrgPerson + * + * (&(objectclass=nextcloudUser)(nextcloudEnabled=TRUE)) + * 1 + * (&(|(objectclass=nextcloudGroup))) + * 0 + * nextcloudGroup + * + * cn + * memberUid + * (&(|(objectclass=inetOrgPerson))(uid=%uid)) + * 0 + * 0 + * 1 + * + * + * + * mail + * 20 + * auto + * auto + * + * 1 + * uid;sn;givenname + * + * 0 + * + * + * + * 1 + * uid + * uid + * + * 0 + * 0 + * 500 + * 1 + * + * + * + * + * @param string $configID + * @param bool|string $showPassword + * @return DataResponse + * @throws OCSException + */ + public function show($configID, $showPassword = false) { + $this->ensureConfigIDExists($configID); + + try { + $config = new Configuration($configID); + $data = $config->getConfiguration(); + if(!boolval(intval($showPassword))) { + $data['ldapAgentPassword'] = '***'; + } + foreach ($data as $key => $value) { + if(is_array($value)) { + $value = implode(';', $value); + $data[$key] = $value; + } + } + } catch (\Exception $e) { + $this->logger->logException($e); + throw new OCSException('An issue occurred when modifying the config.'); + } + + return new DataResponse($data); + } + /** * if the given config ID is not available, an exception is thrown * diff --git a/build/integration/features/bootstrap/LDAPContext.php b/build/integration/features/bootstrap/LDAPContext.php index 3a66641685a..5d1f75ceff4 100644 --- a/build/integration/features/bootstrap/LDAPContext.php +++ b/build/integration/features/bootstrap/LDAPContext.php @@ -66,4 +66,23 @@ class LDAPContext implements Context { new \Behat\Gherkin\Node\TableNode([['key', $key], ['value', $value]]) ); } + + /** + * @Given /^the response should contain a tag "([^"]*)" with value "([^"]*)"$/ + */ + public function theResponseShouldContainATagWithValue($tagName, $expectedValue) { + $data = $this->response->xml()->data[0]->$tagName; + PHPUnit_Framework_Assert::assertEquals($expectedValue, $data[0]); + } + + /** + * @When /^getting the LDAP configuration with showPassword "([^"]*)"$/ + */ + public function gettingTheLDAPConfigurationWithShowPassword($showPassword) { + $this->sendingToWith( + 'GET', + $this->apiUrl . '/' . $this->configID . '?showPassword=' . $showPassword, + null + ); + } } diff --git a/build/integration/ldap_features/ldap-ocs.feature b/build/integration/ldap_features/ldap-ocs.feature index d925df3256d..df643b8a01c 100644 --- a/build/integration/ldap_features/ldap-ocs.feature +++ b/build/integration/ldap_features/ldap-ocs.feature @@ -46,3 +46,25 @@ Feature: LDAP | value | ldaps://my.ldap.server | Then the OCS status code should be "404" And the HTTP status code should be "404" + + Scenario: create, modify and get a configuration + Given As an "admin" + And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" + And setting "ldapHost" of the LDAP configuration to "ldaps://my.ldap.server" + And setting "ldapLoginFilter" of the LDAP configuration to "(&(|(objectclass=inetOrgPerson))(uid=%uid))" + And setting "ldapAgentPassword" of the LDAP configuration to "psst,secret" + When getting the LDAP configuration with showPassword "0" + Then the OCS status code should be "200" + And the HTTP status code should be "200" + And the response should contain a tag "ldapHost" with value "ldaps://my.ldap.server" + And the response should contain a tag "ldapLoginFilter" with value "(&(|(objectclass=inetOrgPerson))(uid=%uid))" + And the response should contain a tag "ldapAgentPassword" with value "***" + + Scenario: receiving password in plain text + Given As an "admin" + And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" + And setting "ldapAgentPassword" of the LDAP configuration to "psst,secret" + When getting the LDAP configuration with showPassword "1" + Then the OCS status code should be "200" + And the HTTP status code should be "200" + And the response should contain a tag "ldapAgentPassword" with value "psst,secret" From 22528f492f18be019cc7dea676e70f6328b353ce Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 19 Jan 2017 17:12:00 +0100 Subject: [PATCH 07/12] also, let ldap integration tests run Signed-off-by: Arthur Schiwon --- .drone.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.drone.yml b/.drone.yml index 1e35b2a2fe8..bac887ff024 100644 --- a/.drone.yml +++ b/.drone.yml @@ -413,6 +413,15 @@ pipeline: when: matrix: TESTS: integration-transfer-ownership-features + integration-ldap-features: + image: nextcloudci/integration-php7.0:integration-php7.0-3 + commands: + - ./occ maintenance:install --admin-pass=admin + - cd build/integration + - ./run.sh ldap_features/ldap-ocs.feature + when: + matrix: + TESTS: integration-ldap-features nodb-codecov: image: nextcloudci/php7.0:php7.0-7 commands: @@ -480,6 +489,7 @@ matrix: - TESTS: integration-setup-features - TESTS: integration-filesdrop-features - TESTS: integration-transfer-ownership-features + - TESTS: integration-ldap-features - TESTS: jsunit - TESTS: check-autoloader - TESTS: app-check-code From 31a08218635e8fadd49389d11a94321d9bdc274a Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 19 Jan 2017 13:06:50 -0600 Subject: [PATCH 08/12] fix indentation Signed-off-by: Morris Jobke --- .drone.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.drone.yml b/.drone.yml index bac887ff024..ccd76e18597 100644 --- a/.drone.yml +++ b/.drone.yml @@ -413,15 +413,15 @@ pipeline: when: matrix: TESTS: integration-transfer-ownership-features - integration-ldap-features: - image: nextcloudci/integration-php7.0:integration-php7.0-3 - commands: - - ./occ maintenance:install --admin-pass=admin - - cd build/integration - - ./run.sh ldap_features/ldap-ocs.feature - when: - matrix: - TESTS: integration-ldap-features + integration-ldap-features: + image: nextcloudci/integration-php7.0:integration-php7.0-3 + commands: + - ./occ maintenance:install --admin-pass=admin + - cd build/integration + - ./run.sh ldap_features/ldap-ocs.feature + when: + matrix: + TESTS: integration-ldap-features nodb-codecov: image: nextcloudci/php7.0:php7.0-7 commands: From 08b31fcb7da9f65e5d4fc87f266a183d1353e193 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 20 Jan 2017 10:10:37 +0100 Subject: [PATCH 09/12] enable user_ldap app for tests Signed-off-by: Arthur Schiwon --- .drone.yml | 1 + build/integration/ldap_features/ldap-ocs.feature | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index ccd76e18597..5e4f18af9f6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -417,6 +417,7 @@ pipeline: image: nextcloudci/integration-php7.0:integration-php7.0-3 commands: - ./occ maintenance:install --admin-pass=admin + - ./occ app:enable user_ldap - cd build/integration - ./run.sh ldap_features/ldap-ocs.feature when: diff --git a/build/integration/ldap_features/ldap-ocs.feature b/build/integration/ldap_features/ldap-ocs.feature index df643b8a01c..2815b308d48 100644 --- a/build/integration/ldap_features/ldap-ocs.feature +++ b/build/integration/ldap_features/ldap-ocs.feature @@ -39,7 +39,7 @@ Feature: LDAP Then the OCS status code should be "400" And the HTTP status code should be "400" - Scenario: Modiying a non-existing configuration + Scenario: Modifying a non-existing configuration Given As an "admin" When sending "PUT" to "/apps/user_ldap/api/v1/config/s666" with | key | ldapHost | From 9ca4065ef5ccce3a4bc807e4b7bfddd76f50724c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 20 Jan 2017 21:57:12 +0100 Subject: [PATCH 10/12] LDAP PUT command now supports setting multiple keys at once Signed-off-by: Arthur Schiwon --- .../lib/Controller/ConfigAPIController.php | 32 ++++++++++--------- .../features/bootstrap/LDAPContext.php | 19 +++++------ .../ldap_features/ldap-ocs.feature | 28 +++++++++------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index 5256b0d8aad..7a5a5c5b7ba 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -133,7 +133,7 @@ class ConfigAPIController extends OCSController { * * * ok - * 100 + * 200 * OK * * @@ -170,7 +170,7 @@ class ConfigAPIController extends OCSController { * modifies a configuration * * Example: - * curl -X PUT -d "key=ldapHost&value=ldaps://my.ldap.server" \ + * curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \ * -H "OCS-APIREQUEST: true" -u $admin:$password \ * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 * @@ -178,33 +178,35 @@ class ConfigAPIController extends OCSController { * * * ok - * 100 + * 200 * OK * * * * * @param string $configID - * @param string $key - * @param string $value + * @param array $configData * @return DataResponse * @throws OCSException */ - public function modify($configID, $key, $value) { + public function modify($configID, $configData) { $this->ensureConfigIDExists($configID); - try { - $config = new Configuration($configID); + if(!is_array($configData)) { + throw new OCSBadRequestException('configData is not properly set'); + } - $configKeys = $config->getConfigTranslationArray(); - if(!isset($configKeys[$key]) && !in_array($key, $configKeys, true)) { - throw new OCSBadRequestException('Invalid config key'); + try { + $configuration = new Configuration($configID); + $configKeys = $configuration->getConfigTranslationArray(); + + foreach ($configKeys as $i => $key) { + if(isset($configData[$key])) { + $configuration->$key = $configData[$key]; + } } - $config->$key = $value; - $config->saveConfiguration(); - } catch(OCSException $e) { - throw $e; + $configuration->saveConfiguration(); } catch (\Exception $e) { $this->logger->logException($e); throw new OCSException('An issue occurred when modifying the config.'); diff --git a/build/integration/features/bootstrap/LDAPContext.php b/build/integration/features/bootstrap/LDAPContext.php index 5d1f75ceff4..f23de6f47cd 100644 --- a/build/integration/features/bootstrap/LDAPContext.php +++ b/build/integration/features/bootstrap/LDAPContext.php @@ -23,6 +23,7 @@ */ use Behat\Behat\Context\Context; +use Behat\Gherkin\Node\TableNode; class LDAPContext implements Context { use BasicStructure; @@ -56,17 +57,6 @@ class LDAPContext implements Context { $this->sendingToWith('DELETE', $this->apiUrl . '/' . $this->configID, null); } - /** - * @When /^setting "([^"]*)" of the LDAP configuration to "([^"]*)"$/ - */ - public function settingOfTheLDAPConfigurationTo($key, $value) { - $this->sendingToWith( - 'PUT', - $this->apiUrl . '/' . $this->configID, - new \Behat\Gherkin\Node\TableNode([['key', $key], ['value', $value]]) - ); - } - /** * @Given /^the response should contain a tag "([^"]*)" with value "([^"]*)"$/ */ @@ -85,4 +75,11 @@ class LDAPContext implements Context { null ); } + + /** + * @Given /^setting the LDAP configuration to$/ + */ + public function settingTheLDAPConfigurationTo(TableNode $configData) { + $this->sendingToWith('PUT', $this->apiUrl . '/' . $this->configID, $configData); + } } diff --git a/build/integration/ldap_features/ldap-ocs.feature b/build/integration/ldap_features/ldap-ocs.feature index 2815b308d48..663bdcb56fd 100644 --- a/build/integration/ldap_features/ldap-ocs.feature +++ b/build/integration/ldap_features/ldap-ocs.feature @@ -31,28 +31,33 @@ Feature: LDAP Scenario: Create and modify a configuration Given As an "admin" And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" - When setting "ldapHost" of the LDAP configuration to "ldaps://my.ldap.server" + When setting the LDAP configuration to + | configData[ldapHost] | ldaps://my.ldap.server | Then the OCS status code should be "200" And the HTTP status code should be "200" - # Testing an invalid config key - When setting "crack0r" of the LDAP configuration to "foobar" - Then the OCS status code should be "400" - And the HTTP status code should be "400" Scenario: Modifying a non-existing configuration Given As an "admin" When sending "PUT" to "/apps/user_ldap/api/v1/config/s666" with - | key | ldapHost | - | value | ldaps://my.ldap.server | + | configData[ldapHost] | ldaps://my.ldap.server | Then the OCS status code should be "404" And the HTTP status code should be "404" + Scenario: Modifying an existing configuration with malformed configData + Given As an "admin" + And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" + When setting the LDAP configuration to + | configData | ldapHost=ldaps://my.ldap.server | + Then the OCS status code should be "400" + And the HTTP status code should be "400" + Scenario: create, modify and get a configuration Given As an "admin" And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" - And setting "ldapHost" of the LDAP configuration to "ldaps://my.ldap.server" - And setting "ldapLoginFilter" of the LDAP configuration to "(&(|(objectclass=inetOrgPerson))(uid=%uid))" - And setting "ldapAgentPassword" of the LDAP configuration to "psst,secret" + And setting the LDAP configuration to + | configData[ldapHost] | ldaps://my.ldap.server | + | configData[ldapLoginFilter] | (&(\|(objectclass=inetOrgPerson))(uid=%uid)) | + | configData[ldapAgentPassword] | psst,secret | When getting the LDAP configuration with showPassword "0" Then the OCS status code should be "200" And the HTTP status code should be "200" @@ -63,7 +68,8 @@ Feature: LDAP Scenario: receiving password in plain text Given As an "admin" And creating an LDAP configuration at "/apps/user_ldap/api/v1/config" - And setting "ldapAgentPassword" of the LDAP configuration to "psst,secret" + And setting the LDAP configuration to + | configData[ldapAgentPassword] | psst,secret | When getting the LDAP configuration with showPassword "1" Then the OCS status code should be "200" And the HTTP status code should be "200" From 91ed70f0942640bec10bc69a414525a8d1779f8a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 20 Jan 2017 23:01:21 +0100 Subject: [PATCH 11/12] fix deletion for configIDs < s10 Also move ensureConfigIDExists checks into try, it might throw DB related exceptions Signed-off-by: Arthur Schiwon --- .../lib/Controller/ConfigAPIController.php | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index 7a5a5c5b7ba..7d51b0aafe4 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -145,12 +145,6 @@ class ConfigAPIController extends OCSController { * @throws OCSException */ public function delete($configID) { - $initial = substr($configID, 0, 1); - $number = substr($configID, 1); - if($initial !== 's' || $number !== strval(intval($number))) { - throw new OCSBadRequestException('Not a valid config ID'); - } - try { $this->ensureConfigIDExists($configID); if(!$this->ldapHelper->deleteServerConfiguration($configID)) { @@ -190,13 +184,13 @@ class ConfigAPIController extends OCSController { * @throws OCSException */ public function modify($configID, $configData) { - $this->ensureConfigIDExists($configID); - - if(!is_array($configData)) { - throw new OCSBadRequestException('configData is not properly set'); - } - try { + $this->ensureConfigIDExists($configID); + + if(!is_array($configData)) { + throw new OCSBadRequestException('configData is not properly set'); + } + $configuration = new Configuration($configID); $configKeys = $configuration->getConfigTranslationArray(); @@ -207,6 +201,8 @@ class ConfigAPIController extends OCSController { } $configuration->saveConfiguration(); + } catch(OCSException $e) { + throw $e; } catch (\Exception $e) { $this->logger->logException($e); throw new OCSException('An issue occurred when modifying the config.'); @@ -287,9 +283,9 @@ class ConfigAPIController extends OCSController { * @throws OCSException */ public function show($configID, $showPassword = false) { - $this->ensureConfigIDExists($configID); - try { + $this->ensureConfigIDExists($configID); + $config = new Configuration($configID); $data = $config->getConfiguration(); if(!boolval(intval($showPassword))) { @@ -301,6 +297,8 @@ class ConfigAPIController extends OCSController { $data[$key] = $value; } } + } catch(OCSException $e) { + throw $e; } catch (\Exception $e) { $this->logger->logException($e); throw new OCSException('An issue occurred when modifying the config.'); @@ -317,7 +315,7 @@ class ConfigAPIController extends OCSController { */ private function ensureConfigIDExists($configID) { $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); - if(!in_array($configID, $prefixes)) { + if(!in_array($configID, $prefixes, true)) { throw new OCSNotFoundException('Config ID not found'); } } From 680fef76f8f5e34d4c47bcaac40e746a9ac72202 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 20 Jan 2017 23:41:20 +0100 Subject: [PATCH 12/12] remove outdated scenario covered by "Delete a non-existing configuration" Signed-off-by: Arthur Schiwon --- build/integration/ldap_features/ldap-ocs.feature | 6 ------ 1 file changed, 6 deletions(-) diff --git a/build/integration/ldap_features/ldap-ocs.feature b/build/integration/ldap_features/ldap-ocs.feature index 663bdcb56fd..a9ad0478702 100644 --- a/build/integration/ldap_features/ldap-ocs.feature +++ b/build/integration/ldap_features/ldap-ocs.feature @@ -15,12 +15,6 @@ Feature: LDAP Then the OCS status code should be "404" And the HTTP status code should be "404" - Scenario: Delete an invalid configuration - Given As an "admin" - When sending "DELETE" to "/apps/user_ldap/api/v1/config/hack0r" - Then the OCS status code should be "400" - And the HTTP status code should be "400" - Scenario: Create and delete a configuration Given As an "admin" And creating an LDAP configuration at "/apps/user_ldap/api/v1/config"