Merge pull request #2121 from nextcloud/stable10_2100

[Stable10] Fixes not allowed increasing of link share permissions
This commit is contained in:
Morris Jobke 2016-11-17 18:55:40 +01:00 committed by GitHub
commit 9386e5b232
2 changed files with 56 additions and 0 deletions

View File

@ -637,6 +637,7 @@ class Share20OCS {
if ($newPermissions !== null) {
$share->setPermissions($newPermissions);
$permissions = $newPermissions;
}
if ($expireDate === '') {

View File

@ -1334,6 +1334,9 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
$this->shareManager->method('getSharedWith')
->willReturn([]);
$expected = new \OC_OCS_Result(null);
$result = $ocs->updateShare(42);
@ -1374,6 +1377,9 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
$this->shareManager->method('getSharedWith')
->willReturn([]);
$expected = new \OC_OCS_Result(null);
$result = $ocs->updateShare(42);
@ -1650,6 +1656,9 @@ class Share20OCSTest extends \Test\TestCase {
})
)->will($this->returnArgument(0));
$this->shareManager->method('getSharedWith')
->willReturn([]);
$expected = new \OC_OCS_Result(null);
$result = $ocs->updateShare(42);
@ -1819,6 +1828,52 @@ class Share20OCSTest extends \Test\TestCase {
$this->assertEquals($expected->getData(), $result->getData());
}
public function testUpdateShareCannotIncreasePermissionsLinkShare() {
$ocs = $this->mockFormatShare();
$folder = $this->getMockBuilder('OCP\Files\Folder')
->getMock();
$share = \OC::$server->getShareManager()->newShare();
$share
->setId(42)
->setSharedBy($this->currentUser->getUID())
->setShareOwner('anotheruser')
->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setNode($folder);
// note: updateShare will modify the received instance but getSharedWith will reread from the database,
// so their values will be different
$incomingShare = \OC::$server->getShareManager()->newShare();
$incomingShare
->setId(42)
->setSharedBy($this->currentUser->getUID())
->setShareOwner('anotheruser')
->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith('currentUser')
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setNode($folder);
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->expects($this->any())
->method('getSharedWith')
->will($this->returnValueMap([
['currentUser', \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0, [$incomingShare]],
['currentUser', \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0, []]
]));
$this->shareManager->expects($this->never())->method('updateShare');
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
$this->request
->method('getParam')
->will($this->returnValueMap([
['publicUpload', null, 'true'],
]));
$expected = new \OC_OCS_Result(null, 404, 'Cannot increase permissions');
$result = $ocs->updateShare(42);
$this->assertEquals($expected->getMeta(), $result->getMeta());
$this->assertEquals($expected->getData(), $result->getData());
}
public function testUpdateShareCanIncreasePermissionsIfOwner() {
$ocs = $this->mockFormatShare();