From 337df1f7600c32c91543dcfef9d476b4f49e85cc Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 17 Sep 2024 17:32:33 +0200 Subject: [PATCH 01/17] fix: Drop unnecessary exit Signed-off-by: Louis Chemineau --- apps/dav/lib/Files/ErrorPagePlugin.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/dav/lib/Files/ErrorPagePlugin.php b/apps/dav/lib/Files/ErrorPagePlugin.php index ddf04d0f7632e..2b93f0e7a49ac 100644 --- a/apps/dav/lib/Files/ErrorPagePlugin.php +++ b/apps/dav/lib/Files/ErrorPagePlugin.php @@ -92,7 +92,6 @@ public function generateBody(\Throwable $ex, int $httpCode): mixed { */ public function sendResponse() { $this->server->sapi->sendResponse($this->server->httpResponse); - exit(); } private function acceptHtml(): bool { From 5bcd74ae87c6e739d3711262345a5881f785e863 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 11:13:20 +0200 Subject: [PATCH 02/17] fix: get source file before moving the cache item in objectstore moveFromStorage Signed-off-by: Robin Appelman --- lib/private/Files/ObjectStore/ObjectStoreStorage.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 1d940b7e619a9..93beaaeca6c18 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -605,10 +605,14 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t } $sourceStorage->rmdir($sourceInternalPath); } else { + $sourceStream = $sourceStorage->fopen($sourceInternalPath, 'r'); + if (!$sourceStream) { + return false; + } // move the cache entry before the contents so that we have the correct fileid/urn for the target $this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath); try { - $this->writeStream($targetInternalPath, $sourceStorage->fopen($sourceInternalPath, 'r'), $sourceCacheEntry->getSize()); + $this->writeStream($targetInternalPath, $sourceStream, $sourceCacheEntry->getSize()); } catch (\Exception $e) { // restore the cache entry $sourceCache->moveFromCache($this->getCache(), $targetInternalPath, $sourceInternalPath); From 9b07b7d9c1ff4db8094f8db0c661738c505e0310 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 11:13:51 +0200 Subject: [PATCH 03/17] fix: create intermediate directories for objectstore moveFromStorage Signed-off-by: Robin Appelman --- lib/private/Files/ObjectStore/ObjectStoreStorage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 93beaaeca6c18..1285e7ea177ce 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -600,6 +600,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t $sourceCacheEntry = $sourceCache->get($sourceInternalPath); } if ($sourceCacheEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) { + $this->mkdir($targetInternalPath); foreach ($sourceCache->getFolderContents($sourceInternalPath) as $child) { $this->moveFromStorage($sourceStorage, $child->getPath(), $targetInternalPath . '/' . $child->getName()); } From e8c7216d5bf464ccf09dfc438f4c7c6ca9d4c2a8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 11:14:20 +0200 Subject: [PATCH 04/17] fix: cleanup objectstore file_put_content Signed-off-by: Robin Appelman --- lib/private/Files/ObjectStore/ObjectStoreStorage.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 1285e7ea177ce..faab6e74eb0db 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -462,13 +462,10 @@ public function needsPartFile() { } public function file_put_contents($path, $data) { - $handle = $this->fopen($path, 'w+'); - if (!$handle) { - return false; - } - $result = fwrite($handle, $data); - fclose($handle); - return $result; + $fh = fopen('php://temp', 'w+'); + fwrite($fh, $data); + rewind($fh); + return $this->writeStream($path, $fh, strlen($data)); } public function writeStream(string $path, $stream, ?int $size = null): int { From 1e03bd5d18f087e10ab8aca29f8d3737a99406c5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 11:14:41 +0200 Subject: [PATCH 05/17] fix: fix object store id for test object store Signed-off-by: Robin Appelman --- lib/private/Files/ObjectStore/StorageObjectStore.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/ObjectStore/StorageObjectStore.php b/lib/private/Files/ObjectStore/StorageObjectStore.php index 5e7125e18a6e3..4361795ec4533 100644 --- a/lib/private/Files/ObjectStore/StorageObjectStore.php +++ b/lib/private/Files/ObjectStore/StorageObjectStore.php @@ -27,8 +27,8 @@ public function __construct(IStorage $storage) { * @return string the container or bucket name where objects are stored * @since 7.0.0 */ - public function getStorageId() { - $this->storage->getId(); + public function getStorageId(): string { + return $this->storage->getId(); } /** From 7b1b5526b77320adca9377e5c079857e0fb336d0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 12:29:13 +0200 Subject: [PATCH 06/17] fix: verify that parent exists in cache when inserting Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Cache.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 876f17ff7402a..c3451326d6f3e 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -265,6 +265,9 @@ public function insert($file, array $data) { if (!isset($data['parent'])) { $data['parent'] = $this->getParentId($file); } + if ($data['parent'] === -1 && $file !== '') { + throw new \Exception('Parent folder not in filecache for ' . $file); + } $data['name'] = basename($file); [$values, $extensionValues] = $this->normalizeData($data); From e82ab7816fcbf5c2451e1ec016cf18a332c38934 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 12:29:29 +0200 Subject: [PATCH 07/17] test: fix incorrect ltrim usage in test Signed-off-by: Robin Appelman --- tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php index 8ffd27f0069fc..95cae5f8b2554 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php @@ -76,7 +76,7 @@ public function testCheckUpdate() { */ public function testMove($source, $target) { $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); @@ -85,7 +85,7 @@ public function testMove($source, $target) { $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'); } From dd68f678b20d7a0a286f112dc3bb22f87b8cbb46 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 13:54:21 +0200 Subject: [PATCH 08/17] fix: ensure parent folder exists when writing a file to object storage Signed-off-by: Robin Appelman --- lib/private/Files/ObjectStore/ObjectStoreStorage.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index faab6e74eb0db..b6e571b134ebe 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -495,6 +495,10 @@ public function writeStream(string $path, $stream, ?int $size = null): int { if ($exists) { $fileId = $stat['fileid']; } else { + $parent = $this->normalizePath(dirname($path)); + if (!$this->is_dir($parent)) { + throw new \InvalidArgumentException("trying to upload a file ($path) inside a non-directory ($parent)"); + } $fileId = $this->getCache()->put($uploadPath, $stat); } From 8b8508c8b126de8a5c0608b7a8fbf2cc6eb3a9b7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 13:54:37 +0200 Subject: [PATCH 09/17] test: put parent items into cache in tests Signed-off-by: Robin Appelman --- .../tests/External/CacheTest.php | 2 + tests/lib/Files/Cache/CacheTest.php | 39 ++++++------ .../Files/Cache/MoveFromCacheTraitTest.php | 4 ++ .../lib/Files/Cache/Wrapper/CacheJailTest.php | 61 ++++++++++--------- tests/lib/Files/Node/FolderTest.php | 28 ++++++++- tests/lib/Repair/RepairMimeTypesTest.php | 1 + 6 files changed, 85 insertions(+), 50 deletions(-) diff --git a/apps/files_sharing/tests/External/CacheTest.php b/apps/files_sharing/tests/External/CacheTest.php index fa613b6de98e6..6f076cb475bc4 100644 --- a/apps/files_sharing/tests/External/CacheTest.php +++ b/apps/files_sharing/tests/External/CacheTest.php @@ -11,6 +11,7 @@ use OCP\Contacts\IManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudIdManager; +use OCP\Files\Cache\ICacheEntry; use OCP\ICacheFactory; use OCP\IURLGenerator; use OCP\IUserManager; @@ -74,6 +75,7 @@ protected function setUp(): void { $this->storage, $this->cloudIdManager->getCloudId($this->remoteUser, 'http://example.com/owncloud') ); + $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $this->cache->put( 'test.txt', [ diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 12955f662cc00..622df0c1d86f2 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -11,6 +11,7 @@ use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\Search\ISearchComparison; use OCP\IDBConnection; use OCP\IUser; @@ -148,7 +149,7 @@ public function testFolder($folder) { } $file2 = $folder . '/bar'; $file3 = $folder . '/foo'; - $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $fileData = []; $fileData['bar'] = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file']; $fileData['foo'] = ['size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file']; @@ -188,7 +189,7 @@ public function testFolder($folder) { } public function testRemoveRecursive() { - $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $fileData = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'text/plain']; $folders = ['folder', 'folder/subfolder', 'folder/sub2', 'folder/sub2/sub3']; $files = ['folder/foo.txt', 'folder/bar.txt', 'folder/subfolder/asd.txt', 'folder/sub2/qwerty.txt', 'folder/sub2/sub3/foo.txt']; @@ -224,7 +225,7 @@ public function testEncryptedFolder() { $file1 = 'folder'; $file2 = 'folder/bar'; $file3 = 'folder/foo'; - $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $fileData = []; $fileData['bar'] = ['size' => 1000, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file']; $fileData['foo'] = ['size' => 20, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file']; @@ -267,11 +268,10 @@ public function testRootFolderSizeForNonHomeStorage() { $dir1 = 'knownsize'; $dir2 = 'unknownsize'; $fileData = []; - $fileData[''] = ['size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']; - $fileData[$dir1] = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory']; - $fileData[$dir2] = ['size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory']; + $fileData[''] = ['size' => -1, 'mtime' => 20, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; + $fileData[$dir1] = ['size' => 1000, 'mtime' => 20, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; + $fileData[$dir2] = ['size' => -1, 'mtime' => 25, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; - $this->cache->put('', $fileData['']); $this->cache->put($dir1, $fileData[$dir1]); $this->cache->put($dir2, $fileData[$dir2]); @@ -338,7 +338,6 @@ public function testSearch() { $this->assertEquals(1, count($this->cache->search('foo'))); $this->assertEquals(1, count($this->cache->search('%folder%'))); $this->assertEquals(1, count($this->cache->search('folder%'))); - $this->assertEquals(3, count($this->cache->search('%'))); // case insensitive search should match the same files $this->assertEquals(2, count($this->cache->search('%Foo%'))); @@ -450,7 +449,7 @@ public function movePathProvider() { */ public function testMove($sourceFolder, $targetFolder, $children) { $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar']; - $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; // create folders foreach ([$sourceFolder, $targetFolder] as $current) { @@ -485,7 +484,7 @@ public function testMove($sourceFolder, $targetFolder, $children) { public function testMoveFromCache() { $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar']; - $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $this->cache2->put('folder', $folderData); $this->cache2->put('folder/sub', $data); @@ -554,6 +553,7 @@ public function testStorageMTime() { public function testLongId() { $storage = new LongId([]); $cache = $storage->getCache(); + $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $storageId = $storage->getId(); $data = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file']; $id = $cache->put('foo', $data); @@ -582,7 +582,7 @@ public function testWithoutNormalizer() { ->method('normalize') ->willReturnArgument(0); - $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $data = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; // put root folder $this->assertFalse($cacheMock->get('folder')); @@ -621,7 +621,7 @@ public function testWithNormalizer() { // folder name "Schön" with U+0308 (un-normalized) $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e"; - $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $data = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; // put root folder $this->assertFalse($this->cache->get('folder')); @@ -660,12 +660,8 @@ public function bogusPathNamesProvider() { * @dataProvider bogusPathNamesProvider */ public function testBogusPaths($bogusPath, $fixedBogusPath) { - $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; - - // put root folder - $this->assertFalse($this->cache->get('')); - $parentId = $this->cache->put('', $data); - $this->assertGreaterThan(0, $parentId); + $data = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; + $parentId = $this->cache->getId(''); $this->assertGreaterThan(0, $this->cache->put($bogusPath, $data)); @@ -719,7 +715,7 @@ public function testEscaping($name) { $this->assertTrue($this->cache->inCache($name . 'asd')); $this->cache->remove($name . 'asd'); $this->assertFalse($this->cache->inCache($name . 'asd')); - $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $this->cache->put($name, $folderData); $this->cache->put('other', $folderData); $childs = ['asd', 'bar', 'foo', 'sub/folder']; @@ -743,8 +739,7 @@ public function testEscaping($name) { } public function testExtended() { - $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; - $this->cache->put("", $folderData); + $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'creation_time' => 20]; $id1 = $this->cache->put("foo1", $data); @@ -827,5 +822,7 @@ protected function setUp(): void { $this->storage2 = new \OC\Files\Storage\Temporary([]); $this->cache = new \OC\Files\Cache\Cache($this->storage); $this->cache2 = new \OC\Files\Cache\Cache($this->storage2); + $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); } } diff --git a/tests/lib/Files/Cache/MoveFromCacheTraitTest.php b/tests/lib/Files/Cache/MoveFromCacheTraitTest.php index f0f143f431fc4..e8a6c8acf32c3 100644 --- a/tests/lib/Files/Cache/MoveFromCacheTraitTest.php +++ b/tests/lib/Files/Cache/MoveFromCacheTraitTest.php @@ -8,6 +8,7 @@ namespace Test\Files\Cache; use OC\Files\Cache\MoveFromCacheTrait; +use OCP\Files\Cache\ICacheEntry; class FallBackCrossCacheMoveCache extends \OC\Files\Cache\Cache { use MoveFromCacheTrait; @@ -26,5 +27,8 @@ protected function setUp(): void { $this->storage2 = new \OC\Files\Storage\Temporary([]); $this->cache = new FallBackCrossCacheMoveCache($this->storage); $this->cache2 = new FallBackCrossCacheMoveCache($this->storage2); + + $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); } } diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php index d0a6f99cb19f3..44869ccfd55cb 100644 --- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php +++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php @@ -13,6 +13,7 @@ use OC\Files\Storage\Wrapper\Jail; use OC\User\User; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\Search\ISearchComparison; use Test\Files\Cache\CacheTest; @@ -31,17 +32,19 @@ class CacheJailTest extends CacheTest { protected function setUp(): void { parent::setUp(); - $this->storage->mkdir('foo'); + $this->storage->mkdir('jail'); $this->sourceCache = $this->cache; - $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'foo'); + $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'jail'); + $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); } public function testSearchOutsideJail() { $this->storage->getScanner()->scan(''); - $file1 = 'foo/foobar'; + $file1 = 'jail/foobar'; $file2 = 'folder/foobar'; $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder']; + $this->sourceCache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $this->sourceCache->put($file1, $data1); $this->sourceCache->put($file2, $data1); @@ -52,20 +55,20 @@ public function testSearchOutsideJail() { $this->assertEquals('foobar', $result[0]['path']); $result = $this->cache->search('%foo%'); - $this->assertCount(2, $result); + $this->assertCount(1, $result); usort($result, function ($a, $b) { return $a['path'] <=> $b['path']; }); - $this->assertEquals('', $result[0]['path']); - $this->assertEquals('foobar', $result[1]['path']); + $this->assertEquals('foobar', $result[0]['path']); } public function testSearchMimeOutsideJail() { $this->storage->getScanner()->scan(''); - $file1 = 'foo/foobar'; + $file1 = 'jail/foobar'; $file2 = 'folder/foobar'; $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder']; + $this->sourceCache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $this->sourceCache->put($file1, $data1); $this->sourceCache->put($file2, $data1); @@ -78,10 +81,12 @@ public function testSearchMimeOutsideJail() { public function testSearchQueryOutsideJail() { $this->storage->getScanner()->scan(''); - $file1 = 'foo/foobar'; + $file1 = 'jail/foobar'; $file2 = 'folder/foobar'; $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder']; + + $this->sourceCache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $this->sourceCache->put($file1, $data1); $this->sourceCache->put($file2, $data1); @@ -92,19 +97,19 @@ public function testSearchQueryOutsideJail() { $this->assertCount(1, $result); $this->assertEquals('foobar', $result[0]['path']); - $query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foo'), 10, 0, [], $user); + $query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'jail'), 10, 0, [], $user); $result = $this->cache->searchQuery($query); $this->assertCount(1, $result); $this->assertEquals('', $result[0]['path']); } public function testClearKeepEntriesOutsideJail() { - $file1 = 'foo/foobar'; - $file2 = 'foo/foobar/asd'; + $file1 = 'jail/foobar'; + $file2 = 'jail/foobar/asd'; $file3 = 'folder/foobar'; - $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; - $this->sourceCache->put('foo', $data1); + $this->sourceCache->put('folder', $data1); $this->sourceCache->put($file1, $data1); $this->sourceCache->put($file2, $data1); $this->sourceCache->put($file3, $data1); @@ -116,8 +121,8 @@ public function testClearKeepEntriesOutsideJail() { } public function testGetById() { - $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; - $id = $this->sourceCache->put('foo/bar', $data1); + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; + $id = $this->sourceCache->put('jail/bar', $data1); // path from jailed foo of foo/bar is bar $path = $this->cache->getPathById($id); @@ -126,7 +131,7 @@ public function testGetById() { // path from jailed '' of foo/bar is foo/bar $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, ''); $path = $this->cache->getPathById($id); - $this->assertEquals('foo/bar', $path); + $this->assertEquals('jail/bar', $path); } public function testGetIncomplete() { @@ -135,7 +140,7 @@ public function testGetIncomplete() { } public function testMoveFromJail() { - $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $this->sourceCache->put('source', $folderData); $this->sourceCache->put('source/foo', $folderData); @@ -151,7 +156,7 @@ public function testMoveFromJail() { } public function testMoveToJail() { - $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $this->sourceCache->put('source', $folderData); $this->sourceCache->put('source/foo', $folderData); @@ -167,7 +172,7 @@ public function testMoveToJail() { } public function testMoveBetweenJail() { - $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory']; + $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $this->sourceCache->put('source', $folderData); $this->sourceCache->put('source/foo', $folderData); @@ -185,9 +190,9 @@ public function testMoveBetweenJail() { public function testSearchNested() { $this->storage->getScanner()->scan(''); - $file1 = 'foo'; - $file2 = 'foo/bar'; - $file3 = 'foo/bar/asd'; + $file1 = 'jail'; + $file2 = 'jail/bar'; + $file3 = 'jail/bar/asd'; $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder']; $this->sourceCache->put($file1, $data1); @@ -203,9 +208,9 @@ public function testSearchNested() { public function testRootJail() { $this->storage->getScanner()->scan(''); - $file1 = 'foo'; - $file2 = 'foo/bar'; - $file3 = 'foo/bar/asd'; + $file1 = 'jail'; + $file2 = 'jail/bar'; + $file3 = 'jail/bar/asd'; $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder']; $this->sourceCache->put($file1, $data1); @@ -216,13 +221,13 @@ public function testRootJail() { $result = $nested->search('%asd%'); $this->assertCount(1, $result); - $this->assertEquals('foo/bar/asd', $result[0]['path']); + $this->assertEquals('jail/bar/asd', $result[0]['path']); } public function testWatcher() { $storage = new Jail([ 'storage' => $this->storage, - 'root' => 'foo' + 'root' => 'jail' ]); $storage->getScanner()->scan(''); $storage->file_put_contents('bar', 'asd'); @@ -235,7 +240,7 @@ public function testWatcher() { public function testWatcherAfterInnerWatcher() { $storage = new Jail([ 'storage' => $this->storage, - 'root' => 'foo' + 'root' => 'jail' ]); $storage->getScanner()->scan(''); $storage->file_put_contents('bar', 'asd'); diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 46fda6c3a7665..c0c14128d6f50 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -17,6 +17,7 @@ use OC\Files\Node\Folder; use OC\Files\Node\Node; use OC\Files\Node\Root; +use OC\Files\Search\SearchBinaryOperator; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchOrder; use OC\Files\Search\SearchQuery; @@ -26,6 +27,7 @@ use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; +use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchComparison; use OCP\Files\Search\ISearchOrder; use OCP\Files\Storage; @@ -312,6 +314,7 @@ public function testSearch() { ->method('getInternalPath') ->willReturn('foo'); + $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']); @@ -354,6 +357,7 @@ public function testSearchInRoot() { $storage->method('getCache') ->willReturn($cache); + $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('files', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('files/foo', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']); @@ -392,6 +396,7 @@ public function testSearchInStorageRoot() { $storage->method('getCache') ->willReturn($cache); + $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']); @@ -446,9 +451,11 @@ public function testSearchSubStorages() { $subStorage->method('getCache') ->willReturn($subCache); + $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']); + $subCache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $subCache->insert('asd', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $subCache->insert('asd/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']); @@ -724,6 +731,10 @@ public function testRecent(): void { $cache = $storage->getCache(); + $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $cache->insert('bar', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $cache->insert('bar/foo', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $cache->insert('bar/asd', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $id1 = $cache->put('bar/foo/inside.txt', [ 'storage_mtime' => $baseTime, 'mtime' => $baseTime, @@ -790,6 +801,9 @@ public function testRecentFolder() { $cache = $storage->getCache(); + $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $cache->insert('bar', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $cache->insert('bar/foo', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $id1 = $cache->put('bar/foo/folder', [ 'storage_mtime' => $baseTime, 'mtime' => $baseTime, @@ -857,6 +871,8 @@ public function testRecentJail() { $cache = $storage->getCache(); + $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $cache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $id1 = $cache->put('folder/inside.txt', [ 'storage_mtime' => $baseTime, 'mtime' => $baseTime, @@ -864,6 +880,7 @@ public function testRecentJail() { 'size' => 3, 'permissions' => \OCP\Constants::PERMISSION_ALL, ]); + $cache->put('outside.txt', [ 'storage_mtime' => $baseTime - 100, 'mtime' => $baseTime - 100, @@ -961,14 +978,19 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $subStorage2->method('getCache') ->willReturn($subCache2); + + $cache->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $cache->insert('foo', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo/foo1', ['size' => 200, 'mtime' => 10, 'mimetype' => 'text/plain']); $cache->insert('foo/foo2', ['size' => 200, 'mtime' => 20, 'mimetype' => 'text/plain']); $cache->insert('foo/foo3', ['size' => 200, 'mtime' => 30, 'mimetype' => 'text/plain']); $cache->insert('foo/foo4', ['size' => 200, 'mtime' => 40, 'mimetype' => 'text/plain']); + $subCache1->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $subCache1->insert('foo5', ['size' => 300, 'mtime' => 15, 'mimetype' => 'text/plain']); $subCache1->insert('foo6', ['size' => 300, 'mtime' => 50, 'mimetype' => 'text/plain']); + $subCache2->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $subCache2->insert('foo7', ['size' => 200, 'mtime' => 5, 'mimetype' => 'text/plain']); $subCache2->insert('foo8', ['size' => 200, 'mtime' => 60, 'mimetype' => 'text/plain']); @@ -982,7 +1004,11 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $node = new Folder($root, $view, '/bar/foo'); $comparison = new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%foo%'); - $query = new SearchQuery($comparison, $limit, $offset, $ordering); + $operator = new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [ + $comparison, + new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE)]), + ]); + $query = new SearchQuery($operator, $limit, $offset, $ordering); $result = $node->search($query); $cache->clear(); $subCache1->clear(); diff --git a/tests/lib/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php index fbccd393fd0a4..f040a7aa1b287 100644 --- a/tests/lib/Repair/RepairMimeTypesTest.php +++ b/tests/lib/Repair/RepairMimeTypesTest.php @@ -47,6 +47,7 @@ protected function setUp(): void { ->willReturn('11.0.0.0'); $this->storage = new \OC\Files\Storage\Temporary([]); + $this->storage->getScanner()->scan(''); $this->repair = new \OC\Repair\RepairMimeTypes($config, \OC::$server->getDatabaseConnection()); } From 8a156768a540e15a9a6c98caa068b654926849da Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 14:48:20 +0200 Subject: [PATCH 10/17] test: fix service overwrite in PartFileInRootUploadTest Signed-off-by: Robin Appelman --- .../Connector/Sabre/RequestTest/PartFileInRootUploadTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php index 200008bcfce14..11a44f26942cb 100644 --- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php @@ -7,6 +7,7 @@ */ namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest; +use OC\AllConfig; use OCP\IConfig; /** @@ -31,7 +32,7 @@ protected function setUp(): void { return $config->getSystemValue($key, $default); } }); - $this->overwriteService('AllConfig', $mockConfig); + $this->overwriteService(AllConfig::class, $mockConfig); parent::setUp(); } From bf480bbde9a0c184fab9dfbae407a648311d562f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 15:02:52 +0200 Subject: [PATCH 11/17] test: fix ShareAPIControllerTest.php Signed-off-by: Robin Appelman --- .../Controller/ShareAPIControllerTest.php | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 85dfb9145cf08..de820583d4810 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -534,6 +534,8 @@ public function dataGetShare() { $parentFolder = $this->getMockBuilder(Folder::class)->getMock(); $parentFolder->method('getId')->willReturn(3); + $mountPoint = $this->createMock(IMountPoint::class); + $mountPoint->method('getMountType')->willReturn(''); $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $file->method('getId')->willReturn(1); @@ -543,6 +545,7 @@ public function dataGetShare() { $file->method('getSize')->willReturn(123465); $file->method('getMTime')->willReturn(1234567890); $file->method('getMimeType')->willReturn('myMimeType'); + $file->method('getMountPoint')->willReturn($mountPoint); $folder = $this->getMockBuilder(Folder::class)->getMock(); $folder->method('getId')->willReturn(2); @@ -552,6 +555,7 @@ public function dataGetShare() { $folder->method('getSize')->willReturn(123465); $folder->method('getMTime')->willReturn(1234567890); $folder->method('getMimeType')->willReturn('myFolderMimeType'); + $folder->method('getMountPoint')->willReturn($mountPoint); [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes(); @@ -607,6 +611,9 @@ public function dataGetShare() { 'item_size' => 123465, 'item_mtime' => 1234567890, 'attributes' => null, + 'item_permissions' => 4, + 'is-mount-root' => false, + 'mount-type' => '', ]; $data[] = [$share, $expected]; @@ -661,6 +668,9 @@ public function dataGetShare() { 'item_size' => 123465, 'item_mtime' => 1234567890, 'attributes' => null, + 'item_permissions' => 4, + 'is-mount-root' => false, + 'mount-type' => '', ]; $data[] = [$share, $expected]; @@ -721,6 +731,9 @@ public function dataGetShare() { 'item_size' => 123465, 'item_mtime' => 1234567890, 'attributes' => null, + 'item_permissions' => 4, + 'is-mount-root' => false, + 'mount-type' => '', ]; $data[] = [$share, $expected]; @@ -3740,6 +3753,12 @@ public function dataFormatShare() { $folder->method('getMimeType')->willReturn('myFolderMimeType'); $fileWithPreview->method('getMimeType')->willReturn('mimeWithPreview'); + $mountPoint = $this->createMock(IMountPoint::class); + $mountPoint->method('getMountType')->willReturn(''); + $file->method('getMountPoint')->willReturn($mountPoint); + $folder->method('getMountPoint')->willReturn($mountPoint); + $fileWithPreview->method('getMountPoint')->willReturn($mountPoint); + $file->method('getPath')->willReturn('file'); $folder->method('getPath')->willReturn('folder'); $fileWithPreview->method('getPath')->willReturn('fileWithPreview'); @@ -3839,6 +3858,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => '[{"scope":"permissions","key":"download","value":true}]', + 'item_permissions' => 1, ], $share, [], false ]; // User backend up @@ -3880,6 +3900,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => '[{"scope":"permissions","key":"download","value":true}]', + 'item_permissions' => 1, ], $share, [ ['owner', $owner], ['initiator', $initiator], @@ -3937,6 +3958,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -3990,6 +4012,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 11, ], $share, [], false ]; @@ -4044,6 +4067,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4095,6 +4119,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4153,6 +4178,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4211,6 +4237,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4263,6 +4290,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4315,6 +4343,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4370,6 +4399,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4422,6 +4452,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4474,6 +4505,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4543,6 +4575,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4598,6 +4631,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, [], false ]; @@ -4651,6 +4685,7 @@ public function dataFormatShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 11, ], $share, [], false ]; @@ -4815,6 +4850,7 @@ public function dataFormatRoomShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 1, ], $share, false, [] ]; @@ -4866,6 +4902,7 @@ public function dataFormatRoomShare() { 'is-mount-root' => false, 'mount-type' => '', 'attributes' => null, + 'item_permissions' => 9, ], $share, true, [ 'share_with_displayname' => 'recipientRoomName' ] @@ -4905,11 +4942,14 @@ public function testFormatRoomShare(array $expects, \OCP\Share\IShare $share, bo ->willReturn(true); $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') - ->setMethods(['formatShare']) + ->setMethods(['formatShare', 'canAccessShare']) ->getMock(); $helper->method('formatShare') ->with($share) ->willReturn($formatShareByHelper); + $helper->method('canAccessShare') + ->with($share) + ->willReturn(true); $this->serverContainer->method('get') ->with('\OCA\Talk\Share\Helper\ShareAPIController') From d2d475a7490c13c499eca04b970afc0d7d43ec8d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 15:44:12 +0200 Subject: [PATCH 12/17] test: fix trashbin StorageTest Signed-off-by: Robin Appelman --- apps/files_trashbin/tests/StorageTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 18fe59f7f7d84..70a40d10d3f46 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -591,6 +591,7 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab $event->expects($this->any())->method('shouldMoveToTrashBin')->willReturn(!$appDisablesTrash); $userFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]); + $rootFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]); $rootFolder->expects($this->any())->method('getUserFolder')->willReturn($userFolder); $storage = $this->getMockBuilder(Storage::class) From 25449de27b08504616e5d9e719c9f40c3aead310 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 18 Sep 2024 15:45:20 +0200 Subject: [PATCH 13/17] test: fix ShareControllerTest.php Signed-off-by: Robin Appelman --- apps/files_sharing/tests/Controller/ShareControllerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php index 79b90d8a15682..d2e6471eafa42 100644 --- a/apps/files_sharing/tests/Controller/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -353,7 +353,8 @@ public function testShowShare() { 'note' => $note, 'hideDownload' => false, 'showgridview' => false, - 'label' => '' + 'label' => '', + 'filename' => $filename, ]; $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); From 8bff8d22e2aa131a339e643217aaedfaf726c336 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Wed, 18 Sep 2024 17:09:49 +0200 Subject: [PATCH 14/17] fix: Override start method of \Sabre\DAV\Server to remove exception output Signed-off-by: Louis Chemineau --- apps/dav/lib/Connector/Sabre/Server.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/apps/dav/lib/Connector/Sabre/Server.php b/apps/dav/lib/Connector/Sabre/Server.php index b7ca8a0a1c0fe..610c79d56613e 100644 --- a/apps/dav/lib/Connector/Sabre/Server.php +++ b/apps/dav/lib/Connector/Sabre/Server.php @@ -25,4 +25,27 @@ public function __construct($treeOrNode = null) { self::$exposeVersion = false; $this->enablePropfindDepthInfinity = true; } + + // Copied from 3rdparty/sabre/dav/lib/DAV/Server.php + // Should be them exact same without the exception output. + public function start(): void { + try { + // If nginx (pre-1.2) is used as a proxy server, and SabreDAV as an + // origin, we must make sure we send back HTTP/1.0 if this was + // requested. + // This is mainly because nginx doesn't support Chunked Transfer + // Encoding, and this forces the webserver SabreDAV is running on, + // to buffer entire responses to calculate Content-Length. + $this->httpResponse->setHTTPVersion($this->httpRequest->getHTTPVersion()); + + // Setting the base url + $this->httpRequest->setBaseUrl($this->getBaseUri()); + $this->invokeMethod($this->httpRequest, $this->httpResponse); + } catch (\Throwable $e) { + try { + $this->emit('exception', [$e]); + } catch (\Exception $ignore) { + } + } + } } From b44ac8238d941b92b9b8499ed537d67023f4ec78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 17 Sep 2024 17:48:01 +0200 Subject: [PATCH 15/17] fix(tests): Remove deprecated tests for ServerTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/lib/ServerTest.php | 120 +++------------------------------------ 1 file changed, 7 insertions(+), 113 deletions(-) diff --git a/tests/lib/ServerTest.php b/tests/lib/ServerTest.php index e43c10b9cde6d..609f19c6f7e39 100644 --- a/tests/lib/ServerTest.php +++ b/tests/lib/ServerTest.php @@ -8,7 +8,6 @@ namespace Test; use OC\App\AppStore\Fetcher\AppFetcher; -use OC\App\AppStore\Fetcher\CategoryFetcher; use OCP\Comments\ICommentsManager; /** @@ -31,118 +30,13 @@ protected function setUp(): void { public function dataTestQuery() { return [ - ['ActivityManager', '\OC\Activity\Manager'], - ['ActivityManager', '\OCP\Activity\IManager'], - ['AllConfig', '\OC\AllConfig'], - ['AllConfig', '\OCP\IConfig'], - ['AppConfig', '\OC\AppConfig'], - ['AppConfig', '\OCP\IAppConfig'], - ['AppFetcher', AppFetcher::class], - ['AppManager', '\OC\App\AppManager'], - ['AppManager', '\OCP\App\IAppManager'], - ['AsyncCommandBus', '\OC\Command\AsyncBus'], - ['AsyncCommandBus', '\OCP\Command\IBus'], - ['AvatarManager', '\OC\Avatar\AvatarManager'], - ['AvatarManager', '\OCP\IAvatarManager'], - - ['CategoryFetcher', CategoryFetcher::class], - ['CapabilitiesManager', '\OC\CapabilitiesManager'], - ['ContactsManager', '\OC\ContactsManager'], - ['ContactsManager', '\OCP\Contacts\IManager'], - ['ContentSecurityPolicyManager', '\OC\Security\CSP\ContentSecurityPolicyManager'], - ['CommentsManager', '\OCP\Comments\ICommentsManager'], - ['Crypto', '\OC\Security\Crypto'], - ['Crypto', '\OCP\Security\ICrypto'], - ['CryptoWrapper', '\OC\Session\CryptoWrapper'], - ['CsrfTokenManager', '\OC\Security\CSRF\CsrfTokenManager'], - - ['DatabaseConnection', '\OC\DB\ConnectionAdapter'], - ['DatabaseConnection', '\OCP\IDBConnection'], - ['DateTimeFormatter', '\OC\DateTimeFormatter'], - ['DateTimeFormatter', '\OCP\IDateTimeFormatter'], - ['DateTimeZone', '\OC\DateTimeZone'], - ['DateTimeZone', '\OCP\IDateTimeZone'], - - ['EncryptionFileHelper', '\OC\Encryption\File'], - ['EncryptionFileHelper', '\OCP\Encryption\IFile'], - ['EncryptionKeyStorage', '\OC\Encryption\Keys\Storage'], - ['EncryptionKeyStorage', '\OCP\Encryption\Keys\IStorage'], - ['EncryptionManager', '\OC\Encryption\Manager'], - ['EncryptionManager', '\OCP\Encryption\IManager'], - ['EventLogger', '\OCP\Diagnostics\IEventLogger'], - - ['GroupManager', '\OC\Group\Manager'], - ['GroupManager', '\OCP\IGroupManager'], - - ['Hasher', '\OC\Security\Hasher'], - ['Hasher', '\OCP\Security\IHasher'], - ['HttpClientService', '\OC\Http\Client\ClientService'], - ['HttpClientService', '\OCP\Http\Client\IClientService'], - - ['IniWrapper', '\bantu\IniGetWrapper\IniGetWrapper'], - ['MimeTypeDetector', '\OCP\Files\IMimeTypeDetector'], - ['MimeTypeDetector', '\OC\Files\Type\Detection'], - - ['JobList', '\OC\BackgroundJob\JobList'], - ['JobList', '\OCP\BackgroundJob\IJobList'], - - ['L10NFactory', '\OC\L10N\Factory'], - ['L10NFactory', '\OCP\L10N\IFactory'], - ['LockingProvider', '\OCP\Lock\ILockingProvider'], - ['Logger', '\OC\Log'], - ['Logger', '\OCP\ILogger'], - - ['Mailer', '\OC\Mail\Mailer'], - ['Mailer', '\OCP\Mail\IMailer'], - ['MemCacheFactory', '\OC\Memcache\Factory'], - ['MemCacheFactory', '\OCP\ICacheFactory'], - ['MountConfigManager', '\OC\Files\Config\MountProviderCollection'], - ['MountConfigManager', '\OCP\Files\Config\IMountProviderCollection'], - - ['NavigationManager', '\OC\NavigationManager'], - ['NavigationManager', '\OCP\INavigationManager'], - ['NotificationManager', '\OC\Notification\Manager'], - ['NotificationManager', '\OCP\Notification\IManager'], - ['UserCache', '\OC\Cache\File'], - ['UserCache', '\OCP\ICache'], - - ['PreviewManager', '\OC\PreviewManager'], - ['PreviewManager', '\OCP\IPreview'], - - ['QueryLogger', '\OCP\Diagnostics\IQueryLogger'], - - ['Request', '\OC\AppFramework\Http\Request'], - ['Request', '\OCP\IRequest'], - ['RootFolder', '\OC\Files\Node\Root'], - ['RootFolder', '\OC\Files\Node\Folder'], - ['RootFolder', '\OCP\Files\IRootFolder'], - ['RootFolder', '\OCP\Files\Folder'], - ['Router', '\OCP\Route\IRouter'], - - ['SecureRandom', '\OC\Security\SecureRandom'], - ['SecureRandom', '\OCP\Security\ISecureRandom'], - ['ShareManager', '\OC\Share20\Manager'], - ['ShareManager', '\OCP\Share\IManager'], - ['SystemConfig', '\OC\SystemConfig'], - - ['URLGenerator', '\OC\URLGenerator'], - ['URLGenerator', '\OCP\IURLGenerator'], - ['UserManager', '\OC\User\Manager'], - ['UserManager', '\OCP\IUserManager'], - ['UserSession', '\OC\User\Session'], - ['UserSession', '\OCP\IUserSession'], - - ['TagMapper', '\OC\Tagging\TagMapper'], - ['TagMapper', '\OCP\AppFramework\Db\QBMapper'], - ['TagManager', '\OC\TagManager'], - ['TagManager', '\OCP\ITagManager'], - ['TempManager', '\OC\TempManager'], - ['TempManager', '\OCP\ITempManager'], - ['ThemingDefaults', '\OCA\Theming\ThemingDefaults'], - ['TrustedDomainHelper', '\OC\Security\TrustedDomainHelper'], - - ['SystemTagManager', '\OCP\SystemTag\ISystemTagManager'], - ['SystemTagObjectMapper', '\OCP\SystemTag\ISystemTagObjectMapper'], + ['\OCP\Activity\IManager', '\OC\Activity\Manager'], + ['\OCP\IConfig', '\OC\AllConfig'], + ['\OCP\IAppConfig', '\OC\AppConfig'], + [AppFetcher::class, AppFetcher::class], + ['\OCP\App\IAppManager', '\OC\App\AppManager'], + ['\OCP\Command\IBus', '\OC\Command\AsyncBus'], + ['\OCP\IAvatarManager', '\OC\Avatar\AvatarManager'], ]; } From 61da34520360d3ddaaa97dcd44f4169213bf1d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 17 Sep 2024 19:19:08 +0200 Subject: [PATCH 16/17] fix(tests): Fix Folder tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/lib/Files/Node/FolderTest.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index c0c14128d6f50..9a3433c020e5e 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -356,6 +356,8 @@ public function testSearchInRoot() { $storage->method('getCache') ->willReturn($cache); + $storage->method('getOwner') + ->willReturn('owner'); $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('files', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); @@ -395,6 +397,8 @@ public function testSearchInStorageRoot() { $storage->method('getCache') ->willReturn($cache); + $storage->method('getOwner') + ->willReturn('owner'); $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); @@ -447,9 +451,13 @@ public function testSearchSubStorages() { $storage->method('getCache') ->willReturn($cache); + $storage->method('getOwner') + ->willReturn('owner'); $subStorage->method('getCache') ->willReturn($subCache); + $subStorage->method('getOwner') + ->willReturn('owner'); $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); $cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); @@ -503,6 +511,8 @@ public function testGetById() { $storage->method('getCache') ->willReturn($cache); + $storage->method('getOwner') + ->willReturn('owner'); $this->userMountCache->expects($this->any()) ->method('getMountsForFileId') @@ -550,6 +560,8 @@ public function testGetByIdMountRoot() { $storage->method('getCache') ->willReturn($cache); + $storage->method('getOwner') + ->willReturn('owner'); $this->userMountCache->expects($this->any()) ->method('getMountsForFileId') @@ -593,6 +605,8 @@ public function testGetByIdOutsideFolder() { $storage->method('getCache') ->willReturn($cache); + $storage->method('getOwner') + ->willReturn('owner'); $this->userMountCache->expects($this->any()) ->method('getMountsForFileId') @@ -636,6 +650,8 @@ public function testGetByIdMultipleStorages() { $storage->method('getCache') ->willReturn($cache); + $storage->method('getOwner') + ->willReturn('owner'); $this->userMountCache->method('getMountsForFileId') ->with(1) @@ -651,9 +667,6 @@ public function testGetByIdMultipleStorages() { ), ]); - $storage->method('getCache') - ->willReturn($cache); - $cache->method('get') ->with(1) ->willReturn($fileInfo); @@ -965,9 +978,13 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $storage->method('getCache') ->willReturn($cache); + $storage->method('getOwner') + ->willReturn('owner'); $subStorage1->method('getCache') ->willReturn($subCache1); + $subStorage1->method('getOwner') + ->willReturn('owner'); $subMount2->method('getStorage') ->willReturn($subStorage2); @@ -977,6 +994,8 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $subStorage2->method('getCache') ->willReturn($subCache2); + $subStorage2->method('getOwner') + ->willReturn('owner'); $cache->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); From 767af5485e4b3a5bafae2b060ced3cfe2392a6ba Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Wed, 18 Sep 2024 09:23:19 +0200 Subject: [PATCH 17/17] fix: Prevent duplicate creation of print_exception function Signed-off-by: Louis Chemineau --- core/templates/exception.php | 15 +-------------- core/templates/print_exception.php | 21 +++++++++++++++++++++ core/templates/print_xml_exception.php | 16 ++++++++++++++++ core/templates/xml_exception.php | 10 +--------- 4 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 core/templates/print_exception.php create mode 100644 core/templates/print_xml_exception.php diff --git a/core/templates/exception.php b/core/templates/exception.php index 5c907038ba2e4..44f9908c57cc6 100644 --- a/core/templates/exception.php +++ b/core/templates/exception.php @@ -9,20 +9,7 @@ style('core', ['styles', 'header', 'exception']); -function print_exception(Throwable $e, \OCP\IL10N $l): void { - print_unescaped('
');
-	p($e->getTraceAsString());
-	print_unescaped('
'); - - if ($e->getPrevious() !== null) { - print_unescaped('
'); - print_unescaped('

'); - p($l->t('Previous')); - print_unescaped('

'); - - print_exception($e->getPrevious(), $l); - } -} +require_once __DIR__ . '/print_exception.php'; ?>
diff --git a/core/templates/print_exception.php b/core/templates/print_exception.php new file mode 100644 index 0000000000000..2def6d4e9d904 --- /dev/null +++ b/core/templates/print_exception.php @@ -0,0 +1,21 @@ +'); + p($e->getTraceAsString()); + print_unescaped(''); + + if ($e->getPrevious() !== null) { + print_unescaped('
'); + print_unescaped('

'); + p($l->t('Previous')); + print_unescaped('

'); + + print_exception($e->getPrevious(), $l); + } +} diff --git a/core/templates/print_xml_exception.php b/core/templates/print_xml_exception.php new file mode 100644 index 0000000000000..94452d8ae9d3f --- /dev/null +++ b/core/templates/print_xml_exception.php @@ -0,0 +1,16 @@ +getTraceAsString()); + + if ($e->getPrevious() !== null) { + print_unescaped(''); + print_exception($e->getPrevious(), $l); + print_unescaped(''); + } +} diff --git a/core/templates/xml_exception.php b/core/templates/xml_exception.php index 342238d824bb7..ba808c88595c2 100644 --- a/core/templates/xml_exception.php +++ b/core/templates/xml_exception.php @@ -5,15 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -function print_exception(Throwable $e, \OCP\IL10N $l): void { - p($e->getTraceAsString()); - - if ($e->getPrevious() !== null) { - print_unescaped(''); - print_exception($e->getPrevious(), $l); - print_unescaped(''); - } -} +require_once __DIR__ . '/print_xml_exception.php'; print_unescaped('' . "\n"); ?>