summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-03-22 21:26:31 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-03-22 21:26:31 +0100
commite516612a257e4b542768146d9705b2c6f6999473 (patch)
tree0fec246679a123b05ecabd4186188fb4f7854b84
parentb1e5adf197b85151de990b79a7205074f36f9069 (diff)
parent00f48ec37ba90254aca4643b2627bb2ffc7bd1fb (diff)
downloadnextcloud-server-e516612a257e4b542768146d9705b2c6f6999473.tar.gz
nextcloud-server-e516612a257e4b542768146d9705b2c6f6999473.zip
Merge pull request #22679 from owncloud/fix_22668
When the Share API is disabled do not return shares
-rw-r--r--apps/files_sharing/api/share20ocs.php21
-rw-r--r--apps/files_sharing/tests/api/share20ocstest.php71
2 files changed, 91 insertions, 1 deletions
diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php
index 5a2af48d6f5..efdd9ecb30e 100644
--- a/apps/files_sharing/api/share20ocs.php
+++ b/apps/files_sharing/api/share20ocs.php
@@ -161,6 +161,10 @@ class Share20OCS {
* @return \OC_OCS_Result
*/
public function getShare($id) {
+ if (!$this->shareManager->shareApiEnabled()) {
+ return new \OC_OCS_Result(null, 404, 'Share API is disabled');
+ }
+
try {
$share = $this->getShareById($id);
} catch (ShareNotFound $e) {
@@ -186,7 +190,10 @@ class Share20OCS {
* @return \OC_OCS_Result
*/
public function deleteShare($id) {
- // Try both our default and our federated provider
+ if (!$this->shareManager->shareApiEnabled()) {
+ return new \OC_OCS_Result(null, 404, 'Share API is disabled');
+ }
+
try {
$share = $this->getShareById($id);
} catch (ShareNotFound $e) {
@@ -208,6 +215,10 @@ class Share20OCS {
public function createShare() {
$share = $this->shareManager->newShare();
+ if (!$this->shareManager->shareApiEnabled()) {
+ return new \OC_OCS_Result(null, 404, 'Share API is disabled');
+ }
+
// Verify path
$path = $this->request->getParam('path', null);
if ($path === null) {
@@ -421,6 +432,10 @@ class Share20OCS {
* @return \OC_OCS_Result
*/
public function getShares() {
+ if (!$this->shareManager->shareApiEnabled()) {
+ return new \OC_OCS_Result();
+ }
+
$sharedWithMe = $this->request->getParam('shared_with_me', null);
$reshares = $this->request->getParam('reshares', null);
$subfiles = $this->request->getParam('subfiles');
@@ -478,6 +493,10 @@ class Share20OCS {
* @return \OC_OCS_Result
*/
public function updateShare($id) {
+ if (!$this->shareManager->shareApiEnabled()) {
+ return new \OC_OCS_Result(null, 404, 'Share API is disabled');
+ }
+
try {
$share = $this->getShareById($id);
} catch (ShareNotFound $e) {
diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php
index a2c70d7673c..f641f683e79 100644
--- a/apps/files_sharing/tests/api/share20ocstest.php
+++ b/apps/files_sharing/tests/api/share20ocstest.php
@@ -65,6 +65,10 @@ class Share20OCSTest extends \Test\TestCase {
$this->shareManager = $this->getMockBuilder('OCP\Share\IManager')
->disableOriginalConstructor()
->getMock();
+ $this->shareManager
+ ->expects($this->any())
+ ->method('shareApiEnabled')
+ ->willReturn(true);
$this->groupManager = $this->getMock('OCP\IGroupManager');
$this->userManager = $this->getMock('OCP\IUserManager');
$this->request = $this->getMock('OCP\IRequest');
@@ -1827,7 +1831,74 @@ class Share20OCSTest extends \Test\TestCase {
} catch (NotFoundException $e) {
$this->assertTrue($exception);
}
+ }
+
+ /**
+ * @return Share20OCS
+ */
+ public function getOcsDisabledAPI() {
+ $shareManager = $this->getMockBuilder('OCP\Share\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $shareManager
+ ->expects($this->any())
+ ->method('shareApiEnabled')
+ ->willReturn(false);
+
+ return new Share20OCS(
+ $shareManager,
+ $this->groupManager,
+ $this->userManager,
+ $this->request,
+ $this->rootFolder,
+ $this->urlGenerator,
+ $this->currentUser
+ );
+ }
+
+ public function testGetShareApiDisabled() {
+ $ocs = $this->getOcsDisabledAPI();
+
+ $expected = new \OC_OCS_Result(null, 404, 'Share API is disabled');
+ $result = $ocs->getShare('my:id');
+
+ $this->assertEquals($expected, $result);
+ }
+
+ public function testDeleteShareApiDisabled() {
+ $ocs = $this->getOcsDisabledAPI();
+
+ $expected = new \OC_OCS_Result(null, 404, 'Share API is disabled');
+ $result = $ocs->deleteShare('my:id');
+
+ $this->assertEquals($expected, $result);
+ }
+
+
+ public function testCreateShareApiDisabled() {
+ $ocs = $this->getOcsDisabledAPI();
+
+ $expected = new \OC_OCS_Result(null, 404, 'Share API is disabled');
+ $result = $ocs->createShare();
+
+ $this->assertEquals($expected, $result);
+ }
+
+ public function testGetSharesApiDisabled() {
+ $ocs = $this->getOcsDisabledAPI();
+
+ $expected = new \OC_OCS_Result();
+ $result = $ocs->getShares();
+
+ $this->assertEquals($expected, $result);
+ }
+
+ public function testUpdateShareApiDisabled() {
+ $ocs = $this->getOcsDisabledAPI();
+ $expected = new \OC_OCS_Result(null, 404, 'Share API is disabled');
+ $result = $ocs->updateShare('my:id');
+ $this->assertEquals($expected, $result);
}
}