diff options
-rw-r--r-- | config/config.sample.php | 5 | ||||
-rw-r--r-- | lib/private/api.php | 11 | ||||
-rw-r--r-- | lib/private/db/migrator.php | 4 | ||||
-rw-r--r-- | lib/private/ocs.php | 1 | ||||
-rw-r--r-- | lib/private/repair.php | 2 | ||||
-rw-r--r-- | lib/private/server.php | 86 | ||||
-rw-r--r-- | lib/repair/dropoldtables.php | 83 | ||||
-rw-r--r-- | tests/lib/repair/dropoldtables.php | 38 | ||||
-rw-r--r-- | tests/lib/repair/fixtures/dropoldtables.xml | 24 | ||||
-rw-r--r-- | tests/lib/templatelayout.php | 72 |
10 files changed, 200 insertions, 126 deletions
diff --git a/config/config.sample.php b/config/config.sample.php index 1b3477417ff..5099fae66c2 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -420,8 +420,9 @@ $CONFIG = array( */ /** - * Check 3rd party apps to make sure they are using the private API and not the - * public API. If the app uses the private API it cannot be installed. + * Checks an app before install whether it uses private APIs instead of the + * proper public APIs. If this is set to true it will just allow to install or + * enable apps that pass this check. */ 'appcodechecker' => true, diff --git a/lib/private/api.php b/lib/private/api.php index c58d2620684..23924c518bb 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -84,11 +84,14 @@ class OC_API { * @param array $parameters */ public static function call($parameters) { + $request = \OC::$server->getRequest(); + $method = $request->getMethod(); + // Prepare the request variables - if($_SERVER['REQUEST_METHOD'] == 'PUT') { - parse_str(file_get_contents("php://input"), $parameters['_put']); - } else if($_SERVER['REQUEST_METHOD'] == 'DELETE') { - parse_str(file_get_contents("php://input"), $parameters['_delete']); + if($method === 'PUT') { + $parameters['_put'] = $request->getParams(); + } else if($method === 'DELETE') { + $parameters['_delete'] = $request->getParams(); } $name = $parameters['_route']; // Foreach registered action diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php index fcf5aae0258..f55b5078c0e 100644 --- a/lib/private/db/migrator.php +++ b/lib/private/db/migrator.php @@ -100,7 +100,7 @@ class Migrator { * @return string */ protected function generateTemporaryTableName($name) { - return 'oc_' . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); + return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); } /** @@ -151,7 +151,7 @@ class Migrator { $indexName = $index->getName(); } else { // avoid conflicts in index names - $indexName = 'oc_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); + $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); } $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); } diff --git a/lib/private/ocs.php b/lib/private/ocs.php index bbe642a247d..d43811e339b 100644 --- a/lib/private/ocs.php +++ b/lib/private/ocs.php @@ -76,7 +76,6 @@ class OC_OCS { $method='get'; }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { $method='put'; - parse_str(file_get_contents("php://input"), $put_vars); }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { $method='post'; }else{ diff --git a/lib/private/repair.php b/lib/private/repair.php index d9fd99707e8..101af66e304 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -13,6 +13,7 @@ use OC\Hooks\Emitter; use OC\Repair\AssetCache; use OC\Repair\CleanTags; use OC\Repair\Collation; +use OC\Repair\DropOldTables; use OC\Repair\FillETags; use OC\Repair\InnoDB; use OC\Repair\RepairConfig; @@ -84,6 +85,7 @@ class Repair extends BasicEmitter { new AssetCache(), new FillETags(\OC_DB::getConnection()), new CleanTags(\OC_DB::getConnection()), + new DropOldTables(\OC_DB::getConnection()), ); } diff --git a/lib/private/server.php b/lib/private/server.php index a16854d6288..18d996537e2 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -268,6 +268,46 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('TrustedDomainHelper', function ($c) { return new TrustedDomainHelper($this->getConfig()); }); + $this->registerService('Request', function ($c) { + if (isset($this['urlParams'])) { + $urlParams = $this['urlParams']; + } else { + $urlParams = []; + } + + if ($this->getSession()->exists('requesttoken')) { + $requestToken = $this->getSession()->get('requesttoken'); + } else { + $requestToken = false; + } + + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN + && in_array('fakeinput', stream_get_wrappers()) + ) { + $stream = 'fakeinput://data'; + } else { + $stream = 'php://input'; + } + + return new Request( + [ + 'get' => $_GET, + 'post' => $_POST, + 'files' => $_FILES, + 'server' => $_SERVER, + 'env' => $_ENV, + 'cookies' => $_COOKIE, + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) + ? $_SERVER['REQUEST_METHOD'] + : null, + 'urlParams' => $urlParams, + 'requesttoken' => $requestToken, + ], + $this->getSecureRandom(), + $this->getConfig(), + $stream + ); + }); } /** @@ -282,54 +322,10 @@ class Server extends SimpleContainer implements IServerContainer { * currently being processed is returned from this method. * In case the current execution was not initiated by a web request null is returned * - * FIXME: This should be queried as well. However, due to our totally awesome - * static code a lot of tests do stuff like $_SERVER['foo'] which obviously - * will not work with that approach. We even have some integration tests in our - * unit tests which setup a complete webserver. Once the code is all non-static - * or we don't have such mixed integration/unit tests setup anymore this can - * get moved out again. - * * @return \OCP\IRequest|null */ function getRequest() { - if (isset($this['urlParams'])) { - $urlParams = $this['urlParams']; - } else { - $urlParams = array(); - } - - if ($this->getSession()->exists('requesttoken')) { - $requestToken = $this->getSession()->get('requesttoken'); - } else { - $requestToken = false; - } - - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN - && in_array('fakeinput', stream_get_wrappers()) - ) { - $stream = 'fakeinput://data'; - } else { - $stream = 'php://input'; - } - - return new Request( - [ - 'get' => $_GET, - 'post' => $_POST, - 'files' => $_FILES, - 'server' => $_SERVER, - 'env' => $_ENV, - 'cookies' => $_COOKIE, - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) - ? $_SERVER['REQUEST_METHOD'] - : null, - 'urlParams' => $urlParams, - 'requesttoken' => $requestToken, - ], - $this->getSecureRandom(), - $this->getConfig(), - $stream - ); + return $this->query('Request'); } /** diff --git a/lib/repair/dropoldtables.php b/lib/repair/dropoldtables.php new file mode 100644 index 00000000000..00d2a1bfab9 --- /dev/null +++ b/lib/repair/dropoldtables.php @@ -0,0 +1,83 @@ +<?php +/** + * ownCloud + * + * @author Joas Schilling + * @copyright 2015 Joas Schilling nickvergessen@owncloud.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Repair; + + +use OC\DB\Connection; +use OC\Hooks\BasicEmitter; +use OC\RepairStep; + +class DropOldTables extends BasicEmitter implements RepairStep { + + /** @var Connection */ + protected $connection; + + /** + * @param Connection $connection + */ + public function __construct(Connection $connection) { + $this->connection = $connection; + } + + /** + * Returns the step's name + * + * @return string + */ + public function getName() { + return 'Drop old database tables'; + } + + /** + * Run repair step. + * Must throw exception on error. + * + * @throws \Exception in case of failure + */ + public function run() { + foreach ($this->oldDatabaseTables() as $tableName) { + if ($this->connection->tableExists($tableName)){ + $this->emit('\OC\Repair', 'info', [ + sprintf('Table %s has been deleted', $tableName) + ]); + $this->connection->dropTable($tableName); + } + } + } + + /** + * Returns a list of outdated tables which are not used anymore + * @return array + */ + protected function oldDatabaseTables() { + return [ + 'calendar_calendars', + 'calendar_objects', + 'calendar_share_calendar', + 'calendar_share_event', + 'foldersize', + 'fscache', + 'locks', + 'log', + 'media_albums', + 'media_artists', + 'media_sessions', + 'media_songs', + 'media_users', + 'permissions', + 'pictures_images_cache', + 'queuedtasks', + 'sharing', + ]; + } +} diff --git a/tests/lib/repair/dropoldtables.php b/tests/lib/repair/dropoldtables.php new file mode 100644 index 00000000000..244d8837949 --- /dev/null +++ b/tests/lib/repair/dropoldtables.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Repair; + +/** + * Tests for the dropping old tables + * + * @see \OC\Repair\DropOldTables + */ +class DropOldTables extends \Test\TestCase { + /** @var \OCP\IDBConnection */ + protected $connection; + + protected function setUp() { + parent::setUp(); + + $this->connection = \OC::$server->getDatabaseConnection(); + $manager = new \OC\DB\MDB2SchemaManager($this->connection); + $manager->createDbFromStructure(__DIR__ . '/fixtures/dropoldtables.xml'); + } + + public function testRun() { + $this->assertFalse($this->connection->tableExists('sharing'), 'Asserting that the table oc_sharing does not exist before repairing'); + $this->assertTrue($this->connection->tableExists('permissions'), 'Asserting that the table oc_permissions does exist before repairing'); + + $repair = new \OC\Repair\DropOldTables($this->connection); + $repair->run(); + + $this->assertFalse($this->connection->tableExists('sharing'), 'Asserting that the table oc_sharing does not exist after repairing'); + $this->assertFalse($this->connection->tableExists('permissions'), 'Asserting that the table oc_permissions does not exist after repairing'); + } +} diff --git a/tests/lib/repair/fixtures/dropoldtables.xml b/tests/lib/repair/fixtures/dropoldtables.xml new file mode 100644 index 00000000000..6c42a8f90a7 --- /dev/null +++ b/tests/lib/repair/fixtures/dropoldtables.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8" ?> +<database> + + <name>*dbname*</name> + <create>true</create> + <overwrite>false</overwrite> + + <charset>utf8</charset> + + <table> + + <name>*dbprefix*permissions</name> + + <declaration> + <field> + <name>textfield</name> + <type>text</type> + <default>foo</default> + <notnull>true</notnull> + <length>32</length> + </field> + </declaration> + </table> +</database> diff --git a/tests/lib/templatelayout.php b/tests/lib/templatelayout.php deleted file mode 100644 index c23aaa9b762..00000000000 --- a/tests/lib/templatelayout.php +++ /dev/null @@ -1,72 +0,0 @@ -<?php -/** - * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OC\Test; - -/** - * @package OC\Test - */ -class OC_TemplateLayout extends \Test\TestCase { - - private $oldServerURI; - private $oldScriptName; - - protected function setUp() { - parent::setUp(); - - $this->oldServerURI = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null; - $this->oldScriptName = $_SERVER['SCRIPT_NAME']; - } - - protected function tearDown() { - if ($this->oldServerURI === null) { - unset($_SERVER['REQUEST_URI']); - } else { - $_SERVER['REQUEST_URI'] = $this->oldServerURI; - } - $_SERVER['SCRIPT_NAME'] = $this->oldScriptName; - - parent::tearDown(); - } - - /** - * Contains valid file paths in the scheme array($absolutePath, $expectedPath) - * @return array - */ - public function validFilePathProvider() { - return array( - array(\OC::$SERVERROOT . '/apps/files/js/fancyJS.js', '/apps/files/js/fancyJS.js'), - array(\OC::$SERVERROOT. '/test.js', '/test.js'), - array(\OC::$SERVERROOT . '/core/test.js', '/core/test.js'), - array(\OC::$SERVERROOT, ''), - ); - } - - /** - * @dataProvider validFilePathProvider - */ - public function testConvertToRelativePath($absolutePath, $expected) { - $_SERVER['REQUEST_URI'] = $expected; - $_SERVER['SCRIPT_NAME'] = $expected; - - $relativePath = \Test_Helper::invokePrivate(new \OC_TemplateLayout('user'), 'convertToRelativePath', array($absolutePath)); - $this->assertEquals($expected, $relativePath); - } - - /** - * @expectedException \Exception - * @expectedExceptionMessage $filePath is not under the \OC::$SERVERROOT - */ - public function testInvalidConvertToRelativePath() { - $invalidFile = '/this/file/is/invalid'; - $_SERVER['REQUEST_URI'] = $invalidFile; - $_SERVER['SCRIPT_NAME'] = '/'; - - \Test_Helper::invokePrivate(new \OC_TemplateLayout('user'), 'convertToRelativePath', array($invalidFile)); - } -} |