Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-03-15 19:45:30 +0300
committerGitHub <noreply@github.com>2021-03-15 19:45:30 +0300
commite559afb8d409f75fdf9a216428d858d08aa1ee03 (patch)
treeafea41e1f4cf5f9f25070e819ef9637267c63ec0 /tests/lib/Files
parentf512705f8f3ba7ff676b139bbfc00dcf6d277bd1 (diff)
parent6ecf33bfe7ef719cd979de5b29fc1da02e255632 (diff)
Merge pull request #25136 from nextcloud/cachejail-search-filter
do cachejail search filtering in sql
Diffstat (limited to 'tests/lib/Files')
-rw-r--r--tests/lib/Files/Cache/Wrapper/CacheJailTest.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
index f0943ba5a03..d9f7af1f034 100644
--- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
+++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
@@ -9,6 +9,11 @@
namespace Test\Files\Cache\Wrapper;
use OC\Files\Cache\Wrapper\CacheJail;
+use OC\Files\Search\SearchComparison;
+use OC\Files\Search\SearchQuery;
+use OC\User\User;
+use OCP\Files\Search\ISearchComparison;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\Files\Cache\CacheTest;
/**
@@ -32,6 +37,7 @@ class CacheJailTest extends CacheTest {
}
public function testSearchOutsideJail() {
+ $this->storage->getScanner()->scan('');
$file1 = 'foo/foobar';
$file2 = 'folder/foobar';
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
@@ -44,6 +50,52 @@ class CacheJailTest extends CacheTest {
$result = $this->cache->search('%foobar%');
$this->assertCount(1, $result);
$this->assertEquals('foobar', $result[0]['path']);
+
+ $result = $this->cache->search('%foo%');
+ $this->assertCount(2, $result);
+ usort($result, function ($a, $b) {
+ return $a['path'] <=> $b['path'];
+ });
+ $this->assertEquals('', $result[0]['path']);
+ $this->assertEquals('foobar', $result[1]['path']);
+ }
+
+ public function testSearchMimeOutsideJail() {
+ $this->storage->getScanner()->scan('');
+ $file1 = 'foo/foobar';
+ $file2 = 'folder/foobar';
+ $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
+
+ $this->sourceCache->put($file1, $data1);
+ $this->sourceCache->put($file2, $data1);
+
+ $this->assertCount(2, $this->sourceCache->searchByMime('foo/folder'));
+
+ $result = $this->cache->search('%foobar%');
+ $this->assertCount(1, $result);
+ $this->assertEquals('foobar', $result[0]['path']);
+ }
+
+ public function testSearchQueryOutsideJail() {
+ $this->storage->getScanner()->scan('');
+ $file1 = 'foo/foobar';
+ $file2 = 'folder/foobar';
+ $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
+
+ $this->sourceCache->put($file1, $data1);
+ $this->sourceCache->put($file2, $data1);
+
+ $user = new User('foo', null, $this->createMock(EventDispatcherInterface::class));
+ $query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foobar'), 10, 0, [], $user);
+ $result = $this->cache->searchQuery($query);
+
+ $this->assertCount(1, $result);
+ $this->assertEquals('foobar', $result[0]['path']);
+
+ $query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foo'), 10, 0, [], $user);
+ $result = $this->cache->searchQuery($query);
+ $this->assertCount(1, $result);
+ $this->assertEquals('', $result[0]['path']);
}
public function testClearKeepEntriesOutsideJail() {
@@ -130,4 +182,22 @@ class CacheJailTest extends CacheTest {
$this->assertTrue($this->sourceCache->inCache('target/foo'));
$this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
}
+
+ public function testSearchNested() {
+ $this->storage->getScanner()->scan('');
+ $file1 = 'foo';
+ $file2 = 'foo/bar';
+ $file3 = 'foo/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');
+
+ $result = $nested->search('%asd%');
+ $this->assertCount(1, $result);
+ $this->assertEquals('asd', $result[0]['path']);
+ }
}