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.php33
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php607
-rw-r--r--apps/files_sharing/tests/Controller/ShareControllerTest.php33
-rw-r--r--apps/files_sharing/tests/Controller/ShareInfoControllerTest.php22
-rw-r--r--apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php21
6 files changed, 464 insertions, 253 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 9750274ff62..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
@@ -20,7 +21,6 @@ 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;
@@ -114,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);
@@ -136,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);
@@ -176,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);
@@ -220,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);
@@ -249,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());
@@ -272,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 02c133ee5d1..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;
@@ -70,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;
@@ -79,6 +83,7 @@ class ShareAPIControllerTest extends TestCase {
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);
@@ -102,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);
@@ -115,6 +121,7 @@ class ShareAPIControllerTest extends TestCase {
$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,
@@ -126,6 +133,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -135,8 +143,10 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
- $this->currentUser,
+ $this->trustedServers,
+ $this->currentUser
);
+
}
/**
@@ -154,6 +164,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -163,6 +174,7 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])->onlyMethods(['formatShare'])
->getMock();
@@ -271,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]));
@@ -592,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);
}
@@ -823,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)
@@ -839,6 +849,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -848,6 +859,7 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])
->onlyMethods(['canAccessShare'])
@@ -1456,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)
@@ -1472,6 +1482,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -1481,6 +1492,7 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])
->onlyMethods(['formatShare'])
@@ -1542,84 +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() {
@@ -1649,13 +1702,13 @@ 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')
@@ -1675,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)
@@ -1712,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');
}
@@ -1815,6 +1871,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -1824,6 +1881,7 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])->onlyMethods(['formatShare'])
->getMock();
@@ -1849,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);
@@ -1913,6 +1971,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -1922,6 +1981,7 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])->onlyMethods(['formatShare'])
->getMock();
@@ -1960,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);
@@ -2077,7 +2137,7 @@ 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')
@@ -2113,12 +2173,12 @@ 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_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);
@@ -2193,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);
@@ -2279,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);
@@ -2339,6 +2399,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -2348,6 +2409,7 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])->onlyMethods(['formatShare'])
->getMock();
@@ -2373,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);
@@ -2410,6 +2472,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -2419,6 +2482,7 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])->onlyMethods(['formatShare'])
->getMock();
@@ -2444,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);
@@ -2492,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 {
@@ -2598,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')
@@ -2642,6 +2712,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->l,
$this->config,
+ $this->appConfig,
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
@@ -2651,6 +2722,7 @@ class ShareAPIControllerTest extends TestCase {
$this->factory,
$this->mailer,
$this->tagManager,
+ $this->trustedServers,
$this->currentUser,
])->onlyMethods(['formatShare'])
->getMock();
@@ -2788,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);
@@ -2847,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);
@@ -2880,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();
@@ -2903,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);
@@ -2931,7 +3001,7 @@ class ShareAPIControllerTest extends TestCase {
}
- public function publicLinkValidPermissionsProvider() {
+ public static function publicLinkValidPermissionsProvider() {
return [
[Constants::PERMISSION_CREATE],
[Constants::PERMISSION_READ],
@@ -2941,9 +3011,7 @@ class ShareAPIControllerTest extends TestCase {
];
}
- /**
- * @dataProvider publicLinkValidPermissionsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkValidPermissionsProvider')]
public function testUpdateLinkShareSetCRUDPermissions($permissions): void {
$ocs = $this->mockFormatShare();
@@ -2988,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],
@@ -2996,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');
@@ -3006,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');
@@ -3051,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
@@ -3067,9 +3131,7 @@ 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');
@@ -3171,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);
@@ -3225,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);
@@ -3323,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);
@@ -3373,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);
@@ -3441,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);
@@ -3499,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);
@@ -3560,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);
@@ -3622,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);
@@ -4443,6 +4505,7 @@ class ShareAPIControllerTest extends TestCase {
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
+ 'is_trusted_server' => false,
], $share, [], false
];
@@ -4496,6 +4559,7 @@ class ShareAPIControllerTest extends TestCase {
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
+ 'is_trusted_server' => false,
], $share, [], false
];
@@ -4845,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);
@@ -5064,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)
@@ -5093,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)
@@ -5176,4 +5243,138 @@ class ShareAPIControllerTest extends TestCase {
['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 58cbb4e0b82..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.
@@ -175,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);
@@ -261,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);
@@ -332,6 +337,7 @@ class ShareControllerTest extends \Test\TestCase {
'fileId' => 111,
'owner' => 'ownerUID',
'ownerDisplayName' => 'ownerDisplay',
+ 'isFileRequest' => false,
];
$response = $this->shareController->showShare();
@@ -395,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');
@@ -474,6 +482,9 @@ class ShareControllerTest extends \Test\TestCase {
'disclaimer' => 'My disclaimer text',
'owner' => 'ownerUID',
'ownerDisplayName' => 'ownerDisplay',
+ 'isFileRequest' => false,
+ 'note' => 'The note',
+ 'label' => 'A label',
];
$response = $this->shareController->showShare();
@@ -483,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'),
@@ -552,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);
@@ -598,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')
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 c8113558f6c..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.
@@ -69,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];
@@ -197,7 +198,6 @@ class ShareesAPIControllerTest extends TestCase {
}
/**
- * @dataProvider dataSearch
*
* @param array $getData
* @param string $apiSetting
@@ -211,6 +211,7 @@ class ShareesAPIControllerTest extends TestCase {
* @param bool $allowGroupSharing
* @throws OCSBadRequestException
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSearch')]
public function testSearch(
array $getData,
string $apiSetting,
@@ -301,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
[[
@@ -328,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;
@@ -376,7 +377,7 @@ class ShareesAPIControllerTest extends TestCase {
}
}
- public function dataIsRemoteSharingAllowed() {
+ public static function dataIsRemoteSharingAllowed() {
return [
['file', true],
['folder', true],
@@ -386,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]));
}
@@ -419,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"'],
@@ -427,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')
@@ -442,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],
@@ -450,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')