summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-01-20 21:57:12 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-01-20 22:01:08 +0100
commit9ca4065ef5ccce3a4bc807e4b7bfddd76f50724c (patch)
treeef2094be85ef640cd55b8ac20d3bf933761fa7d3
parent08b31fcb7da9f65e5d4fc87f266a183d1353e193 (diff)
downloadnextcloud-server-9ca4065ef5ccce3a4bc807e4b7bfddd76f50724c.tar.gz
nextcloud-server-9ca4065ef5ccce3a4bc807e4b7bfddd76f50724c.zip
LDAP PUT command now supports setting multiple keys at once
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r--apps/user_ldap/lib/Controller/ConfigAPIController.php30
-rw-r--r--build/integration/features/bootstrap/LDAPContext.php19
-rw-r--r--build/integration/ldap_features/ldap-ocs.feature28
3 files changed, 41 insertions, 36 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 {
* <ocs>
* <meta>
* <status>ok</status>
- * <statuscode>100</statuscode>
+ * <statuscode>200</statuscode>
* <message>OK</message>
* </meta>
* <data/>
@@ -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 {
* <ocs>
* <meta>
* <status>ok</status>
- * <statuscode>100</statuscode>
+ * <statuscode>200</statuscode>
* <message>OK</message>
* </meta>
* <data/>
* </ocs>
*
* @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);
+ if(!is_array($configData)) {
+ throw new OCSBadRequestException('configData is not properly set');
+ }
+
try {
- $config = new Configuration($configID);
+ $configuration = new Configuration($configID);
+ $configKeys = $configuration->getConfigTranslationArray();
- $configKeys = $config->getConfigTranslationArray();
- if(!isset($configKeys[$key]) && !in_array($key, $configKeys, true)) {
- throw new OCSBadRequestException('Invalid config key');
+ 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;
@@ -57,17 +58,6 @@ class LDAPContext implements Context {
}
/**
- * @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 "([^"]*)"$/
*/
public function theResponseShouldContainATagWithValue($tagName, $expectedValue) {
@@ -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"