aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Cache/Wrapper/CacheJailTest.php')
-rw-r--r--tests/lib/Files/Cache/Wrapper/CacheJailTest.php108
1 files changed, 63 insertions, 45 deletions
diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
index d0a6f99cb19..8ac3492fbd2 100644
--- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
+++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,12 +8,15 @@
namespace Test\Files\Cache\Wrapper;
+use OC\Files\Cache\Cache;
use OC\Files\Cache\Wrapper\CacheJail;
+use OC\Files\Cache\Wrapper\CacheWrapper;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
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;
@@ -25,23 +29,25 @@ use Test\Files\Cache\CacheTest;
*/
class CacheJailTest extends CacheTest {
/**
- * @var \OC\Files\Cache\Cache $sourceCache
+ * @var Cache $sourceCache
*/
protected $sourceCache;
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 CacheJail($this->sourceCache, 'jail');
+ $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
}
- public function testSearchOutsideJail() {
+ public function testSearchOutsideJail(): void {
$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 +58,20 @@ class CacheJailTest extends CacheTest {
$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() {
+ public function testSearchMimeOutsideJail(): void {
$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);
@@ -76,12 +82,14 @@ class CacheJailTest extends CacheTest {
$this->assertEquals('foobar', $result[0]['path']);
}
- public function testSearchQueryOutsideJail() {
+ public function testSearchQueryOutsideJail(): void {
$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 +100,19 @@ class CacheJailTest extends CacheTest {
$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';
+ public function testClearKeepEntriesOutsideJail(): void {
+ $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);
@@ -115,27 +123,27 @@ class CacheJailTest extends CacheTest {
$this->assertTrue($this->sourceCache->inCache('folder/foobar'));
}
- public function testGetById() {
- $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
- $id = $this->sourceCache->put('foo/bar', $data1);
+ public function testGetById(): void {
+ $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);
$this->assertEquals('bar', $path);
// path from jailed '' of foo/bar is foo/bar
- $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, '');
+ $this->cache = new CacheJail($this->sourceCache, '');
$path = $this->cache->getPathById($id);
- $this->assertEquals('foo/bar', $path);
+ $this->assertEquals('jail/bar', $path);
}
- public function testGetIncomplete() {
+ public function testGetIncomplete(): void {
//not supported
$this->addToAssertionCount(1);
}
- public function testMoveFromJail() {
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ public function testMoveFromJail(): void {
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
@@ -150,8 +158,8 @@ class CacheJailTest extends CacheTest {
$this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
}
- public function testMoveToJail() {
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ public function testMoveToJail(): void {
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
@@ -166,8 +174,8 @@ class CacheJailTest extends CacheTest {
$this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
}
- public function testMoveBetweenJail() {
- $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
+ public function testMoveBetweenJail(): void {
+ $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];
$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
@@ -183,46 +191,46 @@ class CacheJailTest extends CacheTest {
$this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
}
- public function testSearchNested() {
+ public function testSearchNested(): void {
$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);
$this->sourceCache->put($file2, $data1);
$this->sourceCache->put($file3, $data1);
- $nested = new \OC\Files\Cache\Wrapper\CacheJail($this->cache, 'bar');
+ $nested = new CacheJail($this->cache, 'bar');
$result = $nested->search('%asd%');
$this->assertCount(1, $result);
$this->assertEquals('asd', $result[0]['path']);
}
- public function testRootJail() {
+ public function testRootJail(): void {
$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);
$this->sourceCache->put($file2, $data1);
$this->sourceCache->put($file3, $data1);
- $nested = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, '');
+ $nested = new CacheJail($this->sourceCache, '');
$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() {
+ public function testWatcher(): void {
$storage = new Jail([
'storage' => $this->storage,
- 'root' => 'foo'
+ 'root' => 'jail'
]);
$storage->getScanner()->scan('');
$storage->file_put_contents('bar', 'asd');
@@ -232,10 +240,10 @@ class CacheJailTest extends CacheTest {
$this->assertTrue($this->cache->inCache('bar'));
}
- public function testWatcherAfterInnerWatcher() {
+ public function testWatcherAfterInnerWatcher(): void {
$storage = new Jail([
'storage' => $this->storage,
- 'root' => 'foo'
+ 'root' => 'jail'
]);
$storage->getScanner()->scan('');
$storage->file_put_contents('bar', 'asd');
@@ -247,4 +255,14 @@ class CacheJailTest extends CacheTest {
$storage->getWatcher()->update('bar', ['mimetype' => 'text/plain']);
$this->assertTrue($this->cache->inCache('bar'));
}
+
+ public function testUnJailedRoot(): void {
+ $jail1 = new CacheJail($this->sourceCache, 'foo');
+ $jail2 = new CacheJail($jail1, 'bar');
+ $this->assertEquals('foo/bar', $jail2->getGetUnjailedRoot());
+
+ $middleWrapper = new CacheWrapper($jail1);
+ $jail3 = new CacheJail($middleWrapper, 'bar');
+ $this->assertEquals('foo/bar', $jail3->getGetUnjailedRoot());
+ }
}