summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-07-13 12:50:00 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-08-03 10:16:28 +0200
commit0bddaa23b098cee55b1d85f9a627a1df1c8a9410 (patch)
treed7c6b0c2d4640971933516583d0941b68af1ff0a /apps
parent67fa6bf9bce6d237684ebd3f60625ff98abc71c0 (diff)
downloadnextcloud-server-0bddaa23b098cee55b1d85f9a627a1df1c8a9410.tar.gz
nextcloud-server-0bddaa23b098cee55b1d85f9a627a1df1c8a9410.zip
Added more tests for sharing's MountProvider
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/tests/MountProviderTest.php158
1 files changed, 158 insertions, 0 deletions
diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php
index c949515546b..95e2140897b 100644
--- a/apps/files_sharing/tests/MountProviderTest.php
+++ b/apps/files_sharing/tests/MountProviderTest.php
@@ -88,6 +88,11 @@ class MountProviderTest extends \Test\TestCase {
return $share;
}
+ /**
+ * Tests excluding shares from the current view. This includes:
+ * - shares that were opted out of (permissions === 0)
+ * - shares with a group in which the owner is already in
+ */
public function testExcludeShares() {
$rootFolder = $this->getMock('\OCP\Files\IRootFolder');
$userManager = $this->getMock('\OCP\IUserManager');
@@ -133,5 +138,158 @@ class MountProviderTest extends \Test\TestCase {
$this->assertEquals('/share4', $mountedShare2->getTarget());
$this->assertEquals(31, $mountedShare2->getPermissions());
}
+
+ public function mergeSharesDataProvider() {
+ // note: the user in the specs here is the shareOwner not recipient
+ // the recipient is always "user1"
+ return [
+ // #0: share as outsider with "group1" and "user1" with same permissions
+ [
+ [
+ [1, 100, 'user2', '/share2', 31],
+ ],
+ [
+ [2, 100, 'user2', '/share2', 31],
+ ],
+ [
+ // combined, user share has higher priority
+ ['1', 100, 'user2', '/share2', 31],
+ ],
+ ],
+ // #1: share as outsider with "group1" and "user1" with different permissions
+ [
+ [
+ [1, 100, 'user2', '/share', 31],
+ ],
+ [
+ [2, 100, 'user2', '/share', 15],
+ ],
+ [
+ // use highest permissions
+ ['1', 100, 'user2', '/share', 31],
+ ],
+ ],
+ // #2: share as outsider with "group1" and "group2" with same permissions
+ [
+ [
+ ],
+ [
+ [1, 100, 'user2', '/share', 31],
+ [2, 100, 'user2', '/share', 31],
+ ],
+ [
+ // combined, first group share has higher priority
+ ['1', 100, 'user2', '/share', 31],
+ ],
+ ],
+ // #3: share as outsider with "group1" and "group2" with different permissions
+ [
+ [
+ ],
+ [
+ [1, 100, 'user2', '/share', 31],
+ [2, 100, 'user2', '/share', 15],
+ ],
+ [
+ // use higher permissions
+ ['1', 100, 'user2', '/share', 31],
+ ],
+ ],
+ // #4: share as insider with "group1"
+ [
+ [
+ ],
+ [
+ [1, 100, 'user1', '/share', 31],
+ ],
+ [
+ // no received share since "user1" is the sharer/owner
+ ],
+ ],
+ // #5: share as insider with "group1" and "group2" with different permissions
+ [
+ [
+ ],
+ [
+ [1, 100, 'user1', '/share', 31],
+ [2, 100, 'user1', '/share', 15],
+ ],
+ [
+ // no received share since "user1" is the sharer/owner
+ ],
+ ],
+ // #6: share as outside with "group1", recipient opted out
+ [
+ [
+ ],
+ [
+ [1, 100, 'user2', '/share', 0],
+ ],
+ [
+ // no received share since "user1" opted out
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Tests merging shares.
+ *
+ * Happens when sharing the same entry to a user through multiple ways,
+ * like several groups and also direct shares at the same time.
+ *
+ * @dataProvider mergeSharesDataProvider
+ *
+ * @param array $userShares array of user share specs
+ * @param array $groupShares array of group share specs
+ * @param array $expectedShares array of expected supershare specs
+ */
+ public function testMergeShares($userShares, $groupShares, $expectedShares) {
+ $rootFolder = $this->getMock('\OCP\Files\IRootFolder');
+ $userManager = $this->getMock('\OCP\IUserManager');
+
+ $userShares = array_map(function($shareSpec) {
+ return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4]);
+ }, $userShares);
+ $groupShares = array_map(function($shareSpec) {
+ return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4]);
+ }, $groupShares);
+
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue('user1'));
+
+ $this->shareManager->expects($this->at(0))
+ ->method('getSharedWith')
+ ->with('user1', \OCP\Share::SHARE_TYPE_USER)
+ ->will($this->returnValue($userShares));
+ $this->shareManager->expects($this->at(1))
+ ->method('getSharedWith')
+ ->with('user1', \OCP\Share::SHARE_TYPE_GROUP, null, -1)
+ ->will($this->returnValue($groupShares));
+ $this->shareManager->expects($this->any())
+ ->method('newShare')
+ ->will($this->returnCallback(function() use ($rootFolder, $userManager) {
+ return new \OC\Share20\Share($rootFolder, $userManager);
+ }));
+
+ $mounts = $this->provider->getMountsForUser($this->user, $this->loader);
+
+ $this->assertCount(count($expectedShares), $mounts);
+
+ foreach ($mounts as $index => $mount) {
+ $expectedShare = $expectedShares[$index];
+ $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mount);
+
+ // supershare
+ $share = $mount->getShare();
+
+ $this->assertEquals($expectedShare[0], $share->getId());
+ $this->assertEquals($expectedShare[1], $share->getNodeId());
+ $this->assertEquals($expectedShare[2], $share->getShareOwner());
+ $this->assertEquals($expectedShare[3], $share->getTarget());
+ $this->assertEquals($expectedShare[4], $share->getPermissions());
+ }
+ }
}