aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/MountProviderTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/tests/MountProviderTest.php')
-rw-r--r--apps/files_sharing/tests/MountProviderTest.php102
1 files changed, 68 insertions, 34 deletions
diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php
index 53bea929def..37e7e3d9d03 100644
--- a/apps/files_sharing/tests/MountProviderTest.php
+++ b/apps/files_sharing/tests/MountProviderTest.php
@@ -39,6 +39,7 @@ use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\Share\IAttributes as IShareAttributes;
use OCP\Share\IManager;
use OCP\Share\IShare;
@@ -81,12 +82,36 @@ class MountProviderTest extends \Test\TestCase {
$this->provider = new MountProvider($this->config, $this->shareManager, $this->logger, $eventDispatcher, $cacheFactory);
}
- private function makeMockShare($id, $nodeId, $owner = 'user2', $target = null, $permissions = 31) {
+ private function makeMockShareAttributes($attrs) {
+ if ($attrs === null) {
+ return null;
+ }
+
+ $shareAttributes = $this->createMock(IShareAttributes::class);
+ $shareAttributes->method('toArray')->willReturn($attrs);
+ $shareAttributes->method('getAttribute')->will(
+ $this->returnCallback(function ($scope, $key) use ($attrs) {
+ $result = null;
+ foreach ($attrs as $attr) {
+ if ($attr['key'] === $key && $attr['scope'] === $scope) {
+ $result = $attr['enabled'];
+ }
+ }
+ return $result;
+ })
+ );
+ return $shareAttributes;
+ }
+
+ private function makeMockShare($id, $nodeId, $owner = 'user2', $target = null, $permissions = 31, $attributes = null) {
$share = $this->createMock(IShare::class);
$share->expects($this->any())
->method('getPermissions')
->willReturn($permissions);
$share->expects($this->any())
+ ->method('getAttributes')
+ ->will($this->returnValue($this->makeMockShareAttributes($attributes)));
+ $share->expects($this->any())
->method('getShareOwner')
->willReturn($owner);
$share->expects($this->any())
@@ -115,14 +140,16 @@ class MountProviderTest extends \Test\TestCase {
public function testExcludeShares() {
$rootFolder = $this->createMock(IRootFolder::class);
$userManager = $this->createMock(IUserManager::class);
+ $attr1 = [];
+ $attr2 = [['scope' => 'permission', 'key' => 'download', 'enabled' => true]];
$userShares = [
- $this->makeMockShare(1, 100, 'user2', '/share2', 0),
- $this->makeMockShare(2, 100, 'user2', '/share2', 31),
+ $this->makeMockShare(1, 100, 'user2', '/share2', 0, $attr1),
+ $this->makeMockShare(2, 100, 'user2', '/share2', 31, $attr2),
];
$groupShares = [
- $this->makeMockShare(3, 100, 'user2', '/share2', 0),
- $this->makeMockShare(4, 101, 'user2', '/share4', 31),
- $this->makeMockShare(5, 100, 'user1', '/share4', 31),
+ $this->makeMockShare(3, 100, 'user2', '/share2', 0, $attr1),
+ $this->makeMockShare(4, 101, 'user2', '/share4', 31, $attr2),
+ $this->makeMockShare(5, 100, 'user1', '/share4', 31, $attr2),
];
$roomShares = [
$this->makeMockShare(6, 102, 'user2', '/share6', 0),
@@ -173,12 +200,14 @@ class MountProviderTest extends \Test\TestCase {
$this->assertEquals(100, $mountedShare1->getNodeId());
$this->assertEquals('/share2', $mountedShare1->getTarget());
$this->assertEquals(31, $mountedShare1->getPermissions());
+ $this->assertEquals(true, $mountedShare1->getAttributes()->getAttribute('permission', 'download'));
$mountedShare2 = $mounts[1]->getShare();
$this->assertEquals('4', $mountedShare2->getId());
$this->assertEquals('user2', $mountedShare2->getShareOwner());
$this->assertEquals(101, $mountedShare2->getNodeId());
$this->assertEquals('/share4', $mountedShare2->getTarget());
$this->assertEquals(31, $mountedShare2->getPermissions());
+ $this->assertEquals(true, $mountedShare2->getAttributes()->getAttribute('permission', 'download'));
$mountedShare3 = $mounts[2]->getShare();
$this->assertEquals('8', $mountedShare3->getId());
$this->assertEquals('user2', $mountedShare3->getShareOwner());
@@ -200,27 +229,27 @@ class MountProviderTest extends \Test\TestCase {
// #0: share as outsider with "group1" and "user1" with same permissions
[
[
- [1, 100, 'user2', '/share2', 31],
+ [1, 100, 'user2', '/share2', 31, null],
],
[
- [2, 100, 'user2', '/share2', 31],
+ [2, 100, 'user2', '/share2', 31, null],
],
[
// combined, user share has higher priority
- ['1', 100, 'user2', '/share2', 31],
+ ['1', 100, 'user2', '/share2', 31, []],
],
],
// #1: share as outsider with "group1" and "user1" with different permissions
[
[
- [1, 100, 'user2', '/share', 31],
+ [1, 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => true], ['scope' => 'app', 'key' => 'attribute1', 'enabled' => true]]],
],
[
- [2, 100, 'user2', '/share', 15],
+ [2, 100, 'user2', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'enabled' => false], ['scope' => 'app', 'key' => 'attribute2', 'enabled' => false]]],
],
[
// use highest permissions
- ['1', 100, 'user2', '/share', 31],
+ ['1', 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => true], ['scope' => 'app', 'key' => 'attribute1', 'enabled' => true], ['scope' => 'app', 'key' => 'attribute2', 'enabled' => false]]],
],
],
// #2: share as outsider with "group1" and "group2" with same permissions
@@ -228,12 +257,12 @@ class MountProviderTest extends \Test\TestCase {
[
],
[
- [1, 100, 'user2', '/share', 31],
- [2, 100, 'user2', '/share', 31],
+ [1, 100, 'user2', '/share', 31, null],
+ [2, 100, 'user2', '/share', 31, []],
],
[
// combined, first group share has higher priority
- ['1', 100, 'user2', '/share', 31],
+ ['1', 100, 'user2', '/share', 31, []],
],
],
// #3: share as outsider with "group1" and "group2" with different permissions
@@ -241,12 +270,12 @@ class MountProviderTest extends \Test\TestCase {
[
],
[
- [1, 100, 'user2', '/share', 31],
- [2, 100, 'user2', '/share', 15],
+ [1, 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => false]]],
+ [2, 100, 'user2', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'enabled' => true]]],
],
[
- // use higher permissions
- ['1', 100, 'user2', '/share', 31],
+ // use higher permissions (most permissive)
+ ['1', 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => true]]],
],
],
// #4: share as insider with "group1"
@@ -254,7 +283,7 @@ class MountProviderTest extends \Test\TestCase {
[
],
[
- [1, 100, 'user1', '/share', 31],
+ [1, 100, 'user1', '/share', 31, []],
],
[
// no received share since "user1" is the sharer/owner
@@ -265,8 +294,8 @@ class MountProviderTest extends \Test\TestCase {
[
],
[
- [1, 100, 'user1', '/share', 31],
- [2, 100, 'user1', '/share', 15],
+ [1, 100, 'user1', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'enabled' => true]]],
+ [2, 100, 'user1', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'enabled' => false]]],
],
[
// no received share since "user1" is the sharer/owner
@@ -277,7 +306,7 @@ class MountProviderTest extends \Test\TestCase {
[
],
[
- [1, 100, 'user2', '/share', 0],
+ [1, 100, 'user2', '/share', 0, []],
],
[
// no received share since "user1" opted out
@@ -286,40 +315,40 @@ class MountProviderTest extends \Test\TestCase {
// #7: share as outsider with "group1" and "user1" where recipient renamed in between
[
[
- [1, 100, 'user2', '/share2-renamed', 31],
+ [1, 100, 'user2', '/share2-renamed', 31, []],
],
[
- [2, 100, 'user2', '/share2', 31],
+ [2, 100, 'user2', '/share2', 31, []],
],
[
// use target of least recent share
- ['1', 100, 'user2', '/share2-renamed', 31],
+ ['1', 100, 'user2', '/share2-renamed', 31, []],
],
],
// #8: share as outsider with "group1" and "user1" where recipient renamed in between
[
[
- [2, 100, 'user2', '/share2', 31],
+ [2, 100, 'user2', '/share2', 31, []],
],
[
- [1, 100, 'user2', '/share2-renamed', 31],
+ [1, 100, 'user2', '/share2-renamed', 31, []],
],
[
// use target of least recent share
- ['1', 100, 'user2', '/share2-renamed', 31],
+ ['1', 100, 'user2', '/share2-renamed', 31, []],
],
],
// #9: share as outsider with "nullgroup" and "user1" where recipient renamed in between
[
[
- [2, 100, 'user2', '/share2', 31],
+ [2, 100, 'user2', '/share2', 31, []],
],
[
- [1, 100, 'nullgroup', '/share2-renamed', 31],
+ [1, 100, 'nullgroup', '/share2-renamed', 31, []],
],
[
// use target of least recent share
- ['1', 100, 'nullgroup', '/share2-renamed', 31],
+ ['1', 100, 'nullgroup', '/share2-renamed', 31, []],
],
true
],
@@ -343,10 +372,10 @@ class MountProviderTest extends \Test\TestCase {
$userManager = $this->createMock(IUserManager::class);
$userShares = array_map(function ($shareSpec) {
- return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4]);
+ return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4], $shareSpec[5]);
}, $userShares);
$groupShares = array_map(function ($shareSpec) {
- return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4]);
+ return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4], $shareSpec[5]);
}, $groupShares);
$this->user->expects($this->any())
@@ -400,6 +429,11 @@ class MountProviderTest extends \Test\TestCase {
$this->assertEquals($expectedShare[2], $share->getShareOwner());
$this->assertEquals($expectedShare[3], $share->getTarget());
$this->assertEquals($expectedShare[4], $share->getPermissions());
+ if ($expectedShare[5] === null) {
+ $this->assertNull($share->getAttributes());
+ } else {
+ $this->assertEquals($expectedShare[5], $share->getAttributes()->toArray());
+ }
}
}
}