diff options
author | Simon L <szaimen@e.mail.de> | 2023-06-25 01:49:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-25 01:49:25 +0200 |
commit | 3f4b7649110f6555bc682d92e4e40d76a45b8283 (patch) | |
tree | ef41f884ae076de6794496768148cbd15e4f97e8 /apps | |
parent | 10d563a873b4c2d6d423f79140985335e2eb57a7 (diff) | |
parent | f21cbfff64bad26b7d80b8b8a1f918611dfa82c3 (diff) | |
download | nextcloud-server-3f4b7649110f6555bc682d92e4e40d76a45b8283.tar.gz nextcloud-server-3f4b7649110f6555bc682d92e4e40d76a45b8283.zip |
Merge pull request #38844 from nextcloud/enh/add-detected-mime-type-to-exception
feat: add detected mime type to exception
Diffstat (limited to 'apps')
-rw-r--r-- | apps/theming/lib/ImageManager.php | 2 | ||||
-rw-r--r-- | apps/theming/tests/ImageManagerTest.php | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index 87123a6f7c9..f609e5ef9d4 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -240,7 +240,7 @@ class ImageManager { $supportedFormats = $this->getSupportedUploadImageFormats($key); $detectedMimeType = mime_content_type($tmpFile); if (!in_array($detectedMimeType, $supportedFormats, true)) { - throw new \Exception('Unsupported image type'); + throw new \Exception('Unsupported image type: ' . $detectedMimeType); } if ($key === 'background' && $this->shouldOptimizeBackgroundImage($detectedMimeType, filesize($tmpFile))) { diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 22432a00103..e0e00615edb 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -390,4 +390,30 @@ class ImageManagerTest extends TestCase { $this->imageManager->updateImage($key, $tmpFile); } + + public function testUnsupportedImageType(): void { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unsupported image type: text/plain'); + + $file = $this->createMock(ISimpleFile::class); + $folder = $this->createMock(ISimpleFolder::class); + $oldFile = $this->createMock(ISimpleFile::class); + + $folder->expects($this->any()) + ->method('getFile') + ->willReturn($oldFile); + + $this->rootFolder + ->expects($this->any()) + ->method('getFolder') + ->with('images') + ->willReturn($folder); + + $folder->expects($this->once()) + ->method('newFile') + ->with('favicon') + ->willReturn($file); + + $this->imageManager->updateImage('favicon', __DIR__ . '/../../../tests/data/lorem.txt'); + } } |