|
@@ -28,6 +28,7 @@ namespace OCA\Files_Sharing\Tests\Controller;
|
|
|
|
|
|
use OCP\App\IAppManager;
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
|
+use OCP\AppFramework\OCS\OCSException;
|
|
|
use OCP\AppFramework\OCS\OCSNotFoundException;
|
|
|
use OCP\Files\File;
|
|
|
use OCP\Files\Folder;
|
|
@@ -45,6 +46,7 @@ use OCP\IURLGenerator;
|
|
|
use OCP\IUser;
|
|
|
use OCP\Files\IRootFolder;
|
|
|
use OCP\Lock\LockedException;
|
|
|
+use OCP\Share\Exceptions\GenericShareException;
|
|
|
use OCP\Share\IManager;
|
|
|
use OCP\Share;
|
|
|
use Test\TestCase;
|
|
@@ -2418,157 +2420,16 @@ class ShareAPIControllerTest extends TestCase {
|
|
|
$mountPoint->method('getStorageRootId')
|
|
|
->willReturn(42);
|
|
|
|
|
|
- $this->shareManager->expects($this->never())->method('updateShare');
|
|
|
-
|
|
|
- try {
|
|
|
- $ocs->updateShare(42, 31);
|
|
|
- $this->fail();
|
|
|
- } catch (OCSNotFoundException $e) {
|
|
|
- $this->assertEquals('Cannot increase permissions', $e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function testUpdateShareCannotIncreasePermissionsLinkShare() {
|
|
|
- $ocs = $this->mockFormatShare();
|
|
|
-
|
|
|
- $folder = $this->createMock(Folder::class);
|
|
|
- $folder->method('getId')
|
|
|
- ->willReturn(42);
|
|
|
-
|
|
|
- $share = \OC::$server->getShareManager()->newShare();
|
|
|
- $share
|
|
|
- ->setId(42)
|
|
|
- ->setSharedBy($this->currentUser)
|
|
|
- ->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)
|
|
|
- ->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, []],
|
|
|
- ['currentUser', \OCP\Share::SHARE_TYPE_ROOM, $share->getNode(), -1, 0, []]
|
|
|
- ]));
|
|
|
-
|
|
|
- $userFolder = $this->createMock(Folder::class);
|
|
|
- $this->rootFolder->method('getUserFolder')
|
|
|
- ->with($this->currentUser)
|
|
|
- ->willReturn($userFolder);
|
|
|
-
|
|
|
- $userFolder->method('getById')
|
|
|
- ->with(42)
|
|
|
- ->willReturn([$folder]);
|
|
|
-
|
|
|
- $mountPoint = $this->createMock(IMountPoint::class);
|
|
|
- $folder->method('getMountPoint')
|
|
|
- ->willReturn($mountPoint);
|
|
|
- $mountPoint->method('getStorageRootId')
|
|
|
- ->willReturn(42);
|
|
|
-
|
|
|
- $this->shareManager->expects($this->never())->method('updateShare');
|
|
|
- $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
|
|
|
-
|
|
|
- try {
|
|
|
- $ocs->updateShare(42, null, null, null, 'true');
|
|
|
- $this->fail();
|
|
|
- } catch (OCSNotFoundException $e) {
|
|
|
- $this->assertEquals('Cannot increase permissions', $e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function testUpdateShareCannotIncreasePermissionsRoomShare() {
|
|
|
- $ocs = $this->mockFormatShare();
|
|
|
-
|
|
|
- $folder = $this->createMock(Folder::class);
|
|
|
- $folder->method('getId')
|
|
|
- ->willReturn(42);
|
|
|
-
|
|
|
- $share = \OC::$server->getShareManager()->newShare();
|
|
|
- $share
|
|
|
- ->setId(42)
|
|
|
- ->setSharedBy($this->currentUser)
|
|
|
- ->setShareOwner('anotheruser')
|
|
|
- ->setShareType(\OCP\Share::SHARE_TYPE_ROOM)
|
|
|
- ->setSharedWith('group1')
|
|
|
- ->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)
|
|
|
- ->setShareOwner('anotheruser')
|
|
|
- ->setShareType(\OCP\Share::SHARE_TYPE_ROOM)
|
|
|
- ->setSharedWith('group1')
|
|
|
- ->setPermissions(\OCP\Constants::PERMISSION_READ)
|
|
|
- ->setNode($folder);
|
|
|
-
|
|
|
- $this->request
|
|
|
- ->method('getParam')
|
|
|
- ->will($this->returnValueMap([
|
|
|
- ['permissions', null, '31'],
|
|
|
- ]));
|
|
|
-
|
|
|
- $this->shareManager
|
|
|
- ->method('getShareById')
|
|
|
- ->will($this->returnCallback(
|
|
|
- function ($id) use ($share) {
|
|
|
- if ($id !== 'ocRoomShare:42') {
|
|
|
- throw new \OCP\Share\Exceptions\ShareNotFound();
|
|
|
- }
|
|
|
-
|
|
|
- return $share;
|
|
|
- }
|
|
|
- ));
|
|
|
-
|
|
|
- $userFolder = $this->createMock(Folder::class);
|
|
|
- $this->rootFolder->method('getUserFolder')
|
|
|
- ->with($this->currentUser)
|
|
|
- ->willReturn($userFolder);
|
|
|
-
|
|
|
- $userFolder->method('getById')
|
|
|
- ->with(42)
|
|
|
- ->willReturn([$folder]);
|
|
|
-
|
|
|
- $mountPoint = $this->createMock(IMountPoint::class);
|
|
|
- $folder->method('getMountPoint')
|
|
|
- ->willReturn($mountPoint);
|
|
|
- $mountPoint->method('getStorageRootId')
|
|
|
- ->willReturn(42);
|
|
|
-
|
|
|
- $this->shareManager->expects($this->any())
|
|
|
- ->method('getSharedWith')
|
|
|
- ->will($this->returnValueMap([
|
|
|
- ['currentUser', \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0, []],
|
|
|
- ['currentUser', \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0, []],
|
|
|
- ['currentUser', \OCP\Share::SHARE_TYPE_ROOM, $share->getNode(), -1, 0, [$incomingShare]]
|
|
|
- ]));
|
|
|
-
|
|
|
- $this->shareManager->expects($this->never())->method('updateShare');
|
|
|
+ $this->shareManager->expects($this->once())
|
|
|
+ ->method('updateShare')
|
|
|
+ ->with($share)
|
|
|
+ ->willThrowException(new GenericShareException('Can’t increase permissions of path/file', 'Can’t increase permissions of path/file', 404));
|
|
|
|
|
|
try {
|
|
|
$ocs->updateShare(42, 31);
|
|
|
$this->fail();
|
|
|
- } catch (OCSNotFoundException $e) {
|
|
|
- $this->assertEquals('Cannot increase permissions', $e->getMessage());
|
|
|
+ } catch (OCSException $e) {
|
|
|
+ $this->assertEquals('Can’t increase permissions of path/file', $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|