summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-05-18 14:54:27 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-07-28 16:53:22 +0200
commita95c19e14b5a371240392de480278ee97c01ab12 (patch)
treec96d6efaa88d234cdc3393e5004fd27cfc174ebe /apps/files_sharing/tests
parentee23f41abe2fd53d00f44d9c16ebd722ac93e9a3 (diff)
downloadnextcloud-server-a95c19e14b5a371240392de480278ee97c01ab12.tar.gz
nextcloud-server-a95c19e14b5a371240392de480278ee97c01ab12.zip
Add share attributes + prevent download permission
Makes it possible to store download permission Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r--apps/files_sharing/tests/ApiTest.php7
-rw-r--r--apps/files_sharing/tests/ApplicationTest.php238
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php49
-rw-r--r--apps/files_sharing/tests/MountProviderTest.php97
4 files changed, 353 insertions, 38 deletions
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index a16a1aaf383..50869b7a9f8 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -948,8 +948,11 @@ class ApiTest extends TestCase {
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
- ->setPermissions(19);
+ ->setPermissions(19)
+ ->setAttributes($this->shareManager->newShare()->newAttributes());
$share1 = $this->shareManager->createShare($share1);
+ $this->assertEquals(19, $share1->getPermissions());
+ $this->assertEquals(null, $share1->getAttributes());
$share2 = $this->shareManager->newShare();
$share2->setNode($node1)
@@ -957,6 +960,7 @@ class ApiTest extends TestCase {
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share2);
+ $this->assertEquals(1, $share2->getPermissions());
// update permissions
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
@@ -965,6 +969,7 @@ class ApiTest extends TestCase {
$share1 = $this->shareManager->getShareById('ocinternal:' . $share1->getId());
$this->assertEquals(1, $share1->getPermissions());
+ $this->assertEquals(true, $share1->getAttributes()->getAttribute('app1', 'attr1'));
// update password for link share
$this->assertNull($share2->getPassword());
diff --git a/apps/files_sharing/tests/ApplicationTest.php b/apps/files_sharing/tests/ApplicationTest.php
new file mode 100644
index 00000000000..3f3164b233e
--- /dev/null
+++ b/apps/files_sharing/tests/ApplicationTest.php
@@ -0,0 +1,238 @@
+<?php
+/**
+ * @copyright 2022, Vincent Petry <vincent@nextcloud.com>
+ *
+ * @author Vincent Petry <vincent@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Files_Sharing\Tests;
+
+use Psr\Log\LoggerInterface;
+use OC\Share20\LegacyHooks;
+use OC\Share20\Manager;
+use OC\EventDispatcher\EventDispatcher;
+use OCA\Files_Sharing\AppInfo\Application;
+use OCA\Files_Sharing\SharedStorage;
+use OCP\Constants;
+use OCP\EventDispatcher\GenericEvent;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\File;
+use OCP\Files\Folder;
+use OCP\Files\IRootFolder;
+use OCP\Files\Storage\IStorage;
+use OCP\IServerContainer;
+use OCP\IUser;
+use OCP\IUserSession;
+use OCP\Share\IAttributes;
+use OCP\Share\IShare;
+use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
+use Test\TestCase;
+
+class ApplicationTest extends TestCase {
+
+ /** @var Application */
+ private $application;
+
+ /** @var IEventDispatcher */
+ private $eventDispatcher;
+
+ /** @var IUserSession */
+ private $userSession;
+
+ /** @var IRootFolder */
+ private $rootFolder;
+
+ /** @var Manager */ private $manager;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->application = new Application([]);
+
+ // FIXME: how to mock this one ??
+ $symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
+ $this->eventDispatcher = new EventDispatcher(
+ $symfonyDispatcher,
+ $this->createMock(IServerContainer::class),
+ $this->createMock(LoggerInterface::class)
+ );
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->rootFolder = $this->createMock(IRootFolder::class);
+
+ $this->application->registerDownloadEvents(
+ $this->eventDispatcher,
+ $this->userSession,
+ $this->rootFolder
+ );
+ }
+
+ public function providesDataForCanGet() {
+ // normal file (sender) - can download directly
+ $senderFileStorage = $this->createMock(IStorage::class);
+ $senderFileStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(false);
+ $senderFile = $this->createMock(File::class);
+ $senderFile->method('getStorage')->willReturn($senderFileStorage);
+ $senderUserFolder = $this->createMock(Folder::class);
+ $senderUserFolder->method('get')->willReturn($senderFile);
+
+ $result[] = [ '/bar.txt', $senderUserFolder, true ];
+
+ // shared file (receiver) with attribute secure-view-enabled set false -
+ // can download directly
+ $receiverFileShareAttributes = $this->createMock(IAttributes::class);
+ $receiverFileShareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(true);
+ $receiverFileShare = $this->createMock(IShare::class);
+ $receiverFileShare->method('getAttributes')->willReturn($receiverFileShareAttributes);
+ $receiverFileStorage = $this->createMock(SharedStorage::class);
+ $receiverFileStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(true);
+ $receiverFileStorage->method('getShare')->willReturn($receiverFileShare);
+ $receiverFile = $this->createMock(File::class);
+ $receiverFile->method('getStorage')->willReturn($receiverFileStorage);
+ $receiverUserFolder = $this->createMock(Folder::class);
+ $receiverUserFolder->method('get')->willReturn($receiverFile);
+
+ $result[] = [ '/share-bar.txt', $receiverUserFolder, true ];
+
+ // shared file (receiver) with attribute secure-view-enabled set true -
+ // cannot download directly
+ $secureReceiverFileShareAttributes = $this->createMock(IAttributes::class);
+ $secureReceiverFileShareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(false);
+ $secureReceiverFileShare = $this->createMock(IShare::class);
+ $secureReceiverFileShare->method('getAttributes')->willReturn($secureReceiverFileShareAttributes);
+ $secureReceiverFileStorage = $this->createMock(SharedStorage::class);
+ $secureReceiverFileStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(true);
+ $secureReceiverFileStorage->method('getShare')->willReturn($secureReceiverFileShare);
+ $secureReceiverFile = $this->createMock(File::class);
+ $secureReceiverFile->method('getStorage')->willReturn($secureReceiverFileStorage);
+ $secureReceiverUserFolder = $this->createMock(Folder::class);
+ $secureReceiverUserFolder->method('get')->willReturn($secureReceiverFile);
+
+ $result[] = [ '/secure-share-bar.txt', $secureReceiverUserFolder, false ];
+
+ return $result;
+ }
+
+ /**
+ * @dataProvider providesDataForCanGet
+ */
+ public function testCheckDirectCanBeDownloaded($path, $userFolder, $run) {
+ $user = $this->createMock(IUser::class);
+ $user->method("getUID")->willReturn("test");
+ $this->userSession->method("getUser")->willReturn($user);
+ $this->userSession->method("isLoggedIn")->willReturn(true);
+ $this->rootFolder->method('getUserFolder')->willReturn($userFolder);
+
+ // Simulate direct download of file
+ $event = new GenericEvent(null, [ 'path' => $path ]);
+ $this->eventDispatcher->dispatch('file.beforeGetDirect', $event);
+
+ $this->assertEquals($run, !$event->hasArgument('errorMessage'));
+ }
+
+ public function providesDataForCanZip() {
+ // Mock: Normal file/folder storage
+ $nonSharedStorage = $this->createMock(IStorage::class);
+ $nonSharedStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(false);
+
+ // Mock: Secure-view file/folder shared storage
+ $secureReceiverFileShareAttributes = $this->createMock(IAttributes::class);
+ $secureReceiverFileShareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(false);
+ $secureReceiverFileShare = $this->createMock(IShare::class);
+ $secureReceiverFileShare->method('getAttributes')->willReturn($secureReceiverFileShareAttributes);
+ $secureSharedStorage = $this->createMock(SharedStorage::class);
+ $secureSharedStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(true);
+ $secureSharedStorage->method('getShare')->willReturn($secureReceiverFileShare);
+
+ // 1. can download zipped 2 non-shared files inside non-shared folder
+ // 2. can download zipped non-shared folder
+ $sender1File = $this->createMock(File::class);
+ $sender1File->method('getStorage')->willReturn($nonSharedStorage);
+ $sender1Folder = $this->createMock(Folder::class);
+ $sender1Folder->method('getStorage')->willReturn($nonSharedStorage);
+ $sender1Folder->method('getDirectoryListing')->willReturn([$sender1File, $sender1File]);
+ $sender1RootFolder = $this->createMock(Folder::class);
+ $sender1RootFolder->method('getStorage')->willReturn($nonSharedStorage);
+ $sender1RootFolder->method('getDirectoryListing')->willReturn([$sender1Folder]);
+ $sender1UserFolder = $this->createMock(Folder::class);
+ $sender1UserFolder->method('get')->willReturn($sender1RootFolder);
+
+ $return[] = [ '/folder', ['bar1.txt', 'bar2.txt'], $sender1UserFolder, true ];
+ $return[] = [ '/', 'folder', $sender1UserFolder, true ];
+
+ // 3. cannot download zipped 1 non-shared file and 1 secure-shared inside non-shared folder
+ $receiver1File = $this->createMock(File::class);
+ $receiver1File->method('getStorage')->willReturn($nonSharedStorage);
+ $receiver1SecureFile = $this->createMock(File::class);
+ $receiver1SecureFile->method('getStorage')->willReturn($secureSharedStorage);
+ $receiver1Folder = $this->createMock(Folder::class);
+ $receiver1Folder->method('getStorage')->willReturn($nonSharedStorage);
+ $receiver1Folder->method('getDirectoryListing')->willReturn([$receiver1File, $receiver1SecureFile]);
+ $receiver1RootFolder = $this->createMock(Folder::class);
+ $receiver1RootFolder->method('getStorage')->willReturn($nonSharedStorage);
+ $receiver1RootFolder->method('getDirectoryListing')->willReturn([$receiver1Folder]);
+ $receiver1UserFolder = $this->createMock(Folder::class);
+ $receiver1UserFolder->method('get')->willReturn($receiver1RootFolder);
+
+ $return[] = [ '/folder', ['secured-bar1.txt', 'bar2.txt'], $receiver1UserFolder, false ];
+
+ // 4. cannot download zipped secure-shared folder
+ $receiver2Folder = $this->createMock(Folder::class);
+ $receiver2Folder->method('getStorage')->willReturn($secureSharedStorage);
+ $receiver2RootFolder = $this->createMock(Folder::class);
+ $receiver2RootFolder->method('getStorage')->willReturn($nonSharedStorage);
+ $receiver2RootFolder->method('getDirectoryListing')->willReturn([$receiver2Folder]);
+ $receiver2UserFolder = $this->createMock(Folder::class);
+ $receiver2UserFolder->method('get')->willReturn($receiver2RootFolder);
+
+ $return[] = [ '/', 'secured-folder', $receiver2UserFolder, false ];
+
+ return $return;
+ }
+
+ /**
+ * @dataProvider providesDataForCanZip
+ */
+ public function testCheckZipCanBeDownloaded($dir, $files, $userFolder, $run) {
+ $user = $this->createMock(IUser::class);
+ $user->method("getUID")->willReturn("test");
+ $this->userSession->method("getUser")->willReturn($user);
+ $this->userSession->method("isLoggedIn")->willReturn(true);
+
+ $this->rootFolder->method('getUserFolder')->with("test")->willReturn($userFolder);
+
+ // Simulate zip download of folder folder
+ $event = new GenericEvent(null, ['dir' => $dir, 'files' => $files, 'run' => true]);
+ $this->eventDispatcher->dispatch('file.beforeCreateZip', $event);
+
+ $this->assertEquals($run, $event->getArgument('run'));
+ $this->assertEquals($run, !$event->hasArgument('errorMessage'));
+ }
+
+ public function testCheckFileUserNotFound() {
+ $this->userSession->method("isLoggedIn")->willReturn(false);
+
+ // Simulate zip download of folder folder
+ $event = new GenericEvent(null, ['dir' => '/test', 'files' => ['test.txt'], 'run' => true]);
+ $this->eventDispatcher->dispatch('file.beforeCreateZip', $event);
+
+ // It should run as this would restrict e.g. share links otherwise
+ $this->assertTrue($event->getArgument('run'));
+ $this->assertFalse($event->hasArgument('errorMessage'));
+ }
+}
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index fd5580f19a7..f6568415727 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -124,7 +124,11 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(true);
$this->shareManager
->expects($this->any())
- ->method('shareProviderExists')->willReturn(true);
+ ->method('shareProviderExists')->willReturn(true);
+ $this->shareManager
+ ->expects($this->any())
+ ->method('newShare')
+ ->willReturn($this->newShare());
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->request = $this->createMock(IRequest::class);
@@ -194,6 +198,25 @@ class ShareAPIControllerTest extends TestCase {
}
+ private function mockShareAttributes() {
+ $formattedShareAttributes = [
+ [
+ [
+ 'scope' => 'permissions',
+ 'key' => 'download',
+ 'enabled' => true
+ ]
+ ]
+ ];
+
+ $shareAttributes = $this->createMock(IShareAttributes::class);
+ $shareAttributes->method('toArray')->willReturn($formattedShareAttributes);
+ $shareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(true);
+
+ // send both IShare attributes class and expected json string
+ return [$shareAttributes, \json_encode($formattedShareAttributes)];
+ }
+
public function testDeleteShareShareNotFound() {
$this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class);
$this->expectExceptionMessage('Wrong share ID, share does not exist');
@@ -505,7 +528,7 @@ class ShareAPIControllerTest extends TestCase {
public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
$shareTime, $expiration, $parent, $target, $mail_send, $note = '', $token = null,
- $password = null, $label = '') {
+ $password = null, $label = '', $attributes = null) {
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getId')->willReturn($id);
$share->method('getShareType')->willReturn($shareType);
@@ -516,6 +539,7 @@ class ShareAPIControllerTest extends TestCase {
$share->method('getPermissions')->willReturn($permissions);
$share->method('getNote')->willReturn($note);
$share->method('getLabel')->willReturn($label);
+ $share->method('getAttributes')->willReturn($attributes);
$time = new \DateTime();
$time->setTimestamp($shareTime);
$share->method('getShareTime')->willReturn($time);
@@ -565,6 +589,8 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getParent')->willReturn($parentFolder);
$folder->method('getMimeType')->willReturn('myFolderMimeType');
+ [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes();
+
// File shared with user
$share = $this->createShare(
100,
@@ -579,7 +605,8 @@ class ShareAPIControllerTest extends TestCase {
6,
'target',
0,
- 'personal note'
+ 'personal note',
+ $shareAttributes,
);
$expected = [
'id' => 100,
@@ -597,6 +624,7 @@ class ShareAPIControllerTest extends TestCase {
'token' => null,
'expiration' => null,
'permissions' => 4,
+ 'attributes' => $shareAttributesReturnJson,
'stime' => 5,
'parent' => null,
'storage_id' => 'STORAGE',
@@ -630,7 +658,8 @@ class ShareAPIControllerTest extends TestCase {
6,
'target',
0,
- 'personal note'
+ 'personal note',
+ $shareAttributes,
);
$expected = [
'id' => 101,
@@ -647,6 +676,7 @@ class ShareAPIControllerTest extends TestCase {
'token' => null,
'expiration' => null,
'permissions' => 4,
+ 'attributes' => $shareAttributesReturnJson,
'stime' => 5,
'parent' => null,
'storage_id' => 'STORAGE',
@@ -702,6 +732,7 @@ class ShareAPIControllerTest extends TestCase {
'token' => 'token',
'expiration' => '2000-01-02 00:00:00',
'permissions' => 4,
+ 'attributes' => null,
'stime' => 5,
'parent' => null,
'storage_id' => 'STORAGE',
@@ -3725,7 +3756,7 @@ class ShareAPIControllerTest extends TestCase {
$recipient = $this->getMockBuilder(IUser::class)->getMock();
$recipient->method('getDisplayName')->willReturn('recipientDN');
$recipient->method('getSystemEMailAddress')->willReturn('recipient');
-
+ [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes();
$result = [];
@@ -3735,6 +3766,7 @@ class ShareAPIControllerTest extends TestCase {
->setSharedBy('initiator')
->setShareOwner('owner')
->setPermissions(\OCP\Constants::PERMISSION_READ)
+ ->setAttributes($shareAttributes)
->setNode($file)
->setShareTime(new \DateTime('2000-01-01T00:01:02'))
->setTarget('myTarget')
@@ -3749,6 +3781,7 @@ class ShareAPIControllerTest extends TestCase {
'uid_owner' => 'initiator',
'displayname_owner' => 'initiator',
'permissions' => 1,
+ 'attributes' => $shareAttributesReturnJson,
'stime' => 946684862,
'parent' => null,
'expiration' => null,
@@ -3785,6 +3818,7 @@ class ShareAPIControllerTest extends TestCase {
'uid_owner' => 'initiator',
'displayname_owner' => 'initiatorDN',
'permissions' => 1,
+ 'attributes' => $shareAttributesReturnJson,
'stime' => 946684862,
'parent' => null,
'expiration' => null,
@@ -3837,6 +3871,7 @@ class ShareAPIControllerTest extends TestCase {
'uid_owner' => 'initiator',
'displayname_owner' => 'initiator',
'permissions' => 1,
+ 'attributes' => null,
'stime' => 946684862,
'parent' => null,
'expiration' => null,
@@ -3885,6 +3920,7 @@ class ShareAPIControllerTest extends TestCase {
'uid_owner' => 'initiator',
'displayname_owner' => 'initiator',
'permissions' => 1,
+ 'attributes' => null,
'stime' => 946684862,
'parent' => null,
'expiration' => null,
@@ -3935,6 +3971,7 @@ class ShareAPIControllerTest extends TestCase {
'uid_owner' => 'initiator',
'displayname_owner' => 'initiator',
'permissions' => 1,
+ 'attributes' => null,
'stime' => 946684862,
'parent' => null,
'expiration' => null,
@@ -4030,6 +4067,7 @@ class ShareAPIControllerTest extends TestCase {
'uid_owner' => 'initiator',
'displayname_owner' => 'initiator',
'permissions' => 1,
+ 'attributes' => null,
'stime' => 946684862,
'parent' => null,
'expiration' => '2001-01-02 00:00:00',
@@ -4228,6 +4266,7 @@ class ShareAPIControllerTest extends TestCase {
'uid_owner' => 'initiator',
'displayname_owner' => 'initiator',
'permissions' => 1,
+ 'attributes' => null,
'stime' => 946684862,
'parent' => null,
'expiration' => null,
diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php
index 53bea929def..740c7c89eb7 100644
--- a/apps/files_sharing/tests/MountProviderTest.php
+++ b/apps/files_sharing/tests/MountProviderTest.php
@@ -81,12 +81,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) {
$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 +139,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 +199,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 +228,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 +256,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 +269,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 +282,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 +293,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 +305,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 +314,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
],
@@ -400,6 +428,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());
+ }
}
}
}