Merge pull request #28175 from nextcloud/jail-search-root

This commit is contained in:
Julius Härtl 2021-07-29 09:27:53 +02:00 committed by GitHub
commit db7ffb0bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 11 deletions

View file

@ -306,17 +306,21 @@ class CacheJail extends CacheWrapper {
}
public function getQueryFilterForStorage(): ISearchOperator {
return new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND,
[
$this->getCache()->getQueryFilterForStorage(),
new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR,
[
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()),
new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $this->getGetUnjailedRoot() . '/%'),
],
)
]
);
if ($this->root !== '' && $this->root !== '/') {
return new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND,
[
$this->getCache()->getQueryFilterForStorage(),
new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR,
[
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()),
new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $this->getGetUnjailedRoot() . '/%'),
],
)
]
);
} else {
return $this->getCache()->getQueryFilterForStorage();
}
}
public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {

View file

@ -200,4 +200,22 @@ class CacheJailTest extends CacheTest {
$this->assertCount(1, $result);
$this->assertEquals('asd', $result[0]['path']);
}
public function testRootJail() {
$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->sourceCache, '');
$result = $nested->search('%asd%');
$this->assertCount(1, $result);
$this->assertEquals('foo/bar/asd', $result[0]['path']);
}
}