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
12 changes: 12 additions & 0 deletions apps/theming/lib/Controller/ThemingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* @package OCA\Theming\Controller
*/
class ThemingController extends Controller {
const VALID_UPLOAD_KEYS = ['logo', 'logoheader', 'background', 'favicon'];
/** @var ThemingDefaults */
private $themingDefaults;
/** @var IL10N */
Expand Down Expand Up @@ -215,6 +216,17 @@ private function isValidUrl(string $url): bool {
*/
public function uploadImage(): DataResponse {
$key = $this->request->getParam('key');
if (!in_array($key, self::VALID_UPLOAD_KEYS, true)) {
return new DataResponse(
[
'data' => [
'message' => 'Invalid key'
],
'status' => 'failure',
],
Http::STATUS_BAD_REQUEST
);
}
$image = $this->request->getUploadedFile('image');
$error = null;
$phpFileUploadErrors = [
Expand Down
30 changes: 30 additions & 0 deletions apps/theming/tests/Controller/ThemingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,36 @@ public function testUpdateLogoNoData() {
$this->assertEquals($expected, $this->themingController->uploadImage());
}

public function testUploadInvalidUploadKey() {
$this->request
->expects($this->once())
->method('getParam')
->with('key')
->willReturn('invalid');
$this->request
->expects($this->never())
->method('getUploadedFile');
$this->l10n
->expects($this->any())
->method('t')
->willReturnCallback(function ($str) {
return $str;
});

$expected = new DataResponse(
[
'data' =>
[
'message' => 'Invalid key',
],
'status' => 'failure',
],
Http::STATUS_BAD_REQUEST
);

$this->assertEquals($expected, $this->themingController->uploadImage());
}

/**
* Checks that trying to upload an SVG favicon without imagemagick
* results in an unsupported media type response.
Expand Down