Add an OCS app for testing instead of using sudo and exec

This commit is contained in:
Joas Schilling 2015-12-09 16:08:14 +01:00 committed by Thomas Müller
parent 0449dc387b
commit 7d3e40c065
5 changed files with 172 additions and 41 deletions

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<info>
<id>testing</id>
<name>QA Testing</name>
<description>This app is only for testing! It is dangerous to have it enabled in a live instance</description>
<licence>AGPL</licence>
<author>Joas Schilling</author>
<version>0.1.0</version>
<dependencies>
<owncloud min-version="9.0" />
</dependencies>
</info>

View File

@ -0,0 +1,46 @@
<?php
/**
* @author Joas Schilling <nickvergessen@owncloud.com>
*
* @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 <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Testing\AppInfo;
use OCA\Testing\Config;
use OCP\API;
$config = new Config(
\OC::$server->getConfig(),
\OC::$server->getRequest()
);
API::register(
'post',
'/apps/testing/api/v1/app/{appid}/{configkey}',
[$config, 'setAppValue'],
'testing',
API::ADMIN_AUTH
);
API::register(
'delete',
'/apps/testing/api/v1/app/{appid}/{configkey}',
[$config, 'deleteAppValue'],
'testing',
API::ADMIN_AUTH
);

70
apps/testing/config.php Normal file
View File

@ -0,0 +1,70 @@
<?php
/**
* @author Joas Schilling <nickvergessen@owncloud.com>
*
* @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 <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Testing;
use OCP\IConfig;
use OCP\IRequest;
class Config {
/** @var IConfig */
private $config;
/** @var IRequest */
private $request;
/**
* @param IConfig $config
* @param IRequest $request
*/
public function __construct(IConfig $config, IRequest $request) {
$this->config = $config;
$this->request = $request;
}
/**
* @param array $parameters
* @return \OC_OCS_Result
*/
public function setAppValue($parameters) {
$app = $parameters['appid'];
$configKey = $parameters['configkey'];
$value = $this->request->getParam('value');
$this->config->setAppValue($app, $configKey, $value);
return new \OC_OCS_Result();
}
/**
* @param array $parameters
* @return \OC_OCS_Result
*/
public function deleteAppValue($parameters) {
$app = $parameters['appid'];
$configKey = $parameters['configkey'];
$this->config->deleteAppValue($app, $configKey);
return new \OC_OCS_Result();
}
}

View File

@ -14,30 +14,21 @@ class CapabilitiesContext implements Context, SnippetAcceptingContext {
use Provisioning; use Provisioning;
use Sharing; use Sharing;
private $apacheUser = NULL;
/** /**
* @Given /^parameter "([^"]*)" of app "([^"]*)" is set to "([^"]*)"$/ * @Given /^parameter "([^"]*)" of app "([^"]*)" is set to "([^"]*)"$/
*/ */
public function serverParameterIsSetTo($parameter, $app, $value){ public function serverParameterIsSetTo($parameter, $app, $value){
if (!isset($this->apacheUser)){ $this->modifyServerConfig($app, $parameter, $value);
$this->apacheUser = $this->getOSApacheUser();
}
$this->modifyServerConfig($this->apacheUser, $parameter, $app, $value);
} }
/** /**
* @Then /^fields of capabilities match with$/ * @Then /^fields of capabilities match with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData * @param \Behat\Gherkin\Node\TableNode|null $formData
*/ */
public function checkCapabilitiesResponse($formData){ public function checkCapabilitiesResponse(\Behat\Gherkin\Node\TableNode $formData){
if ($formData instanceof \Behat\Gherkin\Node\TableNode) {
$fd = $formData->getHash();
}
$capabilitiesXML = $this->response->xml()->data->capabilities; $capabilitiesXML = $this->response->xml()->data->capabilities;
foreach ($fd as $row) { foreach ($formData->getHash() as $row) {
if ($row['value'] === ''){ if ($row['value'] === ''){
$answeredValue = (string)$capabilitiesXML->$row['capability']->$row['feature']; $answeredValue = (string)$capabilitiesXML->$row['capability']->$row['feature'];
PHPUnit_Framework_Assert::assertEquals( PHPUnit_Framework_Assert::assertEquals(
@ -47,7 +38,7 @@ class CapabilitiesContext implements Context, SnippetAcceptingContext {
); );
} else{ } else{
$answeredValue = (string)$capabilitiesXML->$row['capability']->$row['feature']->$row['value_or_subfeature']; $answeredValue = (string)$capabilitiesXML->$row['capability']->$row['feature']->$row['value_or_subfeature'];
PHPUnit_Framework_Assert::assertEquals( PHPUnit_Framework_Assert::assertEquals(
$answeredValue, $answeredValue,
$row['value']==="EMPTY" ? '' : $row['value'], $row['value']==="EMPTY" ? '' : $row['value'],
"Failed field: " . $row['capability'] . " " . $row['feature'] . " " . $row['value_or_subfeature'] "Failed field: " . $row['capability'] . " " . $row['feature'] . " " . $row['value_or_subfeature']
@ -56,36 +47,53 @@ class CapabilitiesContext implements Context, SnippetAcceptingContext {
} }
} }
public static function modifyServerConfig($apacheUser, $parameter, $app, $value){ /**
$comando = 'sudo -u ' . $apacheUser . ' ../../occ config:app:set ' . $app . " " . $parameter . ' --value=' . $value; * @BeforeScenario
$expectedAnswer = "Config value $parameter for app $app set to $value"; */
$output = exec($comando); public function prepareParameters(){
PHPUnit_Framework_Assert::assertEquals( $this->modifyServerConfig('core', 'shareapi_allow_public_upload', 'yes');
$output,
$expectedAnswer,
"Failed setting $parameter to $value"
);
}
public static function getOSApacheUser(){
return exec('ps axho user,comm|grep -E "httpd|apache"|uniq|grep -v "root"|awk \'END {if ($1) print $1}\'');
} }
/** /**
* @BeforeSuite * @AfterScenario
*/ */
public static function prepareParameters(){ public function undoChangingParameters(){
$apacheUser = self::getOSApacheUser(); $this->modifyServerConfig('core', 'shareapi_allow_public_upload', 'yes');
self::modifyServerConfig($apacheUser, "shareapi_allow_public_upload", "core", "yes");
} }
/** /**
* @AfterSuite * @param string $app
* @param string $parameter
* @param string $value
*/ */
public static function undoChangingParameters(){ protected function modifyServerConfig($app, $parameter, $value) {
$apacheUser = self::getOSApacheUser(); $user = $this->currentUser;
self::modifyServerConfig($apacheUser, "shareapi_allow_public_upload", "core", "yes");
$this->currentUser = 'admin';
$this->setStatusTestingApp(true);
$body = new \Behat\Gherkin\Node\TableNode([['value', $value]]);
$this->sendingToWith('post', "/apps/testing/api/v1/app/{$app}/{$parameter}", $body);
$this->theHTTPStatusCodeShouldBe('200');
$this->theOCSStatusCodeShouldBe('100');
$this->setStatusTestingApp(false);
$this->currentUser = $user;
} }
protected function setStatusTestingApp($enabled) {
$this->sendingTo(($enabled ? 'post' : 'delete'), '/cloud/apps/testing');
$this->theHTTPStatusCodeShouldBe('200');
$this->theOCSStatusCodeShouldBe('100');
$this->sendingTo('get', '/cloud/apps?filter=enabled');
$this->theHTTPStatusCodeShouldBe('200');
if ($enabled) {
PHPUnit_Framework_Assert::assertContains('testing', $this->response->getBody()->getContents());
} else {
PHPUnit_Framework_Assert::assertNotContains('testing', $this->response->getBody()->getContents());
}
}
} }

View File

@ -291,8 +291,3 @@ Feature: provisioning
Then the OCS status code should be "100" Then the OCS status code should be "100"
And the HTTP status code should be "200" And the HTTP status code should be "200"
And app "files_external" is disabled And app "files_external" is disabled