summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-07-06 18:31:18 +0200
committerGitHub <noreply@github.com>2017-07-06 18:31:18 +0200
commitb4a221f9beae44634931abb193198d02eda30fad (patch)
tree0b600b26112f8d00a9e74dd219f3aaf75285acfb /tests
parentad1d4d363fca28b34396bcfb605ba5336cf040f7 (diff)
parent601362e164632a1b68e896bd5359d0b7308eed4f (diff)
downloadnextcloud-server-b4a221f9beae44634931abb193198d02eda30fad.tar.gz
nextcloud-server-b4a221f9beae44634931abb193198d02eda30fad.zip
Merge pull request #5424 from nextcloud/moveFromCache-from-shared
fix moving folders out of a cache jail
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Files/Cache/Wrapper/CacheJailTest.php50
-rw-r--r--tests/lib/Repair/RepairInvalidPathsTest.php117
2 files changed, 167 insertions, 0 deletions
diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
index e3043c50d57..f26e3a59f1c 100644
--- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
+++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
@@ -8,6 +8,7 @@
namespace Test\Files\Cache\Wrapper;
+use OC\Files\Cache\Wrapper\CacheJail;
use Test\Files\Cache\CacheTest;
/**
@@ -80,4 +81,53 @@ class CacheJailTest extends CacheTest {
//not supported
$this->assertTrue(true);
}
+
+ function testMoveFromJail() {
+ $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ $this->sourceCache->put('source', $folderData);
+ $this->sourceCache->put('source/foo', $folderData);
+ $this->sourceCache->put('source/foo/bar', $folderData);
+ $this->sourceCache->put('target', $folderData);
+
+ $jail = new CacheJail($this->sourceCache, 'source');
+
+ $this->sourceCache->moveFromCache($jail, 'foo', 'target/foo');
+
+ $this->assertTrue($this->sourceCache->inCache('target/foo'));
+ $this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
+ }
+
+ function testMoveToJail() {
+ $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ $this->sourceCache->put('source', $folderData);
+ $this->sourceCache->put('source/foo', $folderData);
+ $this->sourceCache->put('source/foo/bar', $folderData);
+ $this->sourceCache->put('target', $folderData);
+
+ $jail = new CacheJail($this->sourceCache, 'target');
+
+ $jail->moveFromCache($this->sourceCache, 'source/foo', 'foo');
+
+ $this->assertTrue($this->sourceCache->inCache('target/foo'));
+ $this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
+ }
+
+ function testMoveBetweenJail() {
+ $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ $this->sourceCache->put('source', $folderData);
+ $this->sourceCache->put('source/foo', $folderData);
+ $this->sourceCache->put('source/foo/bar', $folderData);
+ $this->sourceCache->put('target', $folderData);
+
+ $jail = new CacheJail($this->sourceCache, 'target');
+ $sourceJail = new CacheJail($this->sourceCache, 'source');
+
+ $jail->moveFromCache($sourceJail, 'foo', 'foo');
+
+ $this->assertTrue($this->sourceCache->inCache('target/foo'));
+ $this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
+ }
}
diff --git a/tests/lib/Repair/RepairInvalidPathsTest.php b/tests/lib/Repair/RepairInvalidPathsTest.php
new file mode 100644
index 00000000000..b18758585c1
--- /dev/null
+++ b/tests/lib/Repair/RepairInvalidPathsTest.php
@@ -0,0 +1,117 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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 RepairInvalidPaths */
+ private $repair;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->storage = new Temporary();
+ $this->cache = $this->storage->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']);
+ }
+}