summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/middleware/sharingcheckmiddleware.php15
-rw-r--r--apps/files_sharing/tests/middleware/sharingcheckmiddleware.php57
2 files changed, 43 insertions, 29 deletions
diff --git a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
index 61dfd914d0b..f51399b76a8 100644
--- a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
+++ b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
@@ -68,6 +68,13 @@ class SharingCheckMiddleware extends Middleware {
if(!$this->isSharingEnabled()) {
throw new NotFoundException('Sharing is disabled.');
}
+
+ if ($controller instanceof \OCA\Files_Sharing\Controllers\ExternalSharesController) {
+ //TODO: Proper checks
+ } else if ($controller instanceof \OCA\Files_Sharing\Controllers\ShareController &&
+ !$this->isLinkSharingEnabled()) {
+ throw new NotFoundException('Link sharing is disabled');
+ }
}
/**
@@ -98,6 +105,14 @@ class SharingCheckMiddleware extends Middleware {
return false;
}
+ return true;
+ }
+
+ /**
+ * Check if link sharing is allowed
+ * @return bool
+ */
+ private function isLinkSharingEnabled() {
// Check if the shareAPI is enabled
if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') {
return false;
diff --git a/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php b/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php
index 3171d45d331..a43b11c81b6 100644
--- a/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php
+++ b/apps/files_sharing/tests/middleware/sharingcheckmiddleware.php
@@ -51,13 +51,27 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
$this->sharingCheckMiddleware = new SharingCheckMiddleware('files_sharing', $this->config, $this->appManager);
}
- public function testIsSharingEnabledWithEverythingEnabled() {
+ public function testIsSharingEnabledWithAppEnabled() {
$this->appManager
->expects($this->once())
->method('isEnabledForUser')
->with('files_sharing')
->will($this->returnValue(true));
+ $this->assertTrue(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
+ }
+
+ public function testIsSharingEnabledWithAppDisabled() {
+ $this->appManager
+ ->expects($this->once())
+ ->method('isEnabledForUser')
+ ->with('files_sharing')
+ ->will($this->returnValue(false));
+
+ $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
+ }
+
+ public function testIsLinkSharingEnabledWithEverythinEnabled() {
$this->config
->expects($this->at(0))
->method('getAppValue')
@@ -70,26 +84,11 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
->with('core', 'shareapi_allow_links', 'yes')
->will($this->returnValue('yes'));
- $this->assertTrue(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
+ $this->assertTrue(self::invokePrivate($this->sharingCheckMiddleware, 'isLinkSharingEnabled'));
}
- public function testIsSharingEnabledWithAppDisabled() {
- $this->appManager
- ->expects($this->once())
- ->method('isEnabledForUser')
- ->with('files_sharing')
- ->will($this->returnValue(false));
-
- $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
- }
-
- public function testIsSharingEnabledWithLinkSharingDisabled() {
- $this->appManager
- ->expects($this->once())
- ->method('isEnabledForUser')
- ->with('files_sharing')
- ->will($this->returnValue(true));
+ public function testIsLinkSharingEnabledWithLinkSharingDisabled() {
$this->config
->expects($this->at(0))
->method('getAppValue')
@@ -102,23 +101,17 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
->with('core', 'shareapi_allow_links', 'yes')
->will($this->returnValue('no'));
- $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
+ $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isLinkSharingEnabled'));
}
- public function testIsSharingEnabledWithSharingAPIDisabled() {
- $this->appManager
- ->expects($this->once())
- ->method('isEnabledForUser')
- ->with('files_sharing')
- ->will($this->returnValue(true));
-
+ public function testIsLinkSharingEnabledWithSharingAPIDisabled() {
$this->config
->expects($this->once())
->method('getAppValue')
->with('core', 'shareapi_enabled', 'yes')
->will($this->returnValue('no'));
- $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
+ $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isLinkSharingEnabled'));
}
public function testBeforeControllerWithSharingEnabled() {
@@ -140,7 +133,10 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
->with('core', 'shareapi_allow_links', 'yes')
->will($this->returnValue('yes'));
- $this->sharingCheckMiddleware->beforeController($this->controllerMock, 'myMethod');
+ $controller = $this->getMockBuilder('\OCA\Files_Sharing\Controllers\ShareController')
+ ->disableOriginalConstructor()->getMock();
+
+ $this->sharingCheckMiddleware->beforeController($controller, 'myMethod');
}
/**
@@ -154,7 +150,10 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
->with('files_sharing')
->will($this->returnValue(false));
- $this->sharingCheckMiddleware->beforeController($this->controllerMock, 'myMethod');
+ $controller = $this->getMockBuilder('\OCA\Files_Sharing\Controllers\ShareController')
+ ->disableOriginalConstructor()->getMock();
+
+ $this->sharingCheckMiddleware->beforeController($controller, 'myMethod');
}
/**