summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-02-22 22:20:56 -0600
committerMorris Jobke <hey@morrisjobke.de>2017-02-22 22:35:18 -0600
commit2bbf3b18d90301e4c1afc8deb5ef0cf9b91a6ff9 (patch)
treeff6b9d5e9f7f6a16b6f10605ce9aacc779fa1176 /tests
parentc2d3e12e23a0315c2ef14aab9235dfec1f6b9e26 (diff)
downloadnextcloud-server-2bbf3b18d90301e4c1afc8deb5ef0cf9b91a6ff9.tar.gz
nextcloud-server-2bbf3b18d90301e4c1afc8deb5ef0cf9b91a6ff9.zip
cleanup old and not needed repair steps to speed up the update
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Repair/DropOldJobsTest.php48
-rw-r--r--tests/lib/Repair/DropOldTablesTest.php46
-rw-r--r--tests/lib/Repair/RemoveGetETagEntriesTest.php90
-rw-r--r--tests/lib/Repair/RemoveOldSharesTest.php160
-rw-r--r--tests/lib/Repair/RepairInnoDBTest.php78
-rw-r--r--tests/lib/Repair/RepairInvalidSharesTest.php153
-rw-r--r--tests/lib/Repair/RepairMimeTypesTest.php359
-rw-r--r--tests/lib/Repair/RepairSharePropagationTest.php58
-rw-r--r--tests/lib/Repair/RepairUnmergedSharesTest.php575
-rw-r--r--tests/lib/Repair/UpdateOutdatedOcsIdsTest.php80
-rw-r--r--tests/lib/Repair/fixtures/dropoldtables.xml24
11 files changed, 19 insertions, 1652 deletions
diff --git a/tests/lib/Repair/DropOldJobsTest.php b/tests/lib/Repair/DropOldJobsTest.php
deleted file mode 100644
index d83ecbe59c4..00000000000
--- a/tests/lib/Repair/DropOldJobsTest.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-/**
- * Copyright (c) 2015 Arthur Schiwon <blizzz@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Repair;
-
-use OCP\BackgroundJob\IJobList;
-use OCP\Migration\IOutput;
-
-/**
- * Tests for the dropping old tables
- *
- * @group DB
- *
- * @see \OC\Repair\DropOldTables
- */
-class DropOldJobsTest extends \Test\TestCase {
- /** @var IJobList */
- protected $jobList;
-
- protected function setUp() {
- parent::setUp();
-
- $this->jobList = \OC::$server->getJobList();
- $this->jobList->add('OC\Cache\FileGlobalGC');
- $this->jobList->add('OC_Cache_FileGlobalGC');
- }
-
- public function testRun() {
- $this->assertTrue($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC exists before repairing');
- $this->assertTrue($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC exists before repairing');
-
- /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
- $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- $repair = new \OC\Repair\DropOldJobs($this->jobList);
- $repair->run($outputMock);
-
- $this->assertFalse($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC does not exist after repairing');
- $this->assertFalse($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC does not exist after repairing');
- }
-}
diff --git a/tests/lib/Repair/DropOldTablesTest.php b/tests/lib/Repair/DropOldTablesTest.php
deleted file mode 100644
index 1f5a4c15295..00000000000
--- a/tests/lib/Repair/DropOldTablesTest.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?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;
-use OCP\Migration\IOutput;
-
-/**
- * Tests for the dropping old tables
- *
- * @group DB
- *
- * @see \OC\Repair\DropOldTables
- */
-class DropOldTablesTest 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');
-
- /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
- $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- $repair = new \OC\Repair\DropOldTables($this->connection);
- $repair->run($outputMock);
-
- $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/RemoveGetETagEntriesTest.php b/tests/lib/Repair/RemoveGetETagEntriesTest.php
deleted file mode 100644
index c00923228d0..00000000000
--- a/tests/lib/Repair/RemoveGetETagEntriesTest.php
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-/**
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @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 Test\Repair;
-
-use OC\Repair\RemoveGetETagEntries;
-use OCP\Migration\IOutput;
-use Test\TestCase;
-
-/**
- * Class RemoveGetETagEntriesTest
- *
- * @group DB
- *
- * @package Test\Repair
- */
-class RemoveGetETagEntriesTest extends TestCase {
- /** @var \OCP\IDBConnection */
- protected $connection;
-
- protected function setUp() {
- parent::setUp();
-
- $this->connection = \OC::$server->getDatabaseConnection();
- }
-
- public function testRun() {
-
- $userName = 'removePropertiesUser';
- $data = [
- [$userName, '/abc.def.txt', '{DAV:}getetag', 'abcdef'],
- [$userName, '/abc.def.txt', '{DAV:}anotherRandomProperty', 'ghi'],
- ];
-
- // insert test data
- $sqlToInsertProperties = 'INSERT INTO `*PREFIX*properties` (`userid`, `propertypath`, `propertyname`, `propertyvalue`) VALUES (?, ?, ? ,?)';
- foreach ($data as $entry) {
- $this->connection->executeUpdate($sqlToInsertProperties, $entry);
- }
-
- // check if test data is written to DB
- $sqlToFetchProperties = 'SELECT `userid`, `propertypath`, `propertyname`, `propertyvalue` FROM `*PREFIX*properties` WHERE `userid` = ?';
- $stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]);
- $entries = $stmt->fetchAll(\PDO::FETCH_NUM);
-
- $this->assertCount(2, $entries, 'Asserts that two entries are returned as we have inserted two');
- foreach($entries as $entry) {
- $this->assertTrue(in_array($entry, $data), 'Asserts that the entries are the ones from the test data set');
- }
-
- /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
- $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- // run repair step
- $repair = new RemoveGetETagEntries($this->connection);
- $repair->run($outputMock);
-
- // check if test data is correctly modified in DB
- $stmt = $this->connection->executeQuery($sqlToFetchProperties, [$userName]);
- $entries = $stmt->fetchAll(\PDO::FETCH_NUM);
-
- $this->assertCount(1, $entries, 'Asserts that only one entry is returned after the repair step - the other one has to be removed');
- $this->assertSame($data[1], $entries[0], 'Asserts that the returned entry is the correct one from the test data set');
-
- // remove test data
- $sqlToRemoveProperties = 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ?';
- $this->connection->executeUpdate($sqlToRemoveProperties, [$userName]);
- }
-
-}
diff --git a/tests/lib/Repair/RemoveOldSharesTest.php b/tests/lib/Repair/RemoveOldSharesTest.php
deleted file mode 100644
index ac30585bdc5..00000000000
--- a/tests/lib/Repair/RemoveOldSharesTest.php
+++ /dev/null
@@ -1,160 +0,0 @@
-<?php
-/**
- * @author Roeland Jago Douma <rullzer@owncloud.com>
- *
- * @copyright Copyright (c) 2016, 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 Test\Repair;
-
-use OC\Repair\RemoveOldShares;
-use OCP\IDBConnection;
-use OCP\Migration\IOutput;
-
-/**
- * Class RemoveOldSharesTest
- *
- * @package Test\Repair
- * @group DB
- */
-class RemoveOldSharesTest extends \Test\TestCase {
-
- /** @var RemoveOldShares */
- protected $repair;
-
- /** @var IDBConnection */
- protected $connection;
-
- /** @var IOutput */
- private $outputMock;
-
- protected function setUp() {
- parent::setUp();
-
- $this->outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->connection = \OC::$server->getDatabaseConnection();
- $this->repair = new RemoveOldShares($this->connection);
- }
-
- protected function tearDown() {
- $qb = $this->connection->getQueryBuilder();
- $qb->delete('share');
- $qb->execute();
-
- return parent::tearDown();
- }
-
- public function testRun() {
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->createNamedParameter(0),
- 'share_with' => $qb->createNamedParameter('foo'),
- 'uid_owner' => $qb->createNamedParameter('owner'),
- 'item_type' => $qb->createNamedParameter('file'),
- 'item_source' => $qb->createNamedParameter(42),
- 'item_target' => $qb->createNamedParameter('/target'),
- 'file_source' => $qb->createNamedParameter(42),
- 'file_target' => $qb->createNamedParameter('/target'),
- 'permissions' => $qb->createNamedParameter(1),
- ]);
- $qb->execute();
-
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->createNamedParameter(0),
- 'share_with' => $qb->createNamedParameter('foo'),
- 'uid_owner' => $qb->createNamedParameter('owner'),
- 'item_type' => $qb->createNamedParameter('calendar'),
- 'item_source' => $qb->createNamedParameter(42),
- 'item_target' => $qb->createNamedParameter('/target'),
- 'file_source' => $qb->createNamedParameter(42),
- 'file_target' => $qb->createNamedParameter('/target'),
- 'permissions' => $qb->createNamedParameter(1),
- ]);
- $qb->execute();
-
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->createNamedParameter(0),
- 'share_with' => $qb->createNamedParameter('foo'),
- 'uid_owner' => $qb->createNamedParameter('owner'),
- 'item_type' => $qb->createNamedParameter('event'),
- 'item_source' => $qb->createNamedParameter(42),
- 'item_target' => $qb->createNamedParameter('/target'),
- 'file_source' => $qb->createNamedParameter(42),
- 'file_target' => $qb->createNamedParameter('/target'),
- 'permissions' => $qb->createNamedParameter(1),
- ]);
- $qb->execute();
-
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->createNamedParameter(0),
- 'share_with' => $qb->createNamedParameter('foo'),
- 'uid_owner' => $qb->createNamedParameter('owner'),
- 'item_type' => $qb->createNamedParameter('contact'),
- 'item_source' => $qb->createNamedParameter(42),
- 'item_target' => $qb->createNamedParameter('/target'),
- 'file_source' => $qb->createNamedParameter(42),
- 'file_target' => $qb->createNamedParameter('/target'),
- 'permissions' => $qb->createNamedParameter(1),
- ]);
- $qb->execute();
-
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->createNamedParameter(0),
- 'share_with' => $qb->createNamedParameter('foo'),
- 'uid_owner' => $qb->createNamedParameter('owner'),
- 'item_type' => $qb->createNamedParameter('addressbook'),
- 'item_source' => $qb->createNamedParameter(42),
- 'item_target' => $qb->createNamedParameter('/target'),
- 'file_source' => $qb->createNamedParameter(42),
- 'file_target' => $qb->createNamedParameter('/target'),
- 'permissions' => $qb->createNamedParameter(1),
- ]);
- $qb->execute();
-
- $qb = $this->connection->getQueryBuilder();
- $qb->selectAlias($qb->createFunction('COUNT(*)'), 'count')
- ->from('share');
-
- $cursor = $qb->execute();
- $data = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertEquals(5, $data[0]['count']);
-
- $this->repair->run($this->outputMock);
-
- $qb = $this->connection->getQueryBuilder();
- $qb->select('*')
- ->from('share');
-
- $cursor = $qb->execute();
- $data = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertCount(1, $data);
- $this->assertEquals('file', $data[0]['item_type']);
- }
-}
diff --git a/tests/lib/Repair/RepairInnoDBTest.php b/tests/lib/Repair/RepairInnoDBTest.php
deleted file mode 100644
index 1258dad73f5..00000000000
--- a/tests/lib/Repair/RepairInnoDBTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-/**
- * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-namespace Test\Repair;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-/**
- * Tests for the converting of MySQL tables to InnoDB engine
- *
- * @group DB
- *
- * @see \OC\Repair\RepairMimeTypes
- */
-class RepairInnoDBTest extends \Test\TestCase {
-
- /** @var IRepairStep */
- private $repair;
-
- /** @var \Doctrine\DBAL\Connection */
- private $connection;
-
- /** @var string */
- private $tableName;
-
- protected function setUp() {
- parent::setUp();
-
- $this->connection = \OC::$server->getDatabaseConnection();
- if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
- $this->markTestSkipped("Test only relevant on MySql");
- }
-
- $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
- $this->tableName = $this->getUniqueID($dbPrefix . "_innodb_test");
- $this->connection->exec("CREATE TABLE $this->tableName(id INT) ENGINE MyISAM");
-
- $this->repair = new \OC\Repair\InnoDB();
- }
-
- protected function tearDown() {
- $this->connection->getSchemaManager()->dropTable($this->tableName);
- parent::tearDown();
- }
-
- public function testInnoDBConvert() {
- $result = $this->countMyIsamTables();
- $this->assertEquals(1, $result);
-
- /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
- $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->repair->run($outputMock);
-
- $result = $this->countMyIsamTables();
- $this->assertEquals(0, $result);
- }
-
- /**
- * @param $dbName
- * @return mixed
- */
- private function countMyIsamTables() {
- $dbName = \OC::$server->getConfig()->getSystemValue("dbname");
-
- $result = $this->connection->fetchColumn(
- "SELECT count(*) FROM information_schema.tables WHERE table_schema = ? and table_name = ? AND engine = 'MyISAM'",
- array($dbName, $this->tableName)
- );
- return $result;
- }
-}
diff --git a/tests/lib/Repair/RepairInvalidSharesTest.php b/tests/lib/Repair/RepairInvalidSharesTest.php
index 83dbed7d202..fa75f58472a 100644
--- a/tests/lib/Repair/RepairInvalidSharesTest.php
+++ b/tests/lib/Repair/RepairInvalidSharesTest.php
@@ -39,7 +39,7 @@ class RepairInvalidSharesTest extends TestCase {
$config->expects($this->any())
->method('getSystemValue')
->with('version')
- ->will($this->returnValue('8.0.0.0'));
+ ->will($this->returnValue('12.0.0.0'));
$this->connection = \OC::$server->getDatabaseConnection();
$this->deleteAllShares();
@@ -60,157 +60,6 @@ class RepairInvalidSharesTest extends TestCase {
}
/**
- * Test remove expiration date for non-link shares
- */
- public function testRemoveExpirationDateForNonLinkShares() {
- // user share with bogus expiration date
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_USER),
- 'share_with' => $qb->expr()->literal('recipientuser1'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('folder'),
- 'item_source' => $qb->expr()->literal(123),
- 'item_target' => $qb->expr()->literal('/123'),
- 'file_source' => $qb->expr()->literal(123),
- 'file_target' => $qb->expr()->literal('/test'),
- 'permissions' => $qb->expr()->literal(1),
- 'stime' => $qb->expr()->literal(time()),
- 'expiration' => $qb->expr()->literal('2015-09-25 00:00:00')
- ])
- ->execute();
-
- $bogusShareId = $this->getLastShareId();
-
- // link share with expiration date
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_LINK),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('folder'),
- 'item_source' => $qb->expr()->literal(123),
- 'item_target' => $qb->expr()->literal('/123'),
- 'file_source' => $qb->expr()->literal(123),
- 'file_target' => $qb->expr()->literal('/test'),
- 'permissions' => $qb->expr()->literal(1),
- 'stime' => $qb->expr()->literal(time()),
- 'expiration' => $qb->expr()->literal('2015-09-25 00:00:00'),
- 'token' => $qb->expr()->literal('abcdefg')
- ])->execute();
-
- /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
- $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->repair->run($outputMock);
-
- $results = $this->connection->getQueryBuilder()
- ->select('*')
- ->from('share')
- ->orderBy('share_type', 'ASC')
- ->execute()
- ->fetchAll();
-
- $this->assertCount(2, $results);
-
- $userShare = $results[0];
- $linkShare = $results[1];
- $this->assertEquals($bogusShareId, $userShare['id'], 'sanity check');
- $this->assertNull($userShare['expiration'], 'bogus expiration date was removed');
- $this->assertNotNull($linkShare['expiration'], 'valid link share expiration date still there');
- }
-
- /**
- * Test remove expiration date for non-link shares
- */
- public function testAddShareLinkDeletePermission() {
- $oldPerms = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE;
- $newPerms = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
-
- // share with old permissions
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_LINK),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('folder'),
- 'item_source' => $qb->expr()->literal(123),
- 'item_target' => $qb->expr()->literal('/123'),
- 'file_source' => $qb->expr()->literal(123),
- 'file_target' => $qb->expr()->literal('/test'),
- 'permissions' => $qb->expr()->literal($oldPerms),
- 'stime' => $qb->expr()->literal(time()),
- ])
- ->execute();
-
- $bogusShareId = $this->getLastShareId();
-
- // share with read-only permissions
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_LINK),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('folder'),
- 'item_source' => $qb->expr()->literal(123),
- 'item_target' => $qb->expr()->literal('/123'),
- 'file_source' => $qb->expr()->literal(123),
- 'file_target' => $qb->expr()->literal('/test'),
- 'permissions' => $qb->expr()->literal(\OCP\Constants::PERMISSION_READ),
- 'stime' => $qb->expr()->literal(time()),
- ])
- ->execute();
-
- $keepThisShareId = $this->getLastShareId();
-
- // user share to keep
- $qb = $this->connection->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_USER),
- 'share_with' => $qb->expr()->literal('recipientuser1'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('folder'),
- 'item_source' => $qb->expr()->literal(123),
- 'item_target' => $qb->expr()->literal('/123'),
- 'file_source' => $qb->expr()->literal(123),
- 'file_target' => $qb->expr()->literal('/test'),
- 'permissions' => $qb->expr()->literal(3),
- 'stime' => $qb->expr()->literal(time()),
- ])
- ->execute();
-
- $keepThisShareId2 = $this->getLastShareId();
-
- /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
- $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->repair->run($outputMock);
-
- $results = $this->connection->getQueryBuilder()
- ->select('*')
- ->from('share')
- ->orderBy('permissions', 'ASC')
- ->execute()
- ->fetchAll();
-
- $this->assertCount(3, $results);
-
- $untouchedShare = $results[0];
- $untouchedShare2 = $results[1];
- $updatedShare = $results[2];
- $this->assertEquals($keepThisShareId, $untouchedShare['id'], 'sanity check');
- $this->assertEquals($keepThisShareId2, $untouchedShare2['id'], 'sanity check');
- $this->assertEquals($bogusShareId, $updatedShare['id'], 'sanity check');
- $this->assertEquals($newPerms, $updatedShare['permissions'], 'delete permission was added');
- }
-
- /**
* Test remove shares where the parent share does not exist anymore
*/
public function testSharesNonExistingParent() {
diff --git a/tests/lib/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php
index 6a42b016938..ef1412b2fd2 100644
--- a/tests/lib/Repair/RepairMimeTypesTest.php
+++ b/tests/lib/Repair/RepairMimeTypesTest.php
@@ -45,7 +45,7 @@ class RepairMimeTypesTest extends \Test\TestCase {
$config->expects($this->any())
->method('getSystemValue')
->with('version')
- ->will($this->returnValue('8.0.0.0'));
+ ->will($this->returnValue('11.0.0.0'));
$this->storage = new \OC\Files\Storage\Temporary([]);
@@ -90,20 +90,6 @@ class RepairMimeTypesTest extends \Test\TestCase {
}
}
- /**
- * Returns the id of a given mime type or null
- * if it does not exist.
- */
- private function getMimeTypeIdFromDB($mimeType) {
- $sql = 'SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?';
- $results = \OC_DB::executeAudited($sql, [$mimeType]);
- $result = $results->fetchOne();
- if ($result) {
- return $result['id'];
- }
- return null;
- }
-
private function renameMimeTypes($currentMimeTypes, $fixedMimeTypes) {
$this->addEntries($currentMimeTypes);
@@ -121,344 +107,27 @@ class RepairMimeTypesTest extends \Test\TestCase {
}
/**
- * Test renaming and splitting old office mime types
- */
- public function testRenameOfficeMimeTypes() {
- $currentMimeTypes = [
- ['test.doc', 'application/msword'],
- ['test.docx', 'application/msword'],
- ['test.xls', 'application/msexcel'],
- ['test.xlsx', 'application/msexcel'],
- ['test.ppt', 'application/mspowerpoint'],
- ['test.pptx', 'application/mspowerpoint'],
- ];
-
- $fixedMimeTypes = [
- ['test.doc', 'application/msword'],
- ['test.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
- ['test.xls', 'application/vnd.ms-excel'],
- ['test.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
- ['test.ppt', 'application/vnd.ms-powerpoint'],
- ['test.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming old fonts mime types
- */
- public function testRenameFontsMimeTypes() {
- $currentMimeTypes = [
- ['test.ttf', 'application/x-font-ttf'],
- ['test.otf', 'font/opentype'],
- ['test.pfb', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.ttf', 'application/font-sfnt'],
- ['test.otf', 'application/font-sfnt'],
- ['test.pfb', 'application/x-font'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the APK mime type
- */
- public function testRenameAPKMimeType() {
- $currentMimeTypes = [
- ['test.apk', 'application/octet-stream'],
- ['bogus.apk', 'application/vnd.android.package-archive'],
- ['bogus2.apk', 'application/wrong'],
- ];
-
- $fixedMimeTypes = [
- ['test.apk', 'application/vnd.android.package-archive'],
- ['bogus.apk', 'application/vnd.android.package-archive'],
- ['bogus2.apk', 'application/vnd.android.package-archive'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the postscript mime types
- */
- public function testRenamePostscriptMimeType() {
- $currentMimeTypes = [
- ['test.eps', 'application/octet-stream'],
- ['test.ps', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.eps', 'application/postscript'],
- ['test.ps', 'application/postscript'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the Raw mime types
- */
- public function testRenameRawMimeType() {
- $currentMimeTypes = [
- ['test.arw', 'application/octet-stream'],
- ['test.cr2', 'application/octet-stream'],
- ['test.dcr', 'application/octet-stream'],
- ['test.dng', 'application/octet-stream'],
- ['test.erf', 'application/octet-stream'],
- ['test.iiq', 'application/octet-stream'],
- ['test.k25', 'application/octet-stream'],
- ['test.kdc', 'application/octet-stream'],
- ['test.mef', 'application/octet-stream'],
- ['test.nef', 'application/octet-stream'],
- ['test.orf', 'application/octet-stream'],
- ['test.pef', 'application/octet-stream'],
- ['test.raf', 'application/octet-stream'],
- ['test.rw2', 'application/octet-stream'],
- ['test.srf', 'application/octet-stream'],
- ['test.sr2', 'application/octet-stream'],
- ['test.xrf', 'application/octet-stream'],
- ['CapitalExtension.DNG', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.arw', 'image/x-dcraw'],
- ['test.cr2', 'image/x-dcraw'],
- ['test.dcr', 'image/x-dcraw'],
- ['test.dng', 'image/x-dcraw'],
- ['test.erf', 'image/x-dcraw'],
- ['test.iiq', 'image/x-dcraw'],
- ['test.k25', 'image/x-dcraw'],
- ['test.kdc', 'image/x-dcraw'],
- ['test.mef', 'image/x-dcraw'],
- ['test.nef', 'image/x-dcraw'],
- ['test.orf', 'image/x-dcraw'],
- ['test.pef', 'image/x-dcraw'],
- ['test.raf', 'image/x-dcraw'],
- ['test.rw2', 'image/x-dcraw'],
- ['test.srf', 'image/x-dcraw'],
- ['test.sr2', 'image/x-dcraw'],
- ['test.xrf', 'image/x-dcraw'],
- ['CapitalExtension.DNG', 'image/x-dcraw'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the 3D image media type
- */
- public function testRename3dImagesMimeType() {
- $currentMimeTypes = [
- ['test.jps', 'application/octet-stream'],
- ['test.mpo', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.jps', 'image/jpeg'],
- ['test.mpo', 'image/jpeg'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the conf/cnf media type
- */
- public function testRenameConfMimeType() {
- $currentMimeTypes = [
- ['test.conf', 'application/octet-stream'],
- ['test.cnf', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.conf', 'text/plain'],
- ['test.cnf', 'text/plain'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the yaml media type
- */
- public function testRenameYamlMimeType() {
- $currentMimeTypes = [
- ['test.yaml', 'application/octet-stream'],
- ['test.yml', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.yaml', 'application/yaml'],
- ['test.yml', 'application/yaml'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the java mime types
- */
- public function testRenameJavaMimeType() {
- $currentMimeTypes = [
- ['test.java', 'application/octet-stream'],
- ['test.class', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.java', 'text/x-java-source'],
- ['test.class', 'application/java'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the hpp mime type
- */
- public function testRenameHppMimeType() {
- $currentMimeTypes = [
- ['test.hpp', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.hpp', 'text/x-h'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the rss mime type
- */
- public function testRenameRssMimeType() {
- $currentMimeTypes = [
- ['test.rss', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.rss', 'application/rss+xml'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
- * Test renaming the hpp mime type
- */
- public function testRenameRtfMimeType() {
- $currentMimeTypes = [
- ['test.rtf', 'application/octet-stream'],
- ];
-
- $fixedMimeTypes = [
- ['test.rtf', 'text/rtf'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
- }
-
- /**
* Test renaming the richdocuments additional office mime types
*/
- public function testRenameRichDocumentsMimeTypes() {
+ public function testRenameWindowsProgramTypes() {
$currentMimeTypes = [
- ['test.lwp', 'application/octet-stream'],
- ['test.one', 'application/octet-stream'],
- ['test.vsd', 'application/octet-stream'],
- ['test.wpd', 'application/octet-stream'],
+ ['test.htaccess', 'application/octet-stream'],
+ ['.htaccess', 'application/octet-stream'],
+ ['test.bat', 'application/octet-stream'],
+ ['test.cmd', 'application/octet-stream'],
];
$fixedMimeTypes = [
- ['test.lwp', 'application/vnd.lotus-wordpro'],
- ['test.one', 'application/msonenote'],
- ['test.vsd', 'application/vnd.visio'],
- ['test.wpd', 'application/vnd.wordperfect'],
+ ['test.htaccess', 'text/plain'],
+ ['.htaccess', 'text/plain'],
+ ['test.bat', 'application/x-msdos-program'],
+ ['test.cmd', 'application/cmd'],
];
$this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
}
/**
- * Test renaming and splitting old office mime types when
- * new ones already exist
- */
- public function testRenameOfficeMimeTypesWhenExist() {
- $currentMimeTypes = [
- ['test.doc', 'application/msword'],
- ['test.docx', 'application/msword'],
- ['test.xls', 'application/msexcel'],
- ['test.xlsx', 'application/msexcel'],
- ['test.ppt', 'application/mspowerpoint'],
- ['test.pptx', 'application/mspowerpoint'],
- // make it so that the new mimetypes already exist
- ['bogus.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
- ['bogus.xlsx', 'application/vnd.ms-excel'],
- ['bogus.pptx', 'application/vnd.ms-powerpoint'],
- ['bogus2.docx', 'application/wrong'],
- ['bogus2.xlsx', 'application/wrong'],
- ['bogus2.pptx', 'application/wrong'],
- ];
-
- $fixedMimeTypes = [
- ['test.doc', 'application/msword'],
- ['test.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
- ['test.xls', 'application/vnd.ms-excel'],
- ['test.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
- ['test.ppt', 'application/vnd.ms-powerpoint'],
- ['test.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
- ['bogus.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
- ['bogus.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
- ['bogus.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
- ['bogus2.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
- ['bogus2.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
- ['bogus2.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
-
- // wrong mimetypes are gone
- $this->assertNull($this->getMimeTypeIdFromDB('application/msexcel'));
- $this->assertNull($this->getMimeTypeIdFromDB('application/mspowerpoint'));
- }
-
- /**
- * Test renaming old fonts mime types when
- * new ones already exist
- */
- public function testRenameFontsMimeTypesWhenExist() {
- $currentMimeTypes = [
- ['test.ttf', 'application/x-font-ttf'],
- ['test.otf', 'font/opentype'],
- // make it so that the new mimetypes already exist
- ['bogus.ttf', 'application/font-sfnt'],
- ['bogus.otf', 'application/font-sfnt'],
- ['bogus2.ttf', 'application/wrong'],
- ['bogus2.otf', 'application/wrong'],
- ];
-
- $fixedMimeTypes = [
- ['test.ttf', 'application/font-sfnt'],
- ['test.otf', 'application/font-sfnt'],
- ['bogus.ttf', 'application/font-sfnt'],
- ['bogus.otf', 'application/font-sfnt'],
- ['bogus2.ttf', 'application/font-sfnt'],
- ['bogus2.otf', 'application/font-sfnt'],
- ];
-
- $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
-
- // wrong mimetypes are gone
- $this->assertNull($this->getMimeTypeIdFromDB('application/x-font-ttf'));
- $this->assertNull($this->getMimeTypeIdFromDB('font'));
- $this->assertNull($this->getMimeTypeIdFromDB('font/opentype'));
- }
-
- /**
* Test that nothing happens and no error happens when all mimetypes are
* already correct and no old ones exist..
*/
@@ -509,6 +178,10 @@ class RepairMimeTypesTest extends \Test\TestCase {
['test.one', 'application/msonenote'],
['test.vsd', 'application/vnd.visio'],
['test.wpd', 'application/vnd.wordperfect'],
+ ['test.htaccess', 'text/plain'],
+ ['.htaccess', 'text/plain'],
+ ['test.bat', 'application/x-msdos-program'],
+ ['test.cmd', 'application/cmd'],
];
$fixedMimeTypes = [
@@ -557,6 +230,10 @@ class RepairMimeTypesTest extends \Test\TestCase {
['test.one', 'application/msonenote'],
['test.vsd', 'application/vnd.visio'],
['test.wpd', 'application/vnd.wordperfect'],
+ ['test.htaccess', 'text/plain'],
+ ['.htaccess', 'text/plain'],
+ ['test.bat', 'application/x-msdos-program'],
+ ['test.cmd', 'application/cmd'],
];
$this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
diff --git a/tests/lib/Repair/RepairSharePropagationTest.php b/tests/lib/Repair/RepairSharePropagationTest.php
deleted file mode 100644
index d6010cf5706..00000000000
--- a/tests/lib/Repair/RepairSharePropagationTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/**
- * Copyright (c) 2016 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Repair;
-
-use OC\Repair\SharePropagation;
-use OCP\IConfig;
-use OCP\Migration\IOutput;
-
-class RepairSharePropagationTest extends \Test\TestCase {
- public function keyProvider() {
- return [
- [['1', '2'], ['1', '2']],
- [['1', '2', 'foo'], ['1', '2']],
- [['foo'], []],
- ];
- }
-
- /**
- * @dataProvider keyProvider
- * @param array $startKeys
- * @param array $expectedRemovedKeys
- */
- public function testRemovePropagationEntries(array $startKeys, array $expectedRemovedKeys) {
- /** @var \PHPUnit_Framework_MockObject_MockObject|\OCP\IConfig $config */
- $config = $this->createMock(IConfig::class);
- $config->expects($this->once())
- ->method('getAppKeys')
- ->with('files_sharing')
- ->will($this->returnValue($startKeys));
-
- $removedKeys = [];
-
- $config->expects($this->any())
- ->method('deleteAppValue')
- ->will($this->returnCallback(function ($app, $key) use (&$removedKeys) {
- $removedKeys[] = $key;
- }));
-
- /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
- $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- $step = new SharePropagation($config);
- $step->run($outputMock);
-
- sort($expectedRemovedKeys);
- sort($removedKeys);
-
- $this->assertEquals($expectedRemovedKeys, $removedKeys);
- }
-}
diff --git a/tests/lib/Repair/RepairUnmergedSharesTest.php b/tests/lib/Repair/RepairUnmergedSharesTest.php
deleted file mode 100644
index 2834cfe94b8..00000000000
--- a/tests/lib/Repair/RepairUnmergedSharesTest.php
+++ /dev/null
@@ -1,575 +0,0 @@
-<?php
-/**
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @copyright Copyright (c) 2016, 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 Test\Repair;
-
-
-use OC\Repair\RepairUnmergedShares;
-use OC\Share\Constants;
-use OCP\IUser;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-use Test\TestCase;
-use OC\Share20\DefaultShareProvider;
-use OCP\IUserManager;
-use OCP\IGroupManager;
-
-/**
- * Tests for repairing invalid shares
- *
- * @group DB
- *
- * @see \OC\Repair\RepairUnmergedShares
- */
-class RepairUnmergedSharesTest extends TestCase {
-
- /** @var IRepairStep */
- private $repair;
-
- /** @var \OCP\IDBConnection */
- private $connection;
-
- /** @var int */
- private $lastShareTime;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var IGroupManager */
- private $groupManager;
-
- protected function setUp() {
- parent::setUp();
-
- $config = $this->getMockBuilder('OCP\IConfig')
- ->disableOriginalConstructor()
- ->getMock();
- $config->expects($this->any())
- ->method('getSystemValue')
- ->with('version')
- ->will($this->returnValue('9.0.3.0'));
-
- $this->connection = \OC::$server->getDatabaseConnection();
- $this->deleteAllShares();
-
- $this->userManager = $this->createMock(IUserManager::class);
- $this->groupManager = $this->createMock(IGroupManager::class);
-
- // used to generate incremental stimes
- $this->lastShareTime = time();
-
- /** @var \OCP\IConfig $config */
- $this->repair = new RepairUnmergedShares($config, $this->connection, $this->userManager, $this->groupManager);
- }
-
- protected function tearDown() {
- $this->deleteAllShares();
-
- parent::tearDown();
- }
-
- protected function deleteAllShares() {
- $qb = $this->connection->getQueryBuilder();
- $qb->delete('share')->execute();
- }
-
- private function createShare($type, $sourceId, $recipient, $targetName, $permissions, $parentId = null) {
- $this->lastShareTime += 100;
- $qb = $this->connection->getQueryBuilder();
- $values = [
- 'share_type' => $qb->expr()->literal($type),
- 'share_with' => $qb->expr()->literal($recipient),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('folder'),
- 'item_source' => $qb->expr()->literal($sourceId),
- 'item_target' => $qb->expr()->literal('/' . $sourceId),
- 'file_source' => $qb->expr()->literal($sourceId),
- 'file_target' => $qb->expr()->literal($targetName),
- 'permissions' => $qb->expr()->literal($permissions),
- 'stime' => $qb->expr()->literal($this->lastShareTime),
- ];
- if ($parentId !== null) {
- $values['parent'] = $qb->expr()->literal($parentId);
- }
- $qb->insert('share')
- ->values($values)
- ->execute();
-
- return $this->connection->lastInsertId('*PREFIX*share');
- }
-
- private function getShareById($id) {
- $query = $this->connection->getQueryBuilder();
- $results = $query
- ->select('*')
- ->from('share')
- ->where($query->expr()->eq('id', $query->expr()->literal($id)))
- ->execute()
- ->fetchAll();
-
- if (!empty($results)) {
- return $results[0];
- }
- return null;
- }
-
- public function sharesDataProvider() {
- /**
- * For all these test cases we have the following situation:
- *
- * - "user1" is the share owner
- * - "user2" is the recipient, and member of "recipientgroup1" and "recipientgroup2"
- * - "user1" is member of "samegroup1", "samegroup2" for same group tests
- */
- return [
- [
- // #0 legitimate share:
- // - outsider shares with group1, group2
- // - recipient renamed, resulting in subshares
- // - one subshare for each group share
- // - targets of subshare all match
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 31],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test renamed', 31, 0],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test renamed', 31, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- ['/test', 31],
- ['/test', 31],
- // leave them alone
- ['/test renamed', 31],
- ['/test renamed', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #1 broken share:
- // - outsider shares with group1, group2
- // - only one subshare for two group shares
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 31],
- // child of the previous one
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (2)', 31, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- ['/test', 31],
- ['/test', 31],
- ['/test', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #2 bogus share
- // - outsider shares with group1, group2
- // - one subshare for each group share, both with parenthesis
- // - but the targets do not match when grouped
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 31],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (2)', 31, 0],
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (3)', 31, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- ['/test', 31],
- ['/test', 31],
- // reset to original name as the sub-names have parenthesis
- ['/test', 31],
- ['/test', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #3 bogus share
- // - outsider shares with group1, group2
- // - one subshare for each group share, both renamed manually
- // - but the targets do not match when grouped
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 31],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test_renamed (1 legit paren)', 31, 0],
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test_renamed (2 legit paren)', 31, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- ['/test', 31],
- ['/test', 31],
- // reset to less recent subshare name
- ['/test_renamed (2 legit paren)', 31],
- ['/test_renamed (2 legit paren)', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #4 bogus share
- // - outsider shares with group1, group2
- // - one subshare for each group share, one with parenthesis
- // - but the targets do not match when grouped
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 31],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (2)', 31, 0],
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test_renamed', 31, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- ['/test', 31],
- ['/test', 31],
- // reset to less recent subshare name but without parenthesis
- ['/test_renamed', 31],
- ['/test_renamed', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #5 bogus share
- // - outsider shares with group1, group2
- // - one subshare for each group share
- // - first subshare not renamed (as in real world scenario)
- // - but the targets do not match when grouped
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 31],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test', 31, 0],
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (2)', 31, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- ['/test', 31],
- ['/test', 31],
- // reset to original name
- ['/test', 31],
- ['/test', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #6 bogus share:
- // - outsider shares with group1, group2
- // - one subshare for each group share
- // - non-matching targets
- // - recipient deletes one duplicate (unshare from self, permissions 0)
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 15],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (2)', 0, 0],
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (3)', 15, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- ['/test', 31],
- ['/test', 15],
- // subshares repaired and permissions restored to the max allowed
- ['/test', 31],
- ['/test', 15],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #7 bogus share:
- // - outsider shares with group1, group2
- // - one subshare for each group share
- // - non-matching targets
- // - recipient deletes ALL duplicates (unshare from self, permissions 0)
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 15],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (2)', 0, 0],
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (3)', 0, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- ['/test', 31],
- ['/test', 15],
- // subshares target repaired but left "deleted" as it was the user's choice
- ['/test', 0],
- ['/test', 0],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #8 bogus share:
- // - outsider shares with group1, group2 and also user2
- // - one subshare for each group share
- // - one extra share entry for direct share to user2
- // - non-matching targets
- // - user share has more permissions
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 1],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 15],
- // child of the previous ones
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (2)', 1, 0],
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/test (3)', 15, 1],
- [Constants::SHARE_TYPE_USER, 123, 'user2', '/test (4)', 31],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (5)', 31],
- ],
- [
- ['/test', 1],
- ['/test', 15],
- // subshares repaired
- ['/test', 1],
- ['/test', 15],
- ['/test', 31],
- // leave unrelated alone
- ['/test (5)', 31],
- ]
- ],
- [
- // #9 bogus share:
- // - outsider shares with group1 and also user2
- // - no subshare at all
- // - one extra share entry for direct share to user2
- // - non-matching targets
- // - user share has more permissions
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 1],
- [Constants::SHARE_TYPE_USER, 123, 'user2', '/test (2)', 31],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (5)', 31],
- ],
- [
- ['/test', 1],
- // user share repaired
- ['/test', 31],
- // leave unrelated alone
- ['/test (5)', 31],
- ]
- ],
- [
- // #10 legitimate share with own group:
- // - insider shares with both groups the user is already in
- // - no subshares in this case
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'samegroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'samegroup2', '/test', 31],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- // leave all alone
- ['/test', 31],
- ['/test', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #11 legitimate shares:
- // - group share with same group
- // - group share with other group
- // - user share where recipient renamed
- // - user share where recipient did not rename
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'samegroup1', '/test', 31],
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- [Constants::SHARE_TYPE_USER, 123, 'user3', '/test legit rename', 31],
- [Constants::SHARE_TYPE_USER, 123, 'user4', '/test', 31],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- // leave all alone
- ['/test', 31],
- ['/test', 31],
- ['/test legit rename', 31],
- ['/test', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #12 legitimate share:
- // - outsider shares with group and user directly with different permissions
- // - no subshares
- // - same targets
- [
- [Constants::SHARE_TYPE_GROUP, 123, 'samegroup1', '/test', 1],
- [Constants::SHARE_TYPE_USER, 123, 'user3', '/test', 31],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (4)', 31],
- ],
- [
- // leave all alone
- ['/test', 1],
- ['/test', 31],
- // leave unrelated alone
- ['/test (4)', 31],
- ]
- ],
- [
- // #13 bogus share:
- // - outsider shares with group1, user2 and then group2
- // - user renamed share as soon as it arrived before the next share (order)
- // - one subshare for each group share
- // - one extra share entry for direct share to user2
- // - non-matching targets
- [
- // first share with group
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup1', '/test', 31],
- // recipient renames
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/first', 31, 0],
- // then direct share, user renames too
- [Constants::SHARE_TYPE_USER, 123, 'user2', '/second', 31],
- // another share with the second group
- [Constants::SHARE_TYPE_GROUP, 123, 'recipientgroup2', '/test', 31],
- // use renames it
- [DefaultShareProvider::SHARE_TYPE_USERGROUP, 123, 'user2', '/third', 31, 1],
- // different unrelated share
- [Constants::SHARE_TYPE_GROUP, 456, 'recipientgroup1', '/test (5)', 31],
- ],
- [
- // group share with group1 left alone
- ['/test', 31],
- // first subshare repaired
- ['/third', 31],
- // direct user share repaired
- ['/third', 31],
- // group share with group2 left alone
- ['/test', 31],
- // second subshare repaired
- ['/third', 31],
- // leave unrelated alone
- ['/test (5)', 31],
- ]
- ],
- ];
- }
-
- /**
- * Test merge shares from group shares
- *
- * @dataProvider sharesDataProvider
- */
- public function testMergeGroupShares($shares, $expectedShares) {
- $user1 = $this->createMock(IUser::class);
- $user1->expects($this->any())
- ->method('getUID')
- ->will($this->returnValue('user1'));
-
- $user2 = $this->createMock(IUser::class);
- $user2->expects($this->any())
- ->method('getUID')
- ->will($this->returnValue('user2'));
-
- $users = [$user1, $user2];
-
- $this->groupManager->expects($this->any())
- ->method('getUserGroupIds')
- ->will($this->returnValueMap([
- // owner
- [$user1, ['samegroup1', 'samegroup2']],
- // recipient
- [$user2, ['recipientgroup1', 'recipientgroup2']],
- ]));
-
- $this->userManager->expects($this->once())
- ->method('countUsers')
- ->will($this->returnValue([2]));
- $this->userManager->expects($this->once())
- ->method('callForAllUsers')
- ->will($this->returnCallback(function(\Closure $closure) use ($users) {
- foreach ($users as $user) {
- $closure($user);
- }
- }));
-
- $shareIds = [];
-
- foreach ($shares as $share) {
- // if parent
- if (isset($share[5])) {
- // adjust to real id
- $share[5] = $shareIds[$share[5]];
- } else {
- $share[5] = null;
- }
- $shareIds[] = $this->createShare($share[0], $share[1], $share[2], $share[3], $share[4], $share[5]);
- }
-
- /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
- $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->repair->run($outputMock);
-
- foreach ($expectedShares as $index => $expectedShare) {
- $share = $this->getShareById($shareIds[$index]);
- $this->assertEquals($expectedShare[0], $share['file_target']);
- $this->assertEquals($expectedShare[1], $share['permissions']);
- }
- }
-
- public function duplicateNamesProvider() {
- return [
- // matching
- ['filename (1).txt', true],
- ['folder (2)', true],
- ['filename (1)(2).txt', true],
- // non-matching
- ['filename ().txt', false],
- ['folder ()', false],
- ['folder (1x)', false],
- ['folder (x1)', false],
- ['filename (a)', false],
- ['filename (1).', false],
- ['filename (1).txt.txt', false],
- ['filename (1)..txt', false],
- ];
- }
-
- /**
- * @dataProvider duplicateNamesProvider
- */
- public function testIsPotentialDuplicateName($name, $expectedResult) {
- $this->assertEquals($expectedResult, $this->invokePrivate($this->repair, 'isPotentialDuplicateName', [$name]));
- }
-}
-
diff --git a/tests/lib/Repair/UpdateOutdatedOcsIdsTest.php b/tests/lib/Repair/UpdateOutdatedOcsIdsTest.php
deleted file mode 100644
index eb80e63a202..00000000000
--- a/tests/lib/Repair/UpdateOutdatedOcsIdsTest.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <l8kas@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 Test\Repair;
-
-use OCP\IConfig;
-use Test\TestCase;
-
-/**
- * Class UpdateOutdatedOcsIds
- *
- * @package Test\Repair
- */
-class UpdateOutdatedOcsIdsTest extends TestCase {
- /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
- private $config;
- /** @var \OC\Repair\UpdateOutdatedOcsIds */
- private $updateOutdatedOcsIds;
-
- public function setUp() {
- parent::setUp();
- $this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock();
- $this->updateOutdatedOcsIds = new \OC\Repair\UpdateOutdatedOcsIds($this->config);
- }
-
- public function testGetName() {
- $this->assertSame('Repair outdated OCS IDs', $this->updateOutdatedOcsIds->getName());
- }
-
- public function testFixOcsIdNoOcsId() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('MyNotInstalledApp', 'ocsid')
- ->will($this->returnValue(''));
- $this->assertFalse($this->updateOutdatedOcsIds->fixOcsId('MyNotInstalledApp', '1337', '0815'));
- }
-
- public function testFixOcsIdUpdateOcsId() {
- $this->config
- ->expects($this->at(0))
- ->method('getAppValue')
- ->with('MyInstalledApp', 'ocsid')
- ->will($this->returnValue('1337'));
- $this->config
- ->expects($this->at(1))
- ->method('setAppValue')
- ->with('MyInstalledApp', 'ocsid', '0815');
-
- $this->assertTrue($this->updateOutdatedOcsIds->fixOcsId('MyInstalledApp', '1337', '0815'));
- }
-
- public function testFixOcsIdAlreadyFixed() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('MyAlreadyFixedAppId', 'ocsid')
- ->will($this->returnValue('0815'));
-
- $this->assertFalse($this->updateOutdatedOcsIds->fixOcsId('MyAlreadyFixedAppId', '1337', '0815'));
- }
-}
diff --git a/tests/lib/Repair/fixtures/dropoldtables.xml b/tests/lib/Repair/fixtures/dropoldtables.xml
deleted file mode 100644
index 6c42a8f90a7..00000000000
--- a/tests/lib/Repair/fixtures/dropoldtables.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?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>