summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2018-05-30 13:25:24 +0200
committerGitHub <noreply@github.com>2018-05-30 13:25:24 +0200
commit619b0eece10c200d71c892efcce998ed8605731f (patch)
treef41a7625abaf57caedc85eebd49f6db36d5fd7e5
parent50f6015821bfef676d90e0fd09799c8576d64f10 (diff)
parent14acded1713c3e0546f1aad7b0d58b0f3a5bd1d7 (diff)
downloadnextcloud-server-619b0eece10c200d71c892efcce998ed8605731f.tar.gz
nextcloud-server-619b0eece10c200d71c892efcce998ed8605731f.zip
Merge pull request #9666 from nextcloud/enhancement/noid/preview_check_file_readbale
Make sure the file is readable before attempting to create a preview
-rw-r--r--lib/private/Preview/Generator.php6
-rw-r--r--tests/lib/Preview/GeneratorTest.php20
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 08f6b604eca..3e81004c8aa 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -89,6 +89,12 @@ class Generator {
* @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) {
+ //Make sure that we can read the file
+ if (!$file->isReadable()) {
+ throw new NotFoundException('Cannot read file');
+ }
+
+
$this->eventDispatcher->dispatch(
IPreview::EVENT,
new GenericEvent($file,[
diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php
index 130cccdf09e..b6200b1829b 100644
--- a/tests/lib/Preview/GeneratorTest.php
+++ b/tests/lib/Preview/GeneratorTest.php
@@ -76,6 +76,8 @@ class GeneratorTest extends \Test\TestCase {
public function testGetCachedPreview() {
$file = $this->createMock(File::class);
+ $file->method('isReadable')
+ ->willReturn(true);
$file->method('getMimeType')
->willReturn('myMimeType');
$file->method('getId')
@@ -122,6 +124,8 @@ class GeneratorTest extends \Test\TestCase {
public function testGetNewPreview() {
$file = $this->createMock(File::class);
+ $file->method('isReadable')
+ ->willReturn(true);
$file->method('getMimeType')
->willReturn('myMimeType');
$file->method('getId')
@@ -248,6 +252,8 @@ class GeneratorTest extends \Test\TestCase {
$this->expectException(NotFoundException::class);
$file = $this->createMock(File::class);
+ $file->method('isReadable')
+ ->willReturn(true);
$this->previewManager->method('isMimeSupported')
->with('invalidType')
@@ -271,6 +277,8 @@ class GeneratorTest extends \Test\TestCase {
public function testNoProvider() {
$file = $this->createMock(File::class);
+ $file->method('isReadable')
+ ->willReturn(true);
$file->method('getMimeType')
->willReturn('myMimeType');
$file->method('getId')
@@ -350,6 +358,8 @@ class GeneratorTest extends \Test\TestCase {
*/
public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expectedX, $expectedY) {
$file = $this->createMock(File::class);
+ $file->method('isReadable')
+ ->willReturn(true);
$file->method('getMimeType')
->willReturn('myMimeType');
$file->method('getId')
@@ -416,4 +426,14 @@ class GeneratorTest extends \Test\TestCase {
$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);
+ }
}