aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php')
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php133
1 files changed, 102 insertions, 31 deletions
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
index fa8ec535061..3387808445a 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
@@ -1,27 +1,17 @@
<?php
+
/**
- * @author Jörn Friedrich Dreyer
- * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library 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 library. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\Jail;
+use OCP\Constants;
use OCP\Files\ObjectStore\IObjectStore;
use Test\Files\Storage\Storage;
@@ -55,7 +45,7 @@ class ObjectStoreStorageTest extends Storage {
parent::tearDown();
}
- public function testStat() {
+ public function testStat(): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$ctimeStart = time();
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
@@ -79,29 +69,27 @@ class ObjectStoreStorageTest extends Storage {
}
}
- public function testCheckUpdate() {
+ public function testCheckUpdate(): void {
$this->markTestSkipped('Detecting external changes is not supported on object storages');
}
- /**
- * @dataProvider copyAndMoveProvider
- */
- public function testMove($source, $target) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')]
+ public function testMove($source, $target): void {
$this->initSourceAndTarget($source);
- $sourceId = $this->instance->getCache()->getId(ltrim('/',$source));
+ $sourceId = $this->instance->getCache()->getId(ltrim($source, '/'));
$this->assertNotEquals(-1, $sourceId);
$this->instance->rename($source, $target);
- $this->assertTrue($this->instance->file_exists($target), $target.' was not created');
- $this->assertFalse($this->instance->file_exists($source), $source.' still exists');
+ $this->assertTrue($this->instance->file_exists($target), $target . ' was not created');
+ $this->assertFalse($this->instance->file_exists($source), $source . ' still exists');
$this->assertSameAsLorem($target);
- $targetId = $this->instance->getCache()->getId(ltrim('/',$target));
+ $targetId = $this->instance->getCache()->getId(ltrim($target, '/'));
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
- public function testRenameDirectory() {
+ public function testRenameDirectory(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
$this->instance->file_put_contents('source/test2.txt', 'qwerty');
@@ -130,7 +118,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
- public function testRenameOverWriteDirectory() {
+ public function testRenameOverWriteDirectory(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
$sourceId = $this->instance->getCache()->getId('source');
@@ -150,7 +138,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
- public function testRenameOverWriteDirectoryOverFile() {
+ public function testRenameOverWriteDirectoryOverFile(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
$sourceId = $this->instance->getCache()->getId('source');
@@ -167,7 +155,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
- public function testWriteObjectSilentFailure() {
+ public function testWriteObjectSilentFailure(): void {
$objectStore = $this->instance->getObjectStore();
$this->instance->setObjectStore(new FailWriteObjectStore($objectStore));
@@ -180,7 +168,16 @@ class ObjectStoreStorageTest extends Storage {
$this->assertFalse($this->instance->file_exists('test.txt'));
}
- public function testDeleteObjectFailureKeepCache() {
+ public function testWriteObjectSilentFailureNoCheck(): void {
+ $objectStore = $this->instance->getObjectStore();
+ $this->instance->setObjectStore(new FailWriteObjectStore($objectStore));
+ $this->instance->setValidateWrites(false);
+
+ $this->instance->file_put_contents('test.txt', 'foo');
+ $this->assertTrue($this->instance->file_exists('test.txt'));
+ }
+
+ public function testDeleteObjectFailureKeepCache(): void {
$objectStore = $this->instance->getObjectStore();
$this->instance->setObjectStore(new FailDeleteObjectStore($objectStore));
$cache = $this->instance->getCache();
@@ -204,4 +201,78 @@ class ObjectStoreStorageTest extends Storage {
$this->assertTrue($cache->inCache('foo'));
$this->assertTrue($cache->inCache('foo/test.txt'));
}
+
+ public function testCopyBetweenJails(): void {
+ $this->instance->mkdir('a');
+ $this->instance->mkdir('b');
+ $jailA = new Jail([
+ 'storage' => $this->instance,
+ 'root' => 'a'
+ ]);
+ $jailB = new Jail([
+ 'storage' => $this->instance,
+ 'root' => 'b'
+ ]);
+ $jailA->mkdir('sub');
+ $jailA->file_put_contents('1.txt', '1');
+ $jailA->file_put_contents('sub/2.txt', '2');
+ $jailA->file_put_contents('sub/3.txt', '3');
+
+ $jailB->copyFromStorage($jailA, '', 'target');
+
+ $this->assertEquals('1', $this->instance->file_get_contents('b/target/1.txt'));
+ $this->assertEquals('2', $this->instance->file_get_contents('b/target/sub/2.txt'));
+ $this->assertEquals('3', $this->instance->file_get_contents('b/target/sub/3.txt'));
+ }
+
+ public function testCopyPreservesPermissions(): void {
+ $cache = $this->instance->getCache();
+
+ $this->instance->file_put_contents('test.txt', 'foo');
+ $this->assertTrue($cache->inCache('test.txt'));
+
+ $cache->update($cache->getId('test.txt'), ['permissions' => Constants::PERMISSION_READ]);
+ $this->assertEquals(Constants::PERMISSION_READ, $this->instance->getPermissions('test.txt'));
+
+ $this->assertTrue($this->instance->copy('test.txt', 'new.txt'));
+
+ $this->assertTrue($cache->inCache('new.txt'));
+ $this->assertEquals(Constants::PERMISSION_READ, $this->instance->getPermissions('new.txt'));
+ }
+
+ /**
+ * Test that copying files will drop permissions like local storage does
+ * TODO: Drop this and fix local storage
+ */
+ public function testCopyGrantsPermissions(): void {
+ $config['objectstore'] = $this->objectStorage;
+ $config['handleCopiesAsOwned'] = true;
+ $instance = new ObjectStoreStorageOverwrite($config);
+
+ $cache = $instance->getCache();
+
+ $instance->file_put_contents('test.txt', 'foo');
+ $this->assertTrue($cache->inCache('test.txt'));
+
+ $cache->update($cache->getId('test.txt'), ['permissions' => Constants::PERMISSION_READ]);
+ $this->assertEquals(Constants::PERMISSION_READ, $instance->getPermissions('test.txt'));
+
+ $this->assertTrue($instance->copy('test.txt', 'new.txt'));
+
+ $this->assertTrue($cache->inCache('new.txt'));
+ $this->assertEquals(Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
+ }
+
+ public function testCopyFolderSize(): void {
+ $cache = $this->instance->getCache();
+
+ $this->instance->mkdir('source');
+ $this->instance->file_put_contents('source/test.txt', 'foo');
+ $this->instance->getUpdater()->update('source/test.txt');
+ $this->assertEquals(3, $cache->get('source')->getSize());
+
+ $this->assertTrue($this->instance->copy('source', 'target'));
+
+ $this->assertEquals(3, $cache->get('target')->getSize());
+ }
}