aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/tests/Controller')
-rw-r--r--apps/files_sharing/tests/Controller/ExternalShareControllerTest.php1
-rw-r--r--apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php37
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php922
-rw-r--r--apps/files_sharing/tests/Controller/ShareControllerTest.php82
-rw-r--r--apps/files_sharing/tests/Controller/ShareInfoControllerTest.php22
-rw-r--r--apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php34
6 files changed, 697 insertions, 401 deletions
diff --git a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
index 5e8e32c06d8..7e054d9a6dc 100644
--- a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php b/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php
index bd64cfc60b4..f49d839e8d4 100644
--- a/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php
+++ b/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -18,8 +19,8 @@ use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IPreview;
use OCP\IRequest;
use OCP\ISession;
+use OCP\Preview\IMimeIconProvider;
use OCP\Share\Exceptions\ShareNotFound;
-use OCP\Share\IAttributes;
use OCP\Share\IManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
@@ -52,7 +53,8 @@ class PublicPreviewControllerTest extends TestCase {
$this->request,
$this->shareManager,
$this->createMock(ISession::class),
- $this->previewManager
+ $this->previewManager,
+ $this->createMock(IMimeIconProvider::class),
);
}
@@ -112,12 +114,8 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getPermissions')
->willReturn(Constants::PERMISSION_READ);
- $attributes = $this->createMock(IAttributes::class);
- $attributes->method('getAttribute')
- ->with('permissions', 'download')
+ $share->method('canSeeContent')
->willReturn(false);
- $share->method('getAttributes')
- ->willReturn($attributes);
$res = $this->controller->getPreview('token', 'file', 10, 10);
$expected = new DataResponse([], Http::STATUS_FORBIDDEN);
@@ -134,15 +132,11 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getPermissions')
->willReturn(Constants::PERMISSION_READ);
- $attributes = $this->createMock(IAttributes::class);
- $attributes->method('getAttribute')
- ->with('permissions', 'download')
+ $share->method('canSeeContent')
->willReturn(false);
- $share->method('getAttributes')
- ->willReturn($attributes);
$this->request->method('getHeader')
- ->with('X-NC-Preview')
+ ->with('x-nc-preview')
->willReturn('true');
$file = $this->createMock(File::class);
@@ -174,15 +168,11 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getPermissions')
->willReturn(Constants::PERMISSION_READ);
- $attributes = $this->createMock(IAttributes::class);
- $attributes->method('getAttribute')
- ->with('permissions', 'download')
+ $share->method('canSeeContent')
->willReturn(true);
- $share->method('getAttributes')
- ->willReturn($attributes);
$this->request->method('getHeader')
- ->with('X-NC-Preview')
+ ->with('x-nc-preview')
->willReturn('true');
$file = $this->createMock(File::class);
@@ -218,6 +208,9 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getNode')
->willReturn($file);
+ $share->method('canSeeContent')
+ ->willReturn(true);
+
$preview = $this->createMock(ISimpleFile::class);
$preview->method('getName')->willReturn('name');
$preview->method('getMTime')->willReturn(42);
@@ -247,6 +240,9 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getNode')
->willReturn($folder);
+ $share->method('canSeeContent')
+ ->willReturn(true);
+
$folder->method('get')
->with($this->equalTo('file'))
->willThrowException(new NotFoundException());
@@ -270,6 +266,9 @@ class PublicPreviewControllerTest extends TestCase {
$share->method('getNode')
->willReturn($folder);
+ $share->method('canSeeContent')
+ ->willReturn(true);
+
$file = $this->createMock(File::class);
$folder->method('get')
->with($this->equalTo('file'))
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index f8c316cd2e9..e6be0342c26 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,6 +7,7 @@
*/
namespace OCA\Files_Sharing\Tests\Controller;
+use OCA\Federation\TrustedServers;
use OCA\Files_Sharing\Controller\ShareAPIController;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
@@ -21,6 +23,7 @@ use OCP\Files\Mount\IMountPoint;
use OCP\Files\Mount\IShareOwnerlessMount;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeZone;
use OCP\IGroup;
@@ -28,12 +31,15 @@ use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
+use OCP\ITagManager;
+use OCP\ITags;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Mail\IMailer;
+use OCP\Server;
use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IAttributes as IShareAttributes;
@@ -67,6 +73,7 @@ class ShareAPIControllerTest extends TestCase {
private IURLGenerator&MockObject $urlGenerator;
private IL10N&MockObject $l;
private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
private IAppManager&MockObject $appManager;
private ContainerInterface&MockObject $serverContainer;
private IUserStatusManager&MockObject $userStatusManager;
@@ -75,6 +82,8 @@ class ShareAPIControllerTest extends TestCase {
private LoggerInterface&MockObject $logger;
private IProviderFactory&MockObject $factory;
private IMailer&MockObject $mailer;
+ private ITagManager&MockObject $tagManager;
+ private TrustedServers&MockObject $trustedServers;
protected function setUp(): void {
$this->shareManager = $this->createMock(IManager::class);
@@ -98,6 +107,7 @@ class ShareAPIControllerTest extends TestCase {
return vsprintf($text, $parameters);
});
$this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->serverContainer = $this->createMock(ContainerInterface::class);
$this->userStatusManager = $this->createMock(IUserStatusManager::class);
@@ -110,6 +120,8 @@ class ShareAPIControllerTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->factory = $this->createMock(IProviderFactory::class);
$this->mailer = $this->createMock(IMailer::class);
+ $this->tagManager = $this->createMock(ITagManager::class);
+ $this->trustedServers = $this->createMock(TrustedServers::class);
$this->ocs = new ShareAPIController(
$this->appName,
@@ -121,6 +133,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -129,8 +142,11 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
- $this->currentUser,
+ $this->tagManager,
+ $this->trustedServers,
+ $this->currentUser
);
+
}
/**
@@ -148,6 +164,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -156,13 +173,15 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
+ $this->trustedServers,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
}
private function newShare() {
- return \OCP\Server::get(IManager::class)->newShare();
+ return Server::get(IManager::class)->newShare();
}
@@ -246,9 +265,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with($share->getNodeId())
- ->willReturn($node);
+ ->willReturn([$node]);
$this->shareManager
->expects($this->once())
@@ -264,7 +283,7 @@ class ShareAPIControllerTest extends TestCase {
$node->expects($this->once())
->method('lock')
->with(ILockingProvider::LOCK_SHARED)
- ->will($this->throwException(new LockedException('mypath')));
+ ->willThrowException(new LockedException('mypath'));
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
@@ -411,9 +430,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with($share->getNodeId())
- ->willReturn($share->getNode());
+ ->willReturn([$share->getNode()]);
$this->shareManager->expects($this->once())
->method('deleteFromSelf')
@@ -474,9 +493,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with($share->getNodeId())
- ->willReturn($share->getNode());
+ ->willReturn([$share->getNode()]);
$this->shareManager->expects($this->never())
->method('deleteFromSelf');
@@ -506,9 +525,10 @@ class ShareAPIControllerTest extends TestCase {
->willReturn($mount);
$userFolder = $this->createMock(Folder::class);
- $userFolder
- ->expects($this->exactly(2))
- ->method('getFirstNodeById')
+ $userFolder->method('getById')
+ ->with(2)
+ ->willReturn([$file]);
+ $userFolder->method('getFirstNodeById')
->with(2)
->willReturn($file);
@@ -584,9 +604,9 @@ class ShareAPIControllerTest extends TestCase {
$share->method('getToken')->willReturn($token);
$share->method('getPassword')->willReturn($password);
- if ($shareType === IShare::TYPE_USER ||
- $shareType === IShare::TYPE_GROUP ||
- $shareType === IShare::TYPE_LINK) {
+ if ($shareType === IShare::TYPE_USER
+ || $shareType === IShare::TYPE_GROUP
+ || $shareType === IShare::TYPE_LINK) {
$share->method('getFullId')->willReturn('ocinternal:' . $id);
}
@@ -815,9 +835,7 @@ class ShareAPIControllerTest extends TestCase {
return $data;
}
- /**
- * @dataProvider dataGetShare
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShare')]
public function testGetShare(IShare $share, array $result): void {
/** @var ShareAPIController&MockObject $ocs */
$ocs = $this->getMockBuilder(ShareAPIController::class)
@@ -831,6 +849,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -839,9 +858,11 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
+ $this->trustedServers,
$this->currentUser,
-
- ])->setMethods(['canAccessShare'])
+ ])
+ ->onlyMethods(['canAccessShare'])
->getMock();
$ocs->expects($this->any())
@@ -862,7 +883,6 @@ class ShareAPIControllerTest extends TestCase {
$userFolder->method('getById')
->with($share->getNodeId())
->willReturn([$share->getNode()]);
-
$userFolder->method('getFirstNodeById')
->with($share->getNodeId())
->willReturn($share->getNode());
@@ -901,9 +921,8 @@ class ShareAPIControllerTest extends TestCase {
]);
$this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC'));
- $d = $ocs->getShare($share->getId())->getData()[0];
-
- $this->assertEquals($result, $ocs->getShare($share->getId())->getData()[0]);
+ $data = $ocs->getShare($share->getId())->getData()[0];
+ $this->assertEquals($result, $data);
}
@@ -911,7 +930,7 @@ class ShareAPIControllerTest extends TestCase {
$this->expectException(OCSNotFoundException::class);
$this->expectExceptionMessage('Wrong share ID, share does not exist');
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setSharedBy('initiator')
->setSharedWith('recipient')
->setShareOwner('owner');
@@ -942,7 +961,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getDirectoryListing')
->willReturn([$file1, $file2]);
- $file1UserShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file1UserShareOwner = Server::get(IManager::class)->newShare();
$file1UserShareOwner->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -956,7 +975,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_USER,
];
- $file1UserShareInitiator = \OCP\Server::get(IManager::class)->newShare();
+ $file1UserShareInitiator = Server::get(IManager::class)->newShare();
$file1UserShareInitiator->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('currentUser')
@@ -970,7 +989,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_USER,
];
- $file1UserShareRecipient = \OCP\Server::get(IManager::class)->newShare();
+ $file1UserShareRecipient = Server::get(IManager::class)->newShare();
$file1UserShareRecipient->setShareType(IShare::TYPE_USER)
->setSharedWith('currentUser')
->setSharedBy('initiator')
@@ -984,7 +1003,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_USER,
];
- $file1UserShareOther = \OCP\Server::get(IManager::class)->newShare();
+ $file1UserShareOther = Server::get(IManager::class)->newShare();
$file1UserShareOther->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -998,7 +1017,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_USER,
];
- $file1GroupShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file1GroupShareOwner = Server::get(IManager::class)->newShare();
$file1GroupShareOwner->setShareType(IShare::TYPE_GROUP)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1012,7 +1031,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_GROUP,
];
- $file1GroupShareRecipient = \OCP\Server::get(IManager::class)->newShare();
+ $file1GroupShareRecipient = Server::get(IManager::class)->newShare();
$file1GroupShareRecipient->setShareType(IShare::TYPE_GROUP)
->setSharedWith('currentUserGroup')
->setSharedBy('initiator')
@@ -1026,7 +1045,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_GROUP,
];
- $file1GroupShareOther = \OCP\Server::get(IManager::class)->newShare();
+ $file1GroupShareOther = Server::get(IManager::class)->newShare();
$file1GroupShareOther->setShareType(IShare::TYPE_GROUP)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1035,7 +1054,7 @@ class ShareAPIControllerTest extends TestCase {
->setNode($file1)
->setId(108);
- $file1LinkShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file1LinkShareOwner = Server::get(IManager::class)->newShare();
$file1LinkShareOwner->setShareType(IShare::TYPE_LINK)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1049,7 +1068,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_LINK,
];
- $file1EmailShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file1EmailShareOwner = Server::get(IManager::class)->newShare();
$file1EmailShareOwner->setShareType(IShare::TYPE_EMAIL)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1063,7 +1082,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_EMAIL,
];
- $file1CircleShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file1CircleShareOwner = Server::get(IManager::class)->newShare();
$file1CircleShareOwner->setShareType(IShare::TYPE_CIRCLE)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1077,7 +1096,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_CIRCLE,
];
- $file1RoomShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file1RoomShareOwner = Server::get(IManager::class)->newShare();
$file1RoomShareOwner->setShareType(IShare::TYPE_ROOM)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1091,7 +1110,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_ROOM,
];
- $file1RemoteShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file1RemoteShareOwner = Server::get(IManager::class)->newShare();
$file1RemoteShareOwner->setShareType(IShare::TYPE_REMOTE)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1106,7 +1125,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_REMOTE,
];
- $file1RemoteGroupShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file1RemoteGroupShareOwner = Server::get(IManager::class)->newShare();
$file1RemoteGroupShareOwner->setShareType(IShare::TYPE_REMOTE_GROUP)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1121,7 +1140,7 @@ class ShareAPIControllerTest extends TestCase {
'share_type' => IShare::TYPE_REMOTE_GROUP,
];
- $file2UserShareOwner = \OCP\Server::get(IManager::class)->newShare();
+ $file2UserShareOwner = Server::get(IManager::class)->newShare();
$file2UserShareOwner->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -1449,9 +1468,7 @@ class ShareAPIControllerTest extends TestCase {
return $data;
}
- /**
- * @dataProvider dataGetShares
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShares')]
public function testGetShares(array $getSharesParameters, array $shares, array $extraShareTypes, array $expected): void {
/** @var ShareAPIController&MockObject $ocs */
$ocs = $this->getMockBuilder(ShareAPIController::class)
@@ -1465,6 +1482,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -1473,6 +1491,8 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])
->onlyMethods(['formatShare'])
@@ -1534,81 +1554,125 @@ class ShareAPIControllerTest extends TestCase {
$this->assertEquals($expected, $result->getData());
}
- public function testCanAccessShare(): void {
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ public function testCanAccessShareAsOwner(): void {
+ $share = $this->createMock(IShare::class);
$share->method('getShareOwner')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ public function testCanAccessShareAsSharer(): void {
+ $share = $this->createMock(IShare::class);
$share->method('getSharedBy')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ public function testCanAccessShareAsSharee(): void {
+ $share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
$share->method('getSharedWith')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
- $file = $this->getMockBuilder(File::class)->getMock();
+ public function testCannotAccessLinkShare(): void {
+ $share = $this->createMock(IShare::class);
+ $share->method('getShareType')->willReturn(IShare::TYPE_LINK);
+ $share->method('getNodeId')->willReturn(42);
- $userFolder = $this->getMockBuilder(Folder::class)->getMock();
+ $userFolder = $this->createMock(Folder::class);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
+ $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareWithPermissions')]
+ public function testCanAccessShareWithPermissions(int $permissions, bool $expected): void {
+ $share = $this->createMock(IShare::class);
+ $share->method('getShareType')->willReturn(IShare::TYPE_USER);
+ $share->method('getSharedWith')->willReturn($this->createMock(IUser::class));
+ $share->method('getNodeId')->willReturn(42);
+
+ $file = $this->createMock(File::class);
+
+ $userFolder = $this->getMockBuilder(Folder::class)->getMock();
$userFolder->method('getFirstNodeById')
->with($share->getNodeId())
->willReturn($file);
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$file]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$file->method('getPermissions')
- ->will($this->onConsecutiveCalls(Constants::PERMISSION_SHARE, Constants::PERMISSION_READ));
+ ->willReturn($permissions);
- // getPermissions -> share
- $share = $this->getMockBuilder(IShare::class)->getMock();
- $share->method('getShareType')->willReturn(IShare::TYPE_USER);
- $share->method('getSharedWith')->willReturn($this->getMockBuilder(IUser::class)->getMock());
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ if ($expected) {
+ $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ } else {
+ $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
+ }
- // getPermissions -> read
- $share = $this->getMockBuilder(IShare::class)->getMock();
- $share->method('getShareType')->willReturn(IShare::TYPE_USER);
- $share->method('getSharedWith')->willReturn($this->getMockBuilder(IUser::class)->getMock());
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ public static function dataCanAccessShareWithPermissions(): array {
+ return [
+ [Constants::PERMISSION_SHARE, true],
+ [Constants::PERMISSION_READ, false],
+ [Constants::PERMISSION_READ | Constants::PERMISSION_SHARE, true],
+ ];
+ }
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareAsGroupMember')]
+ public function testCanAccessShareAsGroupMember(string $group, bool $expected): void {
+ $share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
- $share->method('getSharedWith')->willReturn('group');
+ $share->method('getSharedWith')->willReturn($group);
+ $share->method('getNodeId')->willReturn(42);
+
+ $file = $this->createMock(File::class);
+
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getFirstNodeById')
+ ->with($share->getNodeId())
+ ->willReturn($file);
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$file]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
->with($this->currentUser)
->willReturn($user);
- $group = $this->getMockBuilder(IGroup::class)->getMock();
+ $group = $this->createMock(IGroup::class);
$group->method('inGroup')->with($user)->willReturn(true);
- $group2 = $this->getMockBuilder(IGroup::class)->getMock();
+ $group2 = $this->createMock(IGroup::class);
$group2->method('inGroup')->with($user)->willReturn(false);
$this->groupManager->method('get')->willReturnMap([
['group', $group],
['group2', $group2],
- ['groupnull', null],
+ ['group-null', null],
]);
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
-
- $share = $this->createMock(IShare::class);
- $share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
- $share->method('getSharedWith')->willReturn('group2');
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
- // null group
- $share = $this->createMock(IShare::class);
- $share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
- $share->method('getSharedWith')->willReturn('groupnull');
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ if ($expected) {
+ $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ } else {
+ $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ }
+ }
- $share = $this->createMock(IShare::class);
- $share->method('getShareType')->willReturn(IShare::TYPE_LINK);
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ public static function dataCanAccessShareAsGroupMember(): array {
+ return [
+ ['group', true],
+ ['group2', false],
+ ['group-null', false],
+ ];
}
public function dataCanAccessRoomShare() {
@@ -1638,22 +1702,22 @@ class ShareAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataCanAccessRoomShare
*
* @param bool $expects
* @param IShare $share
* @param bool helperAvailable
* @param bool canAccessShareByHelper
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessRoomShare')]
public function testCanAccessRoomShare(bool $expected, IShare $share, bool $helperAvailable, bool $canAccessShareByHelper): void {
$userFolder = $this->getMockBuilder(Folder::class)->getMock();
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with($share->getNodeId())
- ->willReturn($share->getNode());
+ ->willReturn([$share->getNode()]);
if (!$helperAvailable) {
$this->appManager->method('isEnabledForUser')
@@ -1664,8 +1728,11 @@ class ShareAPIControllerTest extends TestCase {
->with('spreed')
->willReturn(true);
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['canAccessShare'])
+ // This is not possible anymore with PHPUnit 10+
+ // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
+ // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ $helper = $this->getMockBuilder(\stdClass::class)
+ ->addMethods(['canAccessShare'])
->getMock();
$helper->method('canAccessShare')
->with($share, $this->currentUser)
@@ -1701,7 +1768,7 @@ class ShareAPIControllerTest extends TestCase {
$userFolder->expects($this->once())
->method('get')
->with('invalid-path')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->ocs->createShare('invalid-path');
}
@@ -1741,8 +1808,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('newShare')->willReturn($share);
[$userFolder, $path] = $this->getNonSharedUserFile();
- $this->rootFolder->expects($this->exactly(2))
- ->method('getUserFolder')
+ $this->rootFolder->method('getUserFolder')
->with('currentUser')
->willReturn($userFolder);
@@ -1769,8 +1835,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('newShare')->willReturn($share);
[$userFolder, $path] = $this->getNonSharedUserFile();
- $this->rootFolder->expects($this->exactly(2))
- ->method('getUserFolder')
+ $this->rootFolder->method('getUserFolder')
->with('currentUser')
->willReturn($userFolder);
@@ -1806,6 +1871,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -1814,8 +1880,10 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
+ $this->trustedServers,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
[$userFolder, $path] = $this->getNonSharedUserFile();
@@ -1839,15 +1907,15 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('createShare')
->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getPermissions() === (
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE
- ) &&
- $share->getShareType() === IShare::TYPE_USER &&
- $share->getSharedWith() === 'validUser' &&
- $share->getSharedBy() === 'currentUser';
+ return $share->getNode() === $path
+ && $share->getPermissions() === (
+ Constants::PERMISSION_ALL
+ & ~Constants::PERMISSION_DELETE
+ & ~Constants::PERMISSION_CREATE
+ )
+ && $share->getShareType() === IShare::TYPE_USER
+ && $share->getSharedWith() === 'validUser'
+ && $share->getSharedBy() === 'currentUser';
}))
->willReturnArgument(0);
@@ -1869,8 +1937,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('allowGroupSharing')->willReturn(true);
[$userFolder, $path] = $this->getNonSharedUserFile();
- $this->rootFolder->expects($this->exactly(2))
- ->method('getUserFolder')
+ $this->rootFolder->method('getUserFolder')
->with('currentUser')
->willReturn($userFolder);
@@ -1904,6 +1971,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -1912,8 +1980,10 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
+ $this->trustedServers,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
$this->request
@@ -1950,11 +2020,11 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('createShare')
->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getShareType() === IShare::TYPE_GROUP &&
- $share->getSharedWith() === 'validGroup' &&
- $share->getSharedBy() === 'currentUser';
+ return $share->getNode() === $path
+ && $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getShareType() === IShare::TYPE_GROUP
+ && $share->getSharedWith() === 'validGroup'
+ && $share->getSharedBy() === 'currentUser';
}))
->willReturnArgument(0);
@@ -1974,8 +2044,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('newShare')->willReturn($share);
[$userFolder, $path] = $this->getNonSharedUserFolder();
- $this->rootFolder->expects($this->exactly(2))
- ->method('getUserFolder')
+ $this->rootFolder->method('getUserFolder')
->with('currentUser')
->willReturn($userFolder);
@@ -2021,7 +2090,7 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
$this->shareManager->method('shareApiAllowLinks')->willReturn(false);
@@ -2047,7 +2116,7 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true');
@@ -2068,13 +2137,13 @@ class ShareAPIControllerTest extends TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(42);
$file->method('getStorage')->willReturn($storage);
-
+
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($file);
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
@@ -2098,18 +2167,18 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
$this->shareManager->expects($this->once())->method('createShare')->with(
$this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getShareType() === IShare::TYPE_LINK &&
- $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getSharedBy() === 'currentUser' &&
- $share->getPassword() === null &&
- $share->getExpirationDate() === null;
+ return $share->getNode() === $path
+ && $share->getShareType() === IShare::TYPE_LINK
+ && $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getSharedBy() === 'currentUser'
+ && $share->getPassword() === null
+ && $share->getExpirationDate() === null;
})
)->willReturnArgument(0);
@@ -2137,7 +2206,7 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
@@ -2176,7 +2245,7 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
@@ -2184,13 +2253,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('createShare')->with(
$this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getShareType() === IShare::TYPE_LINK &&
- $share->getPermissions() === (Constants::PERMISSION_ALL & ~(Constants::PERMISSION_SHARE)) &&
- $share->getSharedBy() === 'currentUser' &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === null;
+ return $share->getNode() === $path
+ && $share->getShareType() === IShare::TYPE_LINK
+ && $share->getPermissions() === (Constants::PERMISSION_ALL & ~(Constants::PERMISSION_SHARE))
+ && $share->getSharedBy() === 'currentUser'
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === null;
})
)->willReturnArgument(0);
@@ -2223,7 +2292,7 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
@@ -2261,7 +2330,7 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
@@ -2270,12 +2339,12 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2000-01-01');
$date->setTime(0, 0, 0);
- return $share->getNode() === $path &&
- $share->getShareType() === IShare::TYPE_LINK &&
- $share->getPermissions() === Constants::PERMISSION_READ | Constants::PERMISSION_SHARE &&
- $share->getSharedBy() === 'currentUser' &&
- $share->getPassword() === null &&
- $share->getExpirationDate() == $date;
+ return $share->getNode() === $path
+ && $share->getShareType() === IShare::TYPE_LINK
+ && $share->getPermissions() === Constants::PERMISSION_READ | Constants::PERMISSION_SHARE
+ && $share->getSharedBy() === 'currentUser'
+ && $share->getPassword() === null
+ && $share->getExpirationDate() == $date;
})
)->willReturnArgument(0);
@@ -2307,7 +2376,7 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getById')
->willReturn([]);
- $this->shareManager->method('newShare')->willReturn(\OCP\Server::get(IManager::class)->newShare());
+ $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
@@ -2330,6 +2399,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -2338,8 +2408,10 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
+ $this->trustedServers,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
[$userFolder, $path] = $this->getNonSharedUserFile();
@@ -2363,15 +2435,15 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('createShare')
->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getPermissions() === (
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE
- ) &&
- $share->getShareType() === IShare::TYPE_REMOTE &&
- $share->getSharedWith() === 'user@example.org' &&
- $share->getSharedBy() === 'currentUser';
+ return $share->getNode() === $path
+ && $share->getPermissions() === (
+ Constants::PERMISSION_ALL
+ & ~Constants::PERMISSION_DELETE
+ & ~Constants::PERMISSION_CREATE
+ )
+ && $share->getShareType() === IShare::TYPE_REMOTE
+ && $share->getSharedWith() === 'user@example.org'
+ && $share->getSharedBy() === 'currentUser';
}))
->willReturnArgument(0);
@@ -2400,6 +2472,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -2408,8 +2481,10 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
+ $this->trustedServers,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
[$userFolder, $path] = $this->getNonSharedUserFile();
@@ -2433,15 +2508,15 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('createShare')
->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path &&
- $share->getPermissions() === (
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE
- ) &&
- $share->getShareType() === IShare::TYPE_REMOTE_GROUP &&
- $share->getSharedWith() === 'group@example.org' &&
- $share->getSharedBy() === 'currentUser';
+ return $share->getNode() === $path
+ && $share->getPermissions() === (
+ Constants::PERMISSION_ALL
+ & ~Constants::PERMISSION_DELETE
+ & ~Constants::PERMISSION_CREATE
+ )
+ && $share->getShareType() === IShare::TYPE_REMOTE_GROUP
+ && $share->getSharedWith() === 'group@example.org'
+ && $share->getSharedBy() === 'currentUser';
}))
->willReturnArgument(0);
@@ -2481,16 +2556,19 @@ class ShareAPIControllerTest extends TestCase {
->with('spreed')
->willReturn(true);
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['createShare'])
+ // This is not possible anymore with PHPUnit 10+
+ // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
+ // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ $helper = $this->getMockBuilder(\stdClass::class)
+ ->addMethods(['createShare'])
->getMock();
$helper->method('createShare')
->with(
$share,
'recipientRoom',
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE,
+ Constants::PERMISSION_ALL
+ & ~Constants::PERMISSION_DELETE
+ & ~Constants::PERMISSION_CREATE,
''
)->willReturnCallback(
function ($share): void {
@@ -2531,8 +2609,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('newShare')->willReturn($share);
[$userFolder, $path] = $this->getNonSharedUserFolder();
- $this->rootFolder->expects($this->exactly(2))
- ->method('getUserFolder')
+ $this->rootFolder->method('getUserFolder')
->with('currentUser')
->willReturn($userFolder);
@@ -2569,8 +2646,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('newShare')->willReturn($share);
[$userFolder, $path] = $this->getNonSharedUserFile();
- $this->rootFolder->expects($this->exactly(2))
- ->method('getUserFolder')
+ $this->rootFolder->method('getUserFolder')
->with('currentUser')
->willReturn($userFolder);
@@ -2589,7 +2665,10 @@ class ShareAPIControllerTest extends TestCase {
->with('spreed')
->willReturn(true);
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ // This is not possible anymore with PHPUnit 10+
+ // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
+ // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ $helper = $this->getMockBuilder(\stdClass::class)
->addMethods(['createShare'])
->getMock();
$helper->method('createShare')
@@ -2618,7 +2697,7 @@ class ShareAPIControllerTest extends TestCase {
* TODO: Remove once proper solution is in place
*/
public function testCreateReshareOfFederatedMountNoDeletePermissions(): void {
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$this->shareManager->method('newShare')->willReturn($share);
/** @var ShareAPIController&MockObject $ocs */
@@ -2633,6 +2712,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -2641,8 +2721,10 @@ class ShareAPIControllerTest extends TestCase {
$this->logger,
$this->factory,
$this->mailer,
+ $this->tagManager,
+ $this->trustedServers,
$this->currentUser,
- ])->setMethods(['formatShare'])
+ ])->onlyMethods(['formatShare'])
->getMock();
$userFolder = $this->getMockBuilder(Folder::class)->getMock();
@@ -2703,9 +2785,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with($share->getNodeId())
- ->willReturn($share->getNode());
+ ->willReturn([$share->getNode()]);
$this->ocs->updateShare(42);
}
@@ -2778,14 +2860,14 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) {
- return $share->getPermissions() === Constants::PERMISSION_READ &&
- $share->getPassword() === null &&
- $share->getExpirationDate() === null &&
+ return $share->getPermissions() === Constants::PERMISSION_READ
+ && $share->getPassword() === null
+ && $share->getExpirationDate() === null
// Once set a note or a label are never back to null, only to an
// empty string.
- $share->getNote() === '' &&
- $share->getLabel() === '' &&
- $share->getHideDownload() === false;
+ && $share->getNote() === ''
+ && $share->getLabel() === ''
+ && $share->getHideDownload() === false;
})
)->willReturnArgument(0);
@@ -2796,6 +2878,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([$node]);
$userFolder->method('getFirstNodeById')
->with(42)
->willReturn($node);
@@ -2820,7 +2905,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -2834,12 +2919,12 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2000-01-01');
$date->setTime(0, 0, 0);
- return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getPassword() === 'password' &&
- $share->getExpirationDate() == $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getPassword() === 'password'
+ && $share->getExpirationDate() == $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -2850,9 +2935,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$mountPoint = $this->createMock(IMountPoint::class);
$folder->method('getMountPoint')
@@ -2867,9 +2952,7 @@ class ShareAPIControllerTest extends TestCase {
$this->assertEquals($expected->getData(), $result->getData());
}
- /**
- * @dataProvider publicUploadParamsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')]
public function testUpdateLinkShareEnablePublicUpload($permissions, $publicUpload, $expireDate, $password): void {
$ocs = $this->mockFormatShare();
@@ -2877,7 +2960,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -2890,9 +2973,9 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) {
- return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getPassword() === 'password' &&
- $share->getExpirationDate() === null;
+ return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getPassword() === 'password'
+ && $share->getExpirationDate() === null;
})
)->willReturnArgument(0);
@@ -2900,9 +2983,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$mountPoint = $this->createMock(IMountPoint::class);
$folder->method('getMountPoint')
@@ -2918,7 +3001,7 @@ class ShareAPIControllerTest extends TestCase {
}
- public function publicLinkValidPermissionsProvider() {
+ public static function publicLinkValidPermissionsProvider() {
return [
[Constants::PERMISSION_CREATE],
[Constants::PERMISSION_READ],
@@ -2928,9 +3011,7 @@ class ShareAPIControllerTest extends TestCase {
];
}
- /**
- * @dataProvider publicLinkValidPermissionsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkValidPermissionsProvider')]
public function testUpdateLinkShareSetCRUDPermissions($permissions): void {
$ocs = $this->mockFormatShare();
@@ -2938,7 +3019,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -2958,9 +3039,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$mountPoint = $this->createMock(IMountPoint::class);
$folder->method('getMountPoint')
@@ -2975,7 +3056,7 @@ class ShareAPIControllerTest extends TestCase {
$this->assertEquals($expected->getData(), $result->getData());
}
- public function publicLinkInvalidPermissionsProvider1() {
+ public static function publicLinkInvalidPermissionsProvider1() {
return [
[Constants::PERMISSION_DELETE],
[Constants::PERMISSION_UPDATE],
@@ -2983,9 +3064,7 @@ class ShareAPIControllerTest extends TestCase {
];
}
- /**
- * @dataProvider publicLinkInvalidPermissionsProvider1
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider1')]
public function testUpdateLinkShareSetInvalidCRUDPermissions1($permissions): void {
$this->expectException(OCSBadRequestException::class);
$this->expectExceptionMessage('Share must at least have READ or CREATE permissions');
@@ -2993,16 +3072,14 @@ class ShareAPIControllerTest extends TestCase {
$this->testUpdateLinkShareSetCRUDPermissions($permissions, null);
}
- public function publicLinkInvalidPermissionsProvider2() {
+ public static function publicLinkInvalidPermissionsProvider2() {
return [
[Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE],
[Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE],
];
}
- /**
- * @dataProvider publicLinkInvalidPermissionsProvider2
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider2')]
public function testUpdateLinkShareSetInvalidCRUDPermissions2($permissions): void {
$this->expectException(OCSBadRequestException::class);
$this->expectExceptionMessage('Share must have READ permission if UPDATE or DELETE permission is set');
@@ -3016,9 +3093,9 @@ class ShareAPIControllerTest extends TestCase {
$ocs = $this->mockFormatShare();
[$userFolder, $folder] = $this->getNonSharedUserFolder();
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
@@ -3026,7 +3103,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -3038,7 +3115,7 @@ class ShareAPIControllerTest extends TestCase {
$ocs->updateShare(42, null, 'password', null, 'true', '2000-01-a');
}
- public function publicUploadParamsProvider() {
+ public static function publicUploadParamsProvider() {
return [
[null, 'true', null, 'password'],
// legacy had no delete
@@ -3054,25 +3131,23 @@ class ShareAPIControllerTest extends TestCase {
];
}
- /**
- * @dataProvider publicUploadParamsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')]
public function testUpdateLinkSharePublicUploadNotAllowed($permissions, $publicUpload, $expireDate, $password): void {
$this->expectException(OCSForbiddenException::class);
$this->expectExceptionMessage('Public upload disabled by the administrator');
$ocs = $this->mockFormatShare();
[$userFolder, $folder] = $this->getNonSharedUserFolder();
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
$folder->method('getId')->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -3091,15 +3166,18 @@ class ShareAPIControllerTest extends TestCase {
$ocs = $this->mockFormatShare();
- [$userFolder, $file] = $this->getNonSharedUserFile();
- $userFolder->method('getFirstNodeById')
+ $file = $this->getMockBuilder(File::class)->getMock();
+ $file->method('getId')
+ ->willReturn(42);
+ [$userFolder, $folder] = $this->getNonSharedUserFolder();
+ $userFolder->method('getById')
->with(42)
- ->willReturn($file);
+ ->willReturn([$folder]);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -3128,9 +3206,9 @@ class ShareAPIControllerTest extends TestCase {
[$userFolder, $node] = $this->getNonSharedUserFolder();
$node->method('getId')->willReturn(42);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($node);
+ ->willReturn([$node]);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
@@ -3155,13 +3233,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'newpassword' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'newpassword'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3179,9 +3257,9 @@ class ShareAPIControllerTest extends TestCase {
$date->setTime(0, 0, 0);
[$userFolder, $node] = $this->getNonSharedUserFolder();
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($node);
+ ->willReturn([$node]);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
@@ -3209,13 +3287,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3237,9 +3315,9 @@ class ShareAPIControllerTest extends TestCase {
$date->setTime(0, 0, 0);
[$userFolder, $node] = $this->getNonSharedUserFolder();
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($node);
+ ->willReturn([$node]);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
@@ -3277,9 +3355,9 @@ class ShareAPIControllerTest extends TestCase {
$date->setTime(0, 0, 0);
[$userFolder, $node] = $this->getNonSharedUserFolder();
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($node);
+ ->willReturn([$node]);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
@@ -3307,13 +3385,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === false &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === false
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3357,13 +3435,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === false &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === false
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3371,9 +3449,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($node);
+ ->willReturn([$node]);
$mountPoint = $this->createMock(IMountPoint::class);
$node->method('getMountPoint')
@@ -3425,13 +3503,13 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2010-12-23');
$date->setTime(0, 0, 0);
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() == $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() == $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3439,9 +3517,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($node);
+ ->willReturn([$node]);
$mountPoint = $this->createMock(IMountPoint::class);
$node->method('getMountPoint')
@@ -3465,7 +3543,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -3483,13 +3561,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3500,9 +3578,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$mountPoint = $this->createMock(IMountPoint::class);
$folder->method('getMountPoint')
@@ -3526,7 +3604,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -3544,13 +3622,13 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (IShare $share) use ($date): bool {
- return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3560,9 +3638,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$mountPoint = $this->createMock(IMountPoint::class);
$folder->method('getMountPoint')
@@ -3586,7 +3664,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_LINK)
@@ -3606,13 +3684,13 @@ class ShareAPIControllerTest extends TestCase {
->method('updateShare')
->with(
$this->callback(function (IShare $share) use ($date) {
- return $share->getPermissions() === Constants::PERMISSION_ALL &&
- $share->getPassword() === 'password' &&
- $share->getSendPasswordByTalk() === true &&
- $share->getExpirationDate() === $date &&
- $share->getNote() === 'note' &&
- $share->getLabel() === 'label' &&
- $share->getHideDownload() === true;
+ return $share->getPermissions() === Constants::PERMISSION_ALL
+ && $share->getPassword() === 'password'
+ && $share->getSendPasswordByTalk() === true
+ && $share->getExpirationDate() === $date
+ && $share->getNote() === 'note'
+ && $share->getLabel() === 'label'
+ && $share->getHideDownload() === true;
})
)->willReturnArgument(0);
@@ -3620,9 +3698,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$mountPoint = $this->createMock(IMountPoint::class);
$folder->method('getMountPoint')
@@ -3646,7 +3724,7 @@ class ShareAPIControllerTest extends TestCase {
$file->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setPermissions(Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
->setShareType(IShare::TYPE_USER)
@@ -3668,9 +3746,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($file);
+ ->willReturn([$file]);
$mountPoint = $this->createMock(IMountPoint::class);
$file->method('getMountPoint')
@@ -3692,7 +3770,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share
->setId(42)
->setSharedBy($this->currentUser)
@@ -3704,7 +3782,7 @@ class ShareAPIControllerTest extends TestCase {
// note: updateShare will modify the received instance but getSharedWith will reread from the database,
// so their values will be different
- $incomingShare = \OCP\Server::get(IManager::class)->newShare();
+ $incomingShare = Server::get(IManager::class)->newShare();
$incomingShare
->setId(42)
->setSharedBy($this->currentUser)
@@ -3734,6 +3812,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([$folder]);
$userFolder->method('getFirstNodeById')
->with(42)
->willReturn($folder);
@@ -3764,7 +3845,7 @@ class ShareAPIControllerTest extends TestCase {
$folder->method('getId')
->willReturn(42);
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share
->setId(42)
->setSharedBy($this->currentUser)
@@ -3776,7 +3857,7 @@ class ShareAPIControllerTest extends TestCase {
// note: updateShare will modify the received instance but getSharedWith will reread from the database,
// so their values will be different
- $incomingShare = \OCP\Server::get(IManager::class)->newShare();
+ $incomingShare = Server::get(IManager::class)->newShare();
$incomingShare
->setId(42)
->setSharedBy($this->currentUser)
@@ -3804,9 +3885,9 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $userFolder->method('getFirstNodeById')
+ $userFolder->method('getById')
->with(42)
- ->willReturn($folder);
+ ->willReturn([$folder]);
$mountPoint = $this->createMock(IMountPoint::class);
$folder->method('getMountPoint')
@@ -3834,9 +3915,10 @@ class ShareAPIControllerTest extends TestCase {
->willReturn($mount);
$userFolder = $this->createMock(Folder::class);
- $userFolder
- ->expects($this->exactly(2))
- ->method('getFirstNodeById')
+ $userFolder->method('getById')
+ ->with(2)
+ ->willReturn([$file]);
+ $userFolder->method('getFirstNodeById')
->with(2)
->willReturn($file);
@@ -3938,7 +4020,7 @@ class ShareAPIControllerTest extends TestCase {
$result = [];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -4040,7 +4122,7 @@ class ShareAPIControllerTest extends TestCase {
], false
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -4094,7 +4176,7 @@ class ShareAPIControllerTest extends TestCase {
], $share, [], false
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -4150,7 +4232,7 @@ class ShareAPIControllerTest extends TestCase {
// with existing group
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_GROUP)
->setSharedWith('recipientGroup')
->setSharedBy('initiator')
@@ -4204,7 +4286,7 @@ class ShareAPIControllerTest extends TestCase {
];
// with unknown group / no group backend
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_GROUP)
->setSharedWith('recipientGroup2')
->setSharedBy('initiator')
@@ -4255,7 +4337,7 @@ class ShareAPIControllerTest extends TestCase {
], $share, [], false
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_LINK)
->setSharedBy('initiator')
->setShareOwner('owner')
@@ -4314,7 +4396,7 @@ class ShareAPIControllerTest extends TestCase {
], $share, [], false
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_LINK)
->setSharedBy('initiator')
->setShareOwner('owner')
@@ -4373,7 +4455,7 @@ class ShareAPIControllerTest extends TestCase {
], $share, [], false
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_REMOTE)
->setSharedBy('initiator')
->setSharedWith('user@server.com')
@@ -4423,10 +4505,11 @@ class ShareAPIControllerTest extends TestCase {
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
+ 'is_trusted_server' => false,
], $share, [], false
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_REMOTE_GROUP)
->setSharedBy('initiator')
->setSharedWith('user@server.com')
@@ -4476,11 +4559,12 @@ class ShareAPIControllerTest extends TestCase {
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
+ 'is_trusted_server' => false,
], $share, [], false
];
// Circle with id, display name and avatar set by the Circles app
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_CIRCLE)
->setSharedBy('initiator')
->setSharedWith('Circle (Public circle, circleOwner) [4815162342]')
@@ -4536,7 +4620,7 @@ class ShareAPIControllerTest extends TestCase {
];
// Circle with id set by the Circles app
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_CIRCLE)
->setSharedBy('initiator')
->setSharedWith('Circle (Public circle, circleOwner) [4815162342]')
@@ -4589,7 +4673,7 @@ class ShareAPIControllerTest extends TestCase {
];
// Circle with id not set by the Circles app
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_CIRCLE)
->setSharedBy('initiator')
->setSharedWith('Circle (Public circle, circleOwner)')
@@ -4641,7 +4725,7 @@ class ShareAPIControllerTest extends TestCase {
], $share, [], false
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_USER)
->setSharedBy('initiator')
->setSharedWith('recipient')
@@ -4656,7 +4740,7 @@ class ShareAPIControllerTest extends TestCase {
[], $share, [], true
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_EMAIL)
->setSharedBy('initiator')
->setSharedWith('user@server.com')
@@ -4711,7 +4795,7 @@ class ShareAPIControllerTest extends TestCase {
], $share, [], false
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_EMAIL)
->setSharedBy('initiator')
->setSharedWith('user@server.com')
@@ -4768,7 +4852,7 @@ class ShareAPIControllerTest extends TestCase {
];
// Preview is available
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_USER)
->setSharedWith('recipient')
->setSharedBy('initiator')
@@ -4825,13 +4909,13 @@ class ShareAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataFormatShare
*
* @param array $expects
* @param IShare $share
* @param array $users
* @param $exception
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatShare')]
public function testFormatShare(array $expects, IShare $share, array $users, $exception): void {
$this->userManager->method('get')->willReturnMap($users);
@@ -4934,7 +5018,7 @@ class ShareAPIControllerTest extends TestCase {
$result = [];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_ROOM)
->setSharedWith('recipientRoom')
->setSharedBy('initiator')
@@ -4986,7 +5070,7 @@ class ShareAPIControllerTest extends TestCase {
], $share, false, []
];
- $share = \OCP\Server::get(IManager::class)->newShare();
+ $share = Server::get(IManager::class)->newShare();
$share->setShareType(IShare::TYPE_ROOM)
->setSharedWith('recipientRoom')
->setSharedBy('initiator')
@@ -5044,13 +5128,13 @@ class ShareAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataFormatRoomShare
*
* @param array $expects
* @param IShare $share
* @param bool $helperAvailable
* @param array $formatShareByHelper
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatRoomShare')]
public function testFormatRoomShare(array $expects, IShare $share, bool $helperAvailable, array $formatShareByHelper): void {
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
@@ -5073,8 +5157,11 @@ class ShareAPIControllerTest extends TestCase {
->with('spreed')
->willReturn(true);
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['formatShare', 'canAccessShare'])
+ // This is not possible anymore with PHPUnit 10+
+ // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
+ // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
+ $helper = $this->getMockBuilder(\stdClass::class)
+ ->addMethods(['formatShare', 'canAccessShare'])
->getMock();
$helper->method('formatShare')
->with($share)
@@ -5107,6 +5194,9 @@ class ShareAPIControllerTest extends TestCase {
$userFolder->method('getStorage')->willReturn($storage);
$node->method('getStorage')->willReturn($storage);
$node->method('getId')->willReturn(42);
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')->willReturn($this->currentUser);
+ $node->method('getOwner')->willReturn($user);
return [$userFolder, $node];
}
@@ -5127,4 +5217,164 @@ class ShareAPIControllerTest extends TestCase {
$node->method('getId')->willReturn(42);
return [$userFolder, $node];
}
+
+ public function testPopulateTags(): void {
+ $tagger = $this->createMock(ITags::class);
+ $this->tagManager->method('load')
+ ->with('files')
+ ->willReturn($tagger);
+ $data = [
+ ['file_source' => 10],
+ ['file_source' => 22, 'foo' => 'bar'],
+ ['file_source' => 42, 'x' => 'y'],
+ ];
+ $tags = [
+ 10 => ['tag3'],
+ 42 => ['tag1', 'tag2'],
+ ];
+ $tagger->method('getTagsForObjects')
+ ->with([10, 22, 42])
+ ->willReturn($tags);
+
+ $result = self::invokePrivate($this->ocs, 'populateTags', [$data]);
+ $this->assertSame([
+ ['file_source' => 10, 'tags' => ['tag3']],
+ ['file_source' => 22, 'foo' => 'bar', 'tags' => []],
+ ['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']],
+ ], $result);
+ }
+
+ public function trustedServerProvider(): array {
+ return [
+ 'Trusted server' => [true, true],
+ 'Untrusted server' => [false, false],
+ ];
+ }
+
+ /**
+ * @dataProvider trustedServerProvider
+ */
+ public function testFormatShareWithFederatedShare(bool $isKnownServer, bool $isTrusted): void {
+ $nodeId = 12;
+ $nodePath = '/test.txt';
+ $share = $this->createShare(
+ 1,
+ IShare::TYPE_REMOTE,
+ 'recipient@remoteserver.com', // shared with
+ 'sender@testserver.com', // shared by
+ 'shareOwner', // share owner
+ $nodePath, // path
+ Constants::PERMISSION_READ,
+ time(),
+ null,
+ null,
+ $nodePath,
+ $nodeId
+ );
+
+ $node = $this->createMock(\OCP\Files\File::class);
+ $node->method('getId')->willReturn($nodeId);
+ $node->method('getPath')->willReturn($nodePath);
+ $node->method('getInternalPath')->willReturn(ltrim($nodePath, '/'));
+ $mountPoint = $this->createMock(\OCP\Files\Mount\IMountPoint::class);
+ $mountPoint->method('getMountType')->willReturn('local');
+ $node->method('getMountPoint')->willReturn($mountPoint);
+ $node->method('getMimetype')->willReturn('text/plain');
+ $storage = $this->createMock(\OCP\Files\Storage\IStorage::class);
+ $storageCache = $this->createMock(\OCP\Files\Cache\ICache::class);
+ $storageCache->method('getNumericStorageId')->willReturn(1);
+ $storage->method('getCache')->willReturn($storageCache);
+ $storage->method('getId')->willReturn('home::shareOwner');
+ $node->method('getStorage')->willReturn($storage);
+ $parent = $this->createMock(\OCP\Files\Folder::class);
+ $parent->method('getId')->willReturn(2);
+ $node->method('getParent')->willReturn($parent);
+ $node->method('getSize')->willReturn(1234);
+ $node->method('getMTime')->willReturn(1234567890);
+
+ $this->previewManager->method('isAvailable')->with($node)->willReturn(false);
+
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturnSelf();
+
+ $this->rootFolder->method('getFirstNodeById')
+ ->with($share->getNodeId())
+ ->willReturn($node);
+
+ $this->rootFolder->method('getRelativePath')
+ ->with($node->getPath())
+ ->willReturnArgument(0);
+
+ $serverName = 'remoteserver.com';
+ $this->trustedServers->method('isTrustedServer')
+ ->with($serverName)
+ ->willReturn($isKnownServer);
+
+ $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
+
+ $this->assertSame($isTrusted, $result['is_trusted_server']);
+ }
+
+ public function testFormatShareWithFederatedShareWithAtInUsername(): void {
+ $nodeId = 12;
+ $nodePath = '/test.txt';
+ $share = $this->createShare(
+ 1,
+ IShare::TYPE_REMOTE,
+ 'recipient@domain.com@remoteserver.com',
+ 'sender@testserver.com',
+ 'shareOwner',
+ $nodePath,
+ Constants::PERMISSION_READ,
+ time(),
+ null,
+ null,
+ $nodePath,
+ $nodeId
+ );
+
+ $node = $this->createMock(\OCP\Files\File::class);
+ $node->method('getId')->willReturn($nodeId);
+ $node->method('getPath')->willReturn($nodePath);
+ $node->method('getInternalPath')->willReturn(ltrim($nodePath, '/'));
+ $mountPoint = $this->createMock(\OCP\Files\Mount\IMountPoint::class);
+ $mountPoint->method('getMountType')->willReturn('local');
+ $node->method('getMountPoint')->willReturn($mountPoint);
+ $node->method('getMimetype')->willReturn('text/plain');
+ $storage = $this->createMock(\OCP\Files\Storage\IStorage::class);
+ $storageCache = $this->createMock(\OCP\Files\Cache\ICache::class);
+ $storageCache->method('getNumericStorageId')->willReturn(1);
+ $storage->method('getCache')->willReturn($storageCache);
+ $storage->method('getId')->willReturn('home::shareOwner');
+ $node->method('getStorage')->willReturn($storage);
+ $parent = $this->createMock(\OCP\Files\Folder::class);
+ $parent->method('getId')->willReturn(2);
+ $node->method('getParent')->willReturn($parent);
+ $node->method('getSize')->willReturn(1234);
+ $node->method('getMTime')->willReturn(1234567890);
+
+ $this->previewManager->method('isAvailable')->with($node)->willReturn(false);
+
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturnSelf();
+
+ $this->rootFolder->method('getFirstNodeById')
+ ->with($share->getNodeId())
+ ->willReturn($node);
+
+ $this->rootFolder->method('getRelativePath')
+ ->with($node->getPath())
+ ->willReturnArgument(0);
+
+ $serverName = 'remoteserver.com';
+ $this->trustedServers->method('isTrustedServer')
+ ->with($serverName)
+ ->willReturn(true);
+
+ $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
+
+ $this->assertTrue($result['is_trusted_server']);
+ }
}
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php
index bc8e5dede63..011210aff42 100644
--- a/apps/files_sharing/tests/Controller/ShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -42,6 +43,7 @@ use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
+use OCP\Share\IAttributes;
use OCP\Share\IPublicShareTemplateFactory;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
@@ -142,9 +144,9 @@ class ShareControllerTest extends \Test\TestCase {
$this->oldUser = \OC_User::getUser();
// Create a dummy user
- $this->user = \OC::$server->getSecureRandom()->generate(12, ISecureRandom::CHAR_LOWER);
+ $this->user = Server::get(ISecureRandom::class)->generate(12, ISecureRandom::CHAR_LOWER);
- \OC::$server->getUserManager()->createUser($this->user, $this->user);
+ Server::get(IUserManager::class)->createUser($this->user, $this->user);
\OC_Util::tearDownFS();
$this->loginAsUser($this->user);
}
@@ -153,13 +155,13 @@ class ShareControllerTest extends \Test\TestCase {
\OC_Util::tearDownFS();
\OC_User::setUserId('');
Filesystem::tearDown();
- $user = \OC::$server->getUserManager()->get($this->user);
+ $user = Server::get(IUserManager::class)->get($this->user);
if ($user !== null) {
$user->delete();
}
\OC_User::setIncognitoMode(false);
- \OC::$server->getSession()->set('public_link_authenticated', '');
+ Server::get(ISession::class)->set('public_link_authenticated', '');
// Set old user
\OC_User::setUserId($this->oldUser);
@@ -174,7 +176,7 @@ class ShareControllerTest extends \Test\TestCase {
->expects($this->once())
->method('getShareByToken')
->with('invalidtoken')
- ->will($this->throwException(new ShareNotFound()));
+ ->willThrowException(new ShareNotFound());
$this->expectException(NotFoundException::class);
@@ -185,7 +187,7 @@ class ShareControllerTest extends \Test\TestCase {
public function testShowShareNotAuthenticated(): void {
$this->shareController->setToken('validtoken');
- $share = \OC::$server->getShareManager()->newShare();
+ $share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setPassword('password');
$this->shareManager
@@ -260,8 +262,12 @@ class ShareControllerTest extends \Test\TestCase {
['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
// this share is not an image to the default preview is used
['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
- // for the direct link
- ['files_sharing.sharecontroller.downloadShare', ['token' => 'token', 'filename' => $filename ], 'downloadUrl'],
+ ]);
+
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->willReturnMap([
+ ['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
]);
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
@@ -329,6 +335,9 @@ class ShareControllerTest extends \Test\TestCase {
'filename' => $filename,
'view' => $view,
'fileId' => 111,
+ 'owner' => 'ownerUID',
+ 'ownerDisplayName' => 'ownerDisplay',
+ 'isFileRequest' => false,
];
$response = $this->shareController->showShare();
@@ -392,6 +401,8 @@ class ShareControllerTest extends \Test\TestCase {
->setPassword('password')
->setShareOwner('ownerUID')
->setSharedBy('initiatorUID')
+ ->setNote('The note')
+ ->setLabel('A label')
->setNode($file)
->setTarget("/$filename")
->setToken('token');
@@ -469,6 +480,11 @@ class ShareControllerTest extends \Test\TestCase {
'filename' => $filename,
'view' => 'public-file-drop',
'disclaimer' => 'My disclaimer text',
+ 'owner' => 'ownerUID',
+ 'ownerDisplayName' => 'ownerDisplay',
+ 'isFileRequest' => false,
+ 'note' => 'The note',
+ 'label' => 'A label',
];
$response = $this->shareController->showShare();
@@ -478,9 +494,9 @@ class ShareControllerTest extends \Test\TestCase {
$csp = new ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
$expectedResponse = new PublicTemplateResponse('files', 'index');
- $expectedResponse->setParams(['pageTitle' => $filename]);
+ $expectedResponse->setParams(['pageTitle' => 'A label']);
$expectedResponse->setContentSecurityPolicy($csp);
- $expectedResponse->setHeaderTitle($filename);
+ $expectedResponse->setHeaderTitle('A label');
$expectedResponse->setHeaderDetails('shared by ownerDisplay');
$expectedResponse->setHeaderActions([
new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', 'shareUrl'),
@@ -547,8 +563,12 @@ class ShareControllerTest extends \Test\TestCase {
['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
// this share is not an image to the default preview is used
['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
- // for the direct link
- ['files_sharing.sharecontroller.downloadShare', ['token' => 'token', 'filename' => $filename ], 'downloadUrl'],
+ ]);
+
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->willReturnMap([
+ ['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
]);
$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
@@ -593,9 +613,9 @@ class ShareControllerTest extends \Test\TestCase {
$this->l10n->expects($this->any())
->method('t')
- ->will($this->returnCallback(function ($text, $parameters) {
+ ->willReturnCallback(function ($text, $parameters) {
return vsprintf($text, $parameters);
- }));
+ });
$this->defaults->expects(self::any())
->method('getProductName')
@@ -637,7 +657,7 @@ class ShareControllerTest extends \Test\TestCase {
$file->method('isShareable')->willReturn(false);
$file->method('isReadable')->willReturn(true);
- $share = \OC::$server->getShareManager()->newShare();
+ $share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setId(42);
$share->setPassword('password')
->setShareOwner('ownerUID')
@@ -690,6 +710,34 @@ class ShareControllerTest extends \Test\TestCase {
$this->assertEquals($expectedResponse, $response);
}
+ public function testDownloadShareWithoutDownloadPermission(): void {
+ $attributes = $this->createMock(IAttributes::class);
+ $attributes->expects(self::once())
+ ->method('getAttribute')
+ ->with('permissions', 'download')
+ ->willReturn(false);
+
+ $share = $this->createMock(IShare::class);
+ $share->method('getPassword')->willReturn('password');
+ $share->expects(self::once())
+ ->method('getPermissions')
+ ->willReturn(Constants::PERMISSION_READ);
+ $share->expects(self::once())
+ ->method('getAttributes')
+ ->willReturn($attributes);
+
+ $this->shareManager
+ ->expects(self::once())
+ ->method('getShareByToken')
+ ->with('validtoken')
+ ->willReturn($share);
+
+ // Test with a password protected share and no authentication
+ $response = $this->shareController->downloadShare('validtoken');
+ $expectedResponse = new DataResponse('Share has no download permission');
+ $this->assertEquals($expectedResponse, $response);
+ }
+
public function testDisabledOwner(): void {
$this->shareController->setToken('token');
@@ -702,7 +750,7 @@ class ShareControllerTest extends \Test\TestCase {
/* @var MockObject|Folder $folder */
$folder = $this->createMock(Folder::class);
- $share = \OC::$server->getShareManager()->newShare();
+ $share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setId(42);
$share->setPermissions(Constants::PERMISSION_CREATE)
->setShareOwner('ownerUID')
@@ -743,7 +791,7 @@ class ShareControllerTest extends \Test\TestCase {
/* @var MockObject|Folder $folder */
$folder = $this->createMock(Folder::class);
- $share = \OC::$server->getShareManager()->newShare();
+ $share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setId(42);
$share->setPermissions(Constants::PERMISSION_CREATE)
->setShareOwner('ownerUID')
diff --git a/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php b/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
index f2df74fd01b..1a678610805 100644
--- a/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -15,15 +16,13 @@ use OCP\IRequest;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ShareInfoControllerTest extends TestCase {
- /** @var ShareInfoController */
- private $controller;
-
- /** @var ShareManager|\PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
+ protected ShareInfoController $controller;
+ protected ShareManager&MockObject $shareManager;
protected function setUp(): void {
@@ -31,14 +30,11 @@ class ShareInfoControllerTest extends TestCase {
$this->shareManager = $this->createMock(ShareManager::class);
- $this->controller = $this->getMockBuilder(ShareInfoController::class)
- ->setConstructorArgs([
- 'files_sharing',
- $this->createMock(IRequest::class),
- $this->shareManager
- ])
- ->setMethods(['addROWrapper'])
- ->getMock();
+ $this->controller = new ShareInfoController(
+ 'files_sharing',
+ $this->createMock(IRequest::class),
+ $this->shareManager
+ );
}
public function testNoShare(): void {
diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
index b3b395da8c0..18e1bf0347b 100644
--- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -11,6 +12,7 @@ use OCA\Files_Sharing\Tests\TestCase;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\Collaboration\Collaborators\ISearch;
+use OCP\GlobalScale\IConfig as GlobalScaleIConfig;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
@@ -68,7 +70,7 @@ class ShareesAPIControllerTest extends TestCase {
);
}
- public function dataSearch(): array {
+ public static function dataSearch(): array {
$noRemote = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_EMAIL];
$allTypes = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_EMAIL];
@@ -196,7 +198,6 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataSearch
*
* @param array $getData
* @param string $apiSetting
@@ -210,6 +211,7 @@ class ShareesAPIControllerTest extends TestCase {
* @param bool $allowGroupSharing
* @throws OCSBadRequestException
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSearch')]
public function testSearch(
array $getData,
string $apiSetting,
@@ -229,14 +231,14 @@ class ShareesAPIControllerTest extends TestCase {
$perPage = $getData['perPage'] ?? 200;
$shareType = $getData['shareType'] ?? null;
+ $globalConfig = $this->createMock(GlobalScaleIConfig::class);
+ $globalConfig->expects(self::once())
+ ->method('isGlobalScaleEnabled')
+ ->willReturn(true);
+ $this->overwriteService(GlobalScaleIConfig::class, $globalConfig);
+
/** @var IConfig|MockObject $config */
$config = $this->createMock(IConfig::class);
- $config->expects($this->exactly(1))
- ->method('getAppValue')
- ->with($this->anything(), $this->anything(), $this->anything())
- ->willReturnMap([
- ['files_sharing', 'lookupServerEnabled', 'yes', 'yes'],
- ]);
$this->shareManager->expects($this->once())
->method('allowGroupSharing')
@@ -300,7 +302,7 @@ class ShareesAPIControllerTest extends TestCase {
$this->assertInstanceOf(DataResponse::class, $sharees->search($search, $itemType, $page, $perPage, $shareType));
}
- public function dataSearchInvalid(): array {
+ public static function dataSearchInvalid(): array {
return [
// Test invalid pagination
[[
@@ -327,11 +329,11 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataSearchInvalid
*
* @param array $getData
* @param string $message
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchInvalid')]
public function testSearchInvalid($getData, $message): void {
$page = $getData['page'] ?? 1;
$perPage = $getData['perPage'] ?? 200;
@@ -375,7 +377,7 @@ class ShareesAPIControllerTest extends TestCase {
}
}
- public function dataIsRemoteSharingAllowed() {
+ public static function dataIsRemoteSharingAllowed() {
return [
['file', true],
['folder', true],
@@ -385,11 +387,11 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataIsRemoteSharingAllowed
*
* @param string $itemType
* @param bool $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataIsRemoteSharingAllowed')]
public function testIsRemoteSharingAllowed($itemType, $expected): void {
$this->assertSame($expected, $this->invokePrivate($this->sharees, 'isRemoteSharingAllowed', [$itemType]));
}
@@ -418,7 +420,7 @@ class ShareesAPIControllerTest extends TestCase {
$this->sharees->search('', null, 1, 10, [], false);
}
- public function dataGetPaginationLink() {
+ public static function dataGetPaginationLink() {
return [
[1, '/ocs/v1.php', ['perPage' => 2], '<?perPage=2&page=2>; rel="next"'],
[10, '/ocs/v2.php', ['perPage' => 2], '<?perPage=2&page=11>; rel="next"'],
@@ -426,13 +428,13 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataGetPaginationLink
*
* @param int $page
* @param string $scriptName
* @param array $params
* @param array $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetPaginationLink')]
public function testGetPaginationLink($page, $scriptName, $params, $expected): void {
$this->request->expects($this->once())
->method('getScriptName')
@@ -441,7 +443,7 @@ class ShareesAPIControllerTest extends TestCase {
$this->assertEquals($expected, $this->invokePrivate($this->sharees, 'getPaginationLink', [$page, $params]));
}
- public function dataIsV2() {
+ public static function dataIsV2() {
return [
['/ocs/v1.php', false],
['/ocs/v2.php', true],
@@ -449,11 +451,11 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataIsV2
*
* @param string $scriptName
* @param bool $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataIsV2')]
public function testIsV2($scriptName, $expected): void {
$this->request->expects($this->once())
->method('getScriptName')