Merge pull request #9668 from nextcloud/backport/9666/stable13
[stable13] Make sure the file is readable before attempting to create a preview
This commit is contained in:
commit
3acfcc433a
|
@ -89,6 +89,12 @@ class Generator {
|
||||||
* @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
|
* @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
|
||||||
*/
|
*/
|
||||||
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
|
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
|
||||||
|
//Make sure that we can read the file
|
||||||
|
if (!$file->isReadable()) {
|
||||||
|
throw new NotFoundException('Cannot read file');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->eventDispatcher->dispatch(
|
$this->eventDispatcher->dispatch(
|
||||||
IPreview::EVENT,
|
IPreview::EVENT,
|
||||||
new GenericEvent($file,[
|
new GenericEvent($file,[
|
||||||
|
|
|
@ -76,6 +76,8 @@ class GeneratorTest extends \Test\TestCase {
|
||||||
|
|
||||||
public function testGetCachedPreview() {
|
public function testGetCachedPreview() {
|
||||||
$file = $this->createMock(File::class);
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('isReadable')
|
||||||
|
->willReturn(true);
|
||||||
$file->method('getMimeType')
|
$file->method('getMimeType')
|
||||||
->willReturn('myMimeType');
|
->willReturn('myMimeType');
|
||||||
$file->method('getId')
|
$file->method('getId')
|
||||||
|
@ -122,6 +124,8 @@ class GeneratorTest extends \Test\TestCase {
|
||||||
|
|
||||||
public function testGetNewPreview() {
|
public function testGetNewPreview() {
|
||||||
$file = $this->createMock(File::class);
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('isReadable')
|
||||||
|
->willReturn(true);
|
||||||
$file->method('getMimeType')
|
$file->method('getMimeType')
|
||||||
->willReturn('myMimeType');
|
->willReturn('myMimeType');
|
||||||
$file->method('getId')
|
$file->method('getId')
|
||||||
|
@ -248,6 +252,8 @@ class GeneratorTest extends \Test\TestCase {
|
||||||
$this->expectException(NotFoundException::class);
|
$this->expectException(NotFoundException::class);
|
||||||
|
|
||||||
$file = $this->createMock(File::class);
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('isReadable')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
$this->previewManager->method('isMimeSupported')
|
$this->previewManager->method('isMimeSupported')
|
||||||
->with('invalidType')
|
->with('invalidType')
|
||||||
|
@ -271,6 +277,8 @@ class GeneratorTest extends \Test\TestCase {
|
||||||
|
|
||||||
public function testNoProvider() {
|
public function testNoProvider() {
|
||||||
$file = $this->createMock(File::class);
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('isReadable')
|
||||||
|
->willReturn(true);
|
||||||
$file->method('getMimeType')
|
$file->method('getMimeType')
|
||||||
->willReturn('myMimeType');
|
->willReturn('myMimeType');
|
||||||
$file->method('getId')
|
$file->method('getId')
|
||||||
|
@ -350,6 +358,8 @@ class GeneratorTest extends \Test\TestCase {
|
||||||
*/
|
*/
|
||||||
public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expectedX, $expectedY) {
|
public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expectedX, $expectedY) {
|
||||||
$file = $this->createMock(File::class);
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('isReadable')
|
||||||
|
->willReturn(true);
|
||||||
$file->method('getMimeType')
|
$file->method('getMimeType')
|
||||||
->willReturn('myMimeType');
|
->willReturn('myMimeType');
|
||||||
$file->method('getId')
|
$file->method('getId')
|
||||||
|
@ -416,4 +426,14 @@ class GeneratorTest extends \Test\TestCase {
|
||||||
$this->assertSame($preview, $result);
|
$this->assertSame($preview, $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUnreadbleFile() {
|
||||||
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('isReadable')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$this->expectException(NotFoundException::class);
|
||||||
|
|
||||||
|
$this->generator->getPreview($file, 100, 100, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue