Merge pull request #23493 from owncloud/stable9_22679

[Stable 9] When the Share API is disabled do not return shares
This commit is contained in:
Thomas Müller 2016-03-23 08:07:06 +01:00
commit 3d0e4bdc82
2 changed files with 92 additions and 0 deletions

View File

@ -156,10 +156,15 @@ 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 both our default, and our federated provider..
$share = null;
// First check if it is an internal share.
try {
$share = $this->shareManager->getShareById('ocinternal:'.$id);
} catch (ShareNotFound $e) {
@ -198,6 +203,10 @@ class Share20OCS {
* @return \OC_OCS_Result
*/
public function deleteShare($id) {
if (!$this->shareManager->shareApiEnabled()) {
return new \OC_OCS_Result(null, 404, 'Share API is disabled');
}
// Try both our default and our federated provider
$share = null;
@ -236,6 +245,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) {
@ -453,6 +466,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');
@ -510,6 +527,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 both our default and our federated provider
$share = null;

View File

@ -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');
@ -1875,7 +1879,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);
}
}