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
This commit is contained in:
Roeland Jago Douma 2015-09-22 14:47:04 +02:00
parent 762e7c3dd9
commit 4dba046712
2 changed files with 37 additions and 3 deletions

View File

@ -87,6 +87,11 @@ class SharingCheckMiddleware extends Middleware {
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;

View File

@ -54,7 +54,13 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
->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,29 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
$this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
}
public function testIsSharingEnabledWithSharingDisabled() {
public function testIsSharingEnabledWithLinkSharingDisabled() {
$this->appManager
->expects($this->once())
->method('isEnabledForUser')
->with('files_sharing')
->will($this->returnValue(true));
$this->config
->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')
@ -82,9 +110,10 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
$this->config
->expects($this->once())
->method('getAppValue')
->with('core', 'shareapi_allow_links', 'yes')
->with('core', 'shareapi_enabled', 'yes')
->will($this->returnValue('no'));
$this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
}
}