Skip to content

Commit

Permalink
When the Share API is disabled do not return shares
Browse files Browse the repository at this point in the history
Fixes #22668

Block everything in the OCS Share API
  • Loading branch information
rullzer committed Mar 7, 2016
1 parent c07b731 commit f12b030
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/files_sharing/api/share20ocs.php
Expand Up @@ -158,6 +158,10 @@ public function getShare($id) {
// Try both our default, and our federated provider..
$share = null;

if (!$this->shareManager->shareApiEnabled()) {
return new \OC_OCS_Result(null, 404, 'Share API is disabled');
}

// First check if it is an internal share.
try {
$share = $this->shareManager->getShareById('ocinternal:'.$id);
Expand Down Expand Up @@ -200,6 +204,10 @@ public function deleteShare($id) {
// Try both our default and our federated provider
$share = null;

if (!$this->shareManager->shareApiEnabled()) {
return new \OC_OCS_Result(null, 404, 'Share API is disabled');
}

try {
$share = $this->shareManager->getShareById('ocinternal:' . $id);
} catch (ShareNotFound $e) {
Expand Down Expand Up @@ -235,6 +243,10 @@ public function deleteShare($id) {
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) {
Expand Down Expand Up @@ -448,6 +460,10 @@ private function getSharesInDir($folder) {
* @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');
Expand Down Expand Up @@ -508,6 +524,10 @@ public function updateShare($id) {
// Try both our default and our federated provider
$share = null;

if (!$this->shareManager->shareApiEnabled()) {
return new \OC_OCS_Result(null, 404, 'Share API is disabled');
}

try {
$share = $this->shareManager->getShareById('ocinternal:' . $id);
} catch (ShareNotFound $e) {
Expand Down
71 changes: 71 additions & 0 deletions apps/files_sharing/tests/api/share20ocstest.php
Expand Up @@ -65,6 +65,10 @@ protected function setUp() {
$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');
Expand Down Expand Up @@ -1813,7 +1817,74 @@ public function testFormatShare(array $expects, \OCP\Share\IShare $share, array
} 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);
}
}

0 comments on commit f12b030

Please sign in to comment.