Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,10 @@ public function get($file) {
}

/**
* Create a CacheEntry from database row
*
* @param array $data
* @param IMimeTypeLoader $mimetypeLoader
* @return CacheEntry
* Helper method that creates a CacheEntry from a database row.
*/
public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) {
//fix types
public static function cacheEntryFromData(array $data, IMimeTypeLoader $mimetypeLoader): ICacheEntry {
// Fix types
$data['fileid'] = (int)$data['fileid'];
$data['parent'] = (int)$data['parent'];
$data['size'] = 0 + $data['size'];
Expand Down
27 changes: 21 additions & 6 deletions lib/private/Files/Cache/Wrapper/CacheJail.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ protected function getJailedPath(string $path, string $root = null) {
}

/**
* @param ICacheEntry|array $entry
* @return array
* @param ICacheEntry $entry
* @return ICacheEntry
*/
protected function formatCacheEntry($entry) {
if (isset($entry['path'])) {
Expand All @@ -118,7 +118,7 @@ protected function formatCacheEntry($entry) {
}

/**
* get the stored metadata of a file or folder
* Get the stored metadata of a file or folder
*
* @param string /int $file
* @return ICacheEntry|false
Expand Down Expand Up @@ -229,10 +229,25 @@ public function getStatus($file) {
}

private function formatSearchResults($results) {
return array_map(function ($entry) {
$finalResult = [];
foreach ($results as $entry) {
// Filter not accessible entries (e.g. some groupfolder entries when ACLs are enabled)
$cacheWrapper = $this;
while (($cacheWrapper instanceof CacheWrapper) && $entry !== false) {
if (!($cacheWrapper instanceof CacheJail)) { // We apply the jail at the end
$entry = $cacheWrapper->formatCacheEntry($entry);
}
$cacheWrapper = $cacheWrapper->getCache();
}
if ($entry === false) {
continue;
}

// Unjailed the path (remove __groupfolder/<id> prefix)
$entry['path'] = $this->getJailedPath($entry['path'], $this->getGetUnjailedRoot());
return $entry;
}, $results);
$finalResult[] = $entry;
}
return $finalResult;
}

/**
Expand Down
14 changes: 10 additions & 4 deletions lib/private/Files/Cache/Wrapper/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function getCache() {
}

/**
* Make it easy for wrappers to modify every returned cache entry
* Makes it easy for wrappers to modify every returned cache entry
*
* @param ICacheEntry $entry
* @return ICacheEntry
Expand Down Expand Up @@ -224,7 +224,9 @@ public function getStatus($file) {
*/
public function search($pattern) {
$results = $this->getCache()->search($pattern);
return array_map([$this, 'formatCacheEntry'], $results);
return array_filter(array_map([$this, 'formatCacheEntry'], $results), function ($entry) {
return $entry !== false;
});
}

/**
Expand All @@ -235,12 +237,16 @@ public function search($pattern) {
*/
public function searchByMime($mimetype) {
$results = $this->getCache()->searchByMime($mimetype);
return array_map([$this, 'formatCacheEntry'], $results);
return array_filter(array_map([$this, 'formatCacheEntry'], $results), function ($entry) {
return $entry !== false;
});
}

public function searchQuery(ISearchQuery $query) {
$results = $this->getCache()->searchQuery($query);
return array_map([$this, 'formatCacheEntry'], $results);
return array_filter(array_map([$this, 'formatCacheEntry'], $results), function ($entry) {
return $entry !== false;
});
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/lib/Files/Cache/Wrapper/CacheJailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Test\Files\Cache\Wrapper;

use OC\Files\Cache\Wrapper\CacheJail;
use OC\Files\Cache\Wrapper\CacheWrapper;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OC\User\User;
Expand Down Expand Up @@ -201,6 +202,29 @@ public function testSearchNested() {
$this->assertEquals('asd', $result[0]['path']);
}

public function testNotAuthorized() {
$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 class($this->cache) extends CacheWrapper {
protected function formatCacheEntry($entry) {
return false;
}
};

$nested = new \OC\Files\Cache\Wrapper\CacheJail($nested, 'bar');

$result = $nested->search('%asd%');
$this->assertCount(0, $result);
}

public function testRootJail() {
$this->storage->getScanner()->scan('');
$file1 = 'foo';
Expand Down