aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/Controller
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-08-16 15:09:15 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-10-04 21:40:30 +0200
commitff895abac081ffd53b9d1509565e9dfe923b6d60 (patch)
treec189db36916df556e2476ec38ea036d9a2346269 /apps/files_sharing/tests/Controller
parentb1069b29fa7eacdaed8160e600f5a98b32e6784b (diff)
downloadnextcloud-server-ff895abac081ffd53b9d1509565e9dfe923b6d60.tar.gz
nextcloud-server-ff895abac081ffd53b9d1509565e9dfe923b6d60.zip
Fix shares read permissions
A user with reshare permissions on a file is now able to get any share of that file (just like the owner). Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files_sharing/tests/Controller')
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 7eee526f2d1..5a84897fe91 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -375,6 +375,15 @@ class ShareAPIControllerTest extends TestCase {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
+ $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
+
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$share->getNode()]);
+
$this->shareManager->expects($this->once())
->method('deleteFromSelf')
->with($share, $this->currentUser);
@@ -427,6 +436,15 @@ class ShareAPIControllerTest extends TestCase {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);
+ $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
+
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$share->getNode()]);
+
$this->shareManager->expects($this->never())
->method('deleteFromSelf');
@@ -758,6 +776,11 @@ class ShareAPIControllerTest extends TestCase {
->with('ocinternal:42', 'currentUser')
->willReturn($share);
+ $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
+
$this->ocs->getShare(42);
}
@@ -775,6 +798,27 @@ class ShareAPIControllerTest extends TestCase {
$share->method('getSharedWith')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $file = $this->getMockBuilder(File::class)->getMock();
+
+ $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
+
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$file]);
+
+ $file->method('getPermissions')
+ ->will($this->onConsecutiveCalls(\OCP\Constants::PERMISSION_SHARE, \OCP\Constants::PERMISSION_READ));
+
+ // getPermissions -> share
+ $share = $this->getMockBuilder(IShare::class)->getMock();
+ $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
+ $share->method('getSharedWith')->willReturn($this->getMockBuilder(IUser::class)->getMock());
+ $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+
+ // getPermissions -> read
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
$share->method('getSharedWith')->willReturn($this->getMockBuilder(IUser::class)->getMock());
@@ -852,6 +896,15 @@ class ShareAPIControllerTest extends TestCase {
* @param bool canAccessShareByHelper
*/
public function testCanAccessRoomShare(bool $expected, \OCP\Share\IShare $share, bool $helperAvailable, bool $canAccessShareByHelper) {
+ $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
+
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$share->getNode()]);
+
if (!$helperAvailable) {
$this->appManager->method('isEnabledForUser')
->with('spreed')
@@ -1727,6 +1780,15 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
+ $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
+
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$share->getNode()]);
+
$this->ocs->updateShare(42);
}