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 Sharing;
private $apacheUser = NULL;
/**
* @Given /^parameter "([^"]*)" of app "([^"]*)" is set to "([^"]*)"$/
*/
public function serverParameterIsSetTo($parameter, $app, $value){
if (!isset($this->apacheUser)){
$this->apacheUser = $this->getOSApacheUser();
}
$this->modifyServerConfig($this->apacheUser, $parameter, $app, $value);
$this->modifyServerConfig($app, $parameter, $value);
}
/**
* @Then /^fields of capabilities match with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData
*/
public function checkCapabilitiesResponse($formData){
if ($formData instanceof \Behat\Gherkin\Node\TableNode) {
$fd = $formData->getHash();
}
public function checkCapabilitiesResponse(\Behat\Gherkin\Node\TableNode $formData){
$capabilitiesXML = $this->response->xml()->data->capabilities;
foreach ($fd as $row) {
foreach ($formData->getHash() as $row) {
if ($row['value'] === ''){
$answeredValue = (string)$capabilitiesXML->$row['capability']->$row['feature'];
PHPUnit_Framework_Assert::assertEquals(
@ -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;
$expectedAnswer = "Config value $parameter for app $app set to $value";
$output = exec($comando);
PHPUnit_Framework_Assert::assertEquals(
$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}\'');
/**
* @BeforeScenario
*/
public function prepareParameters(){
$this->modifyServerConfig('core', 'shareapi_allow_public_upload', 'yes');
}
/**
* @BeforeSuite
* @AfterScenario
*/
public static function prepareParameters(){
$apacheUser = self::getOSApacheUser();
self::modifyServerConfig($apacheUser, "shareapi_allow_public_upload", "core", "yes");
public function undoChangingParameters(){
$this->modifyServerConfig('core', 'shareapi_allow_public_upload', 'yes');
}
/**
* @AfterSuite
* @param string $app
* @param string $parameter
* @param string $value
*/
public static function undoChangingParameters(){
$apacheUser = self::getOSApacheUser();
self::modifyServerConfig($apacheUser, "shareapi_allow_public_upload", "core", "yes");
protected function modifyServerConfig($app, $parameter, $value) {
$user = $this->currentUser;
$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"
And the HTTP status code should be "200"
And app "files_external" is disabled