mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
Merge pull request #46672 from nextcloud/fix/preview-invalid-id
Avoid using partial file info as valid one
This commit is contained in:
commit
4f2a29adf9
5 changed files with 25 additions and 3 deletions
|
|
@ -93,6 +93,10 @@ class ApiController extends Controller {
|
|||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if ($file->getId() <= 0) {
|
||||
return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
/** @var File $file */
|
||||
$preview = $this->previewManager->getPreview($file, $x, $y, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ class ApiControllerTest extends TestCase {
|
|||
|
||||
public function testGetThumbnailInvalidImage() {
|
||||
$file = $this->createMock(File::class);
|
||||
$file->method('getId')->willReturn(123);
|
||||
$this->userFolder->method('get')
|
||||
->with($this->equalTo('unknown.jpg'))
|
||||
->willReturn($file);
|
||||
|
|
@ -168,8 +169,19 @@ class ApiControllerTest extends TestCase {
|
|||
$this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg'));
|
||||
}
|
||||
|
||||
public function testGetThumbnailInvalidPartFile() {
|
||||
$file = $this->createMock(File::class);
|
||||
$file->method('getId')->willReturn(0);
|
||||
$this->userFolder->method('get')
|
||||
->with($this->equalTo('unknown.jpg'))
|
||||
->willReturn($file);
|
||||
$expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
|
||||
$this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg'));
|
||||
}
|
||||
|
||||
public function testGetThumbnail() {
|
||||
$file = $this->createMock(File::class);
|
||||
$file->method('getId')->willReturn(123);
|
||||
$this->userFolder->method('get')
|
||||
->with($this->equalTo('known.jpg'))
|
||||
->willReturn($file);
|
||||
|
|
|
|||
|
|
@ -141,6 +141,10 @@ class PreviewController extends Controller {
|
|||
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
if ($node->getId() <= 0) {
|
||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
$storage = $node->getStorage();
|
||||
if ($storage->instanceOfStorage(SharedStorage::class)) {
|
||||
/** @var SharedStorage $storage */
|
||||
|
|
|
|||
|
|
@ -1338,9 +1338,6 @@ class View {
|
|||
if (!Filesystem::isValidPath($path)) {
|
||||
return false;
|
||||
}
|
||||
if (Cache\Scanner::isPartialFile($path)) {
|
||||
return $this->getPartFileInfo($path);
|
||||
}
|
||||
$relativePath = $path;
|
||||
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
|
||||
|
||||
|
|
@ -1351,6 +1348,10 @@ class View {
|
|||
$data = $this->getCacheEntry($storage, $internalPath, $relativePath);
|
||||
|
||||
if (!$data instanceof ICacheEntry) {
|
||||
if (Cache\Scanner::isPartialFile($relativePath)) {
|
||||
return $this->getPartFileInfo($relativePath);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ class PreviewControllerTest extends \Test\TestCase {
|
|||
->willReturn($userFolder);
|
||||
|
||||
$file = $this->createMock(File::class);
|
||||
$file->method('getId')->willReturn(123);
|
||||
$userFolder->method('get')
|
||||
->with($this->equalTo('file'))
|
||||
->willReturn($file);
|
||||
|
|
|
|||
Loading…
Reference in a new issue