From 4dba046712ebe611ba946ae31d780eb48d224cf0 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 22 Sep 2015 14:47:04 +0200 Subject: [PATCH] Respect disabled sharing API settings If the sharing API setting is disabled that sharing check middle ware should block the request. Thus making link shares unavailable. Fixes #18970 * Unit test added * Unit tests updated --- .../lib/middleware/sharingcheckmiddleware.php | 5 +++ .../middleware/sharingcheckmiddleware.php | 35 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php index 3787ef42d9f7..1c29b1da736f 100644 --- a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php +++ b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php @@ -87,6 +87,11 @@ private function isSharingEnabled() { return false; } + // Check if the shareAPI is enabled + if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { + return false; + } + // Check whether public sharing is enabled if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { return false; diff --git a/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php b/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php index 0db8a1ed5bc1..58f4b8413399 100644 --- a/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php +++ b/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php @@ -54,7 +54,13 @@ public function testIsSharingEnabledWithEverythingEnabled() { ->will($this->returnValue(true)); $this->config - ->expects($this->once()) + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'shareapi_enabled', 'yes') + ->will($this->returnValue('yes')); + + $this->config + ->expects($this->at(1)) ->method('getAppValue') ->with('core', 'shareapi_allow_links', 'yes') ->will($this->returnValue('yes')); @@ -72,7 +78,7 @@ public function testIsSharingEnabledWithAppDisabled() { $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled')); } - public function testIsSharingEnabledWithSharingDisabled() { + public function testIsSharingEnabledWithLinkSharingDisabled() { $this->appManager ->expects($this->once()) ->method('isEnabledForUser') @@ -80,11 +86,34 @@ public function testIsSharingEnabledWithSharingDisabled() { ->will($this->returnValue(true)); $this->config - ->expects($this->once()) + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'shareapi_enabled', 'yes') + ->will($this->returnValue('yes')); + + $this->config + ->expects($this->at(1)) ->method('getAppValue') ->with('core', 'shareapi_allow_links', 'yes') ->will($this->returnValue('no')); $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled')); } + + public function testIsSharingEnabledWithSharingAPIDisabled() { + $this->appManager + ->expects($this->once()) + ->method('isEnabledForUser') + ->with('files_sharing') + ->will($this->returnValue(true)); + + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('core', 'shareapi_enabled', 'yes') + ->will($this->returnValue('no')); + + $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled')); + } + }