From 53d2d95478a2de64778739c7f823f6e01e399d5f Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 8 Jul 2019 14:47:26 +0200 Subject: Remove one time repair steps that have already run when updating to 17 Signed-off-by: Morris Jobke --- tests/lib/Repair/RemoveRootSharesTest.php | 197 ------------------------ tests/lib/Repair/RepairInvalidPathsTest.php | 219 --------------------------- tests/lib/Repair/SetVcardDatabaseUIDTest.php | 128 ---------------- 3 files changed, 544 deletions(-) delete mode 100644 tests/lib/Repair/RemoveRootSharesTest.php delete mode 100644 tests/lib/Repair/RepairInvalidPathsTest.php delete mode 100644 tests/lib/Repair/SetVcardDatabaseUIDTest.php (limited to 'tests/lib/Repair') diff --git a/tests/lib/Repair/RemoveRootSharesTest.php b/tests/lib/Repair/RemoveRootSharesTest.php deleted file mode 100644 index 9a4882bef29..00000000000 --- a/tests/lib/Repair/RemoveRootSharesTest.php +++ /dev/null @@ -1,197 +0,0 @@ - - * - * @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 - * - */ -namespace Test\Repair; - -use OC\Repair\RemoveRootShares; -use OCP\Files\IRootFolder; -use OCP\IDBConnection; -use OCP\IUserManager; -use OCP\Migration\IOutput; -use Test\Traits\UserTrait; - -/** - * Class RemoveOldSharesTest - * - * @package Test\Repair - * @group DB - */ -class RemoveRootSharesTest extends \Test\TestCase { - use UserTrait; - - /** @var RemoveRootShares */ - protected $repair; - - /** @var IDBConnection */ - protected $connection; - - /** @var IOutput */ - private $outputMock; - - /** @var IUserManager */ - private $userManager; - - /** @var IRootFolder */ - private $rootFolder; - - protected function setUp() { - parent::setUp(); - - $this->outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') - ->disableOriginalConstructor() - ->getMock(); - - $this->userManager = \OC::$server->getUserManager(); - $this->rootFolder = \OC::$server->getRootFolder(); - - $this->connection = \OC::$server->getDatabaseConnection(); - $this->repair = new RemoveRootShares($this->connection, $this->userManager, $this->rootFolder); - } - - protected function tearDown() { - $qb = $this->connection->getQueryBuilder(); - $qb->delete('share'); - $qb->execute(); - - return parent::tearDown(); - } - - public function testRootSharesExist() { - //Add test user - $user = $this->userManager->createUser('test', 'test'); - $userFolder = $this->rootFolder->getUserFolder('test'); - $fileId = $userFolder->getId(); - - //Now insert cyclic share - $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($fileId), - 'item_target' => $qb->createNamedParameter('/target'), - 'file_source' => $qb->createNamedParameter($fileId), - 'file_target' => $qb->createNamedParameter('/target'), - 'permissions' => $qb->createNamedParameter(1), - ]); - $qb->execute(); - - $res = $this->invokePrivate($this->repair, 'rootSharesExist', []); - $this->assertTrue($res); - - $user->delete(); - } - - public function testRootSharesDontExist() { - //Add test user - $user = $this->userManager->createUser('test', 'test'); - $userFolder = $this->rootFolder->getUserFolder('test'); - $fileId = $userFolder->getId(); - $user->updateLastLoginTimestamp(); - - //Now insert cyclic share - $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($fileId+1), - 'item_target' => $qb->createNamedParameter('/target'), - 'file_source' => $qb->createNamedParameter($fileId+1), - 'file_target' => $qb->createNamedParameter('/target'), - 'permissions' => $qb->createNamedParameter(1), - ]); - $qb->execute(); - - $res = $this->invokePrivate($this->repair, 'rootSharesExist', []); - $this->assertFalse($res); - - $user->delete(); - } - - public function testRun() { - //Add test user - $user1 = $this->userManager->createUser('test1', 'test1'); - $userFolder = $this->rootFolder->getUserFolder('test1'); - $fileId = $userFolder->getId(); - $user1->updateLastLoginTimestamp(); - - //Now insert cyclic share - $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($fileId), - 'item_target' => $qb->createNamedParameter('/target'), - 'file_source' => $qb->createNamedParameter($fileId), - 'file_target' => $qb->createNamedParameter('/target'), - 'permissions' => $qb->createNamedParameter(1), - ]); - $qb->execute(); - - //Add test user - $user2 = $this->userManager->createUser('test2', 'test2'); - $userFolder = $this->rootFolder->getUserFolder('test2'); - $folder = $userFolder->newFolder('foo'); - $fileId = $folder->getId(); - $user2->updateLastLoginTimestamp(); - - //Now insert cyclic share - $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($fileId), - 'item_target' => $qb->createNamedParameter('/target'), - 'file_source' => $qb->createNamedParameter($fileId), - 'file_target' => $qb->createNamedParameter('/target'), - 'permissions' => $qb->createNamedParameter(1), - ]); - $qb->execute(); - - $this->repair->run($this->outputMock); - - //Verify - $qb = $this->connection->getQueryBuilder(); - $qb->select($qb->func()->count('*', 'count')) - ->from('share'); - - $cursor = $qb->execute(); - $data = $cursor->fetch(); - $cursor->closeCursor(); - - $count = (int)$data['count']; - - $this->assertEquals(1, $count); - - $user1->delete(); - $user2->delete(); - } -} diff --git a/tests/lib/Repair/RepairInvalidPathsTest.php b/tests/lib/Repair/RepairInvalidPathsTest.php deleted file mode 100644 index 17c584fd149..00000000000 --- a/tests/lib/Repair/RepairInvalidPathsTest.php +++ /dev/null @@ -1,219 +0,0 @@ - - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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 - * along with this program. If not, see . - * - */ - -namespace Test\Repair; - -use OC\Files\Cache\Cache; -use OC\Files\Storage\Temporary; -use OC\Repair\NC13\RepairInvalidPaths; -use OCP\IConfig; -use OCP\Migration\IOutput; -use Test\TestCase; - -/** - * @group DB - */ -class RepairInvalidPathsTest extends TestCase { - /** @var Temporary */ - private $storage; - /** @var Cache */ - private $cache; - /** @var Temporary */ - private $storage2; - /** @var Cache */ - private $cache2; - /** @var RepairInvalidPaths */ - private $repair; - - protected function setUp() { - parent::setUp(); - - $this->storage = new Temporary(); - $this->cache = $this->storage->getCache(); - $this->storage2 = new Temporary(); - $this->cache2 = $this->storage2->getCache(); - $config = $this->createMock(IConfig::class); - $config->expects($this->any()) - ->method('getSystemValue') - ->with('version', '0.0.0') - ->willReturn('12.0.0.0'); - $this->repair = new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), $config); - } - - protected function tearDown() { - $this->cache->clear(); - - return parent::tearDown(); - } - - public function testRepairNonDuplicate() { - $this->storage->mkdir('foo/bar/asd'); - $this->storage->mkdir('foo2'); - $this->storage->getScanner()->scan(''); - - $folderId = $this->cache->getId('foo/bar'); - $newParentFolderId = $this->cache->getId('foo2'); - // failed rename, moved entry is updated but not it's children - $this->cache->update($folderId, ['path' => 'foo2/bar', 'parent' => $newParentFolderId]); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo/bar/asd')); - $this->assertFalse($this->cache->inCache('foo2/bar/asd')); - - $this->assertEquals($folderId, $this->cache->get('foo/bar/asd')['parent']); - - $this->repair->run($this->createMock(IOutput::class)); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo2/bar/asd')); - $this->assertFalse($this->cache->inCache('foo/bar/asd')); - - $this->assertEquals($folderId, $this->cache->get('foo2/bar/asd')['parent']); - $this->assertEquals($folderId, $this->cache->getId('foo2/bar')); - } - - public function testRepairDuplicate() { - $this->storage->mkdir('foo/bar/asd'); - $this->storage->mkdir('foo2'); - $this->storage->getScanner()->scan(''); - - $folderId = $this->cache->getId('foo/bar'); - $newParentFolderId = $this->cache->getId('foo2'); - // failed rename, moved entry is updated but not it's children - $this->cache->update($folderId, ['path' => 'foo2/bar', 'parent' => $newParentFolderId]); - $this->storage->rename('foo/bar', 'foo2/bar'); - $this->storage->mkdir('foo2/bar/asd/foo'); - - // usage causes the renamed subfolder to be scanned - $this->storage->getScanner()->scan('foo2/bar/asd'); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo/bar/asd')); - $this->assertTrue($this->cache->inCache('foo2/bar/asd')); - - $this->assertEquals($folderId, $this->cache->get('foo/bar/asd')['parent']); - - $this->repair->run($this->createMock(IOutput::class)); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo2/bar/asd')); - $this->assertFalse($this->cache->inCache('foo/bar/asd')); - - $this->assertEquals($this->cache->getId('foo2/bar'), $this->cache->get('foo2/bar/asd')['parent']); - $this->assertEquals($this->cache->getId('foo2/bar/asd'), $this->cache->get('foo2/bar/asd/foo')['parent']); - } - - public function testRepairMultipleNonDuplicate() { - $this->storage->mkdir('foo/bar/asd'); - $this->storage->mkdir('foo/bar2/asd'); - $this->storage->mkdir('foo2'); - $this->storage->getScanner()->scan(''); - - $folderId1 = $this->cache->getId('foo/bar'); - $folderId2 = $this->cache->getId('foo/bar2'); - $newParentFolderId = $this->cache->getId('foo2'); - // failed rename, moved entry is updated but not it's children - $this->cache->update($folderId1, ['path' => 'foo2/bar', 'parent' => $newParentFolderId]); - $this->cache->update($folderId2, ['path' => 'foo2/bar2', 'parent' => $newParentFolderId]); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo2/bar2')); - $this->assertTrue($this->cache->inCache('foo/bar/asd')); - $this->assertTrue($this->cache->inCache('foo/bar2/asd')); - $this->assertFalse($this->cache->inCache('foo2/bar/asd')); - $this->assertFalse($this->cache->inCache('foo2/bar2/asd')); - - $this->assertEquals($folderId1, $this->cache->get('foo/bar/asd')['parent']); - $this->assertEquals($folderId2, $this->cache->get('foo/bar2/asd')['parent']); - - $this->repair->run($this->createMock(IOutput::class)); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo2/bar2')); - $this->assertTrue($this->cache->inCache('foo2/bar/asd')); - $this->assertTrue($this->cache->inCache('foo2/bar2/asd')); - $this->assertFalse($this->cache->inCache('foo/bar/asd')); - $this->assertFalse($this->cache->inCache('foo/bar2/asd')); - - $this->assertEquals($folderId1, $this->cache->get('foo2/bar/asd')['parent']); - $this->assertEquals($folderId2, $this->cache->get('foo2/bar2/asd')['parent']); - $this->assertEquals($folderId1, $this->cache->getId('foo2/bar')); - $this->assertEquals($folderId2, $this->cache->getId('foo2/bar2')); - } - - public function testRepairNonDuplicateBetweenStorage() { - $this->storage->mkdir('foo/bar/asd'); - $this->storage2->mkdir('foo2'); - $this->storage->getScanner()->scan(''); - $this->storage2->getScanner()->scan(''); - - $folderId = $this->cache->getId('foo/bar'); - $newParentEntry = $this->cache2->get('foo2'); - $newParentFolderId = $newParentEntry->getId(); - // failed rename, moved entry is updated but not it's children - $this->cache->update($folderId, ['path' => 'foo2/bar', 'parent' => $newParentFolderId, 'storage' => $newParentEntry->getStorageId()]); - - $this->assertTrue($this->cache2->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo/bar/asd')); - $this->assertFalse($this->cache2->inCache('foo2/bar/asd')); - - $this->assertEquals($folderId, $this->cache->get('foo/bar/asd')['parent']); - - $this->repair->run($this->createMock(IOutput::class)); - - $this->assertTrue($this->cache2->inCache('foo2/bar')); - $this->assertTrue($this->cache2->inCache('foo2/bar/asd')); - $this->assertFalse($this->cache->inCache('foo/bar/asd')); - - $this->assertEquals($folderId, $this->cache2->get('foo2/bar/asd')['parent']); - $this->assertEquals($folderId, $this->cache2->getId('foo2/bar')); - } - - public function shouldRunDataProvider() { - return [ - ['11.0.0.0', true], - ['11.0.0.31', true], - ['11.0.5.2', false], - ['12.0.0.0', true], - ['12.0.0.1', true], - ['12.0.0.31', false], - ['13.0.0.0', true], - ['13.0.0.1', false] - ]; - } - - /** - * @dataProvider shouldRunDataProvider - * - * @param string $from - * @param boolean $expected - */ - public function testShouldRun($from, $expected) { - $config = $this->createMock(IConfig::class); - $config->expects($this->any()) - ->method('getSystemValue') - ->with('version', '0.0.0') - ->willReturn($from); - $repair = new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), $config); - - $this->assertEquals($expected, $this->invokePrivate($repair, 'shouldRun')); - } -} diff --git a/tests/lib/Repair/SetVcardDatabaseUIDTest.php b/tests/lib/Repair/SetVcardDatabaseUIDTest.php deleted file mode 100644 index 2939528a21a..00000000000 --- a/tests/lib/Repair/SetVcardDatabaseUIDTest.php +++ /dev/null @@ -1,128 +0,0 @@ - - * - * @author John Molakvoæ - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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 - * along with this program. If not, see . - * - */ - -namespace Test\Repair; - -use OCP\IConfig; -use OCP\ILogger; -use OCP\Migration\IOutput; -use OC\Repair\NC15\SetVcardDatabaseUID; -use Test\TestCase; - -/** - * @group DB - */ -class SetVcardDatabaseUIDTest extends TestCase { - - /** @var SetVcardDatabaseUID */ - private $repair; - - /** @var IConfig */ - private $config; - - /** @var Ilogger */ - private $logger; - - protected function setUp() { - parent::setUp(); - - $this->config = $this->createMock(IConfig::class); - $this->logger = $this->createMock(Ilogger::class); - $this->repair = new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), $this->config, $this->logger); - } - - protected function tearDown() { - return parent::tearDown(); - } - - public function dataTestVcards() { - return [ - // classic vcard - ['BEGIN:VCARD'.PHP_EOL. - 'VERSION:3.0'.PHP_EOL. - 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. - 'UID:Test'.PHP_EOL. - 'FN:Test'.PHP_EOL. - 'N:Test;;;;'.PHP_EOL. - 'END:VCARD', 'Test'], - - // UID as url - ['BEGIN:VCARD'.PHP_EOL. - 'VERSION:3.0'.PHP_EOL. - 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. - 'UID:https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'.PHP_EOL. - 'FN:Test'.PHP_EOL. - 'N:Test;;;;'.PHP_EOL. - 'END:VCARD', 'https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'], - - // No uid - ['BEGIN:VCARD'.PHP_EOL. - 'VERSION:3.0'.PHP_EOL. - 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. - 'FN:Test'.PHP_EOL. - 'N:Test;;;;'.PHP_EOL. - 'END:VCARD', false] - ]; - } - - /** - * @dataProvider dataTestVcards - * - * @param string $from - * @param string|boolean $expected - */ - public function testExtractUIDFromVcard($from, $expected) { - $output = $this->createMock(IOutput::class); - $uid = $this->invokePrivate($this->repair, 'getUid', ['carddata' => $from, 'output' => $output]); - $this->assertEquals($expected, $uid); - } - - public function shouldRunDataProvider() { - return [ - ['11.0.0.0', true], - ['15.0.0.3', false], - ['13.0.5.2', true], - ['12.0.0.0', true], - ['16.0.0.1', false], - ['15.0.0.2', true], - ['13.0.0.0', true], - ['13.0.0.1', true] - ]; - } - - /** - * @dataProvider shouldRunDataProvider - * - * @param string $from - * @param boolean $expected - */ - public function testShouldRun($from, $expected) { - $this->config->expects($this->any()) - ->method('getSystemValue') - ->with('version', '0.0.0.0') - ->willReturn($from); - - $this->assertEquals($expected, $this->invokePrivate($this->repair, 'shouldRun')); - } - -} -- cgit v1.2.3