diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-02-18 11:58:12 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-02-18 11:58:12 +0100 |
commit | c19ce403f3ca0567645b7751df5b697509a460c2 (patch) | |
tree | 861e25261e92e14ab2fe0f345b24a3e8f99689a5 /apps/files_sharing/tests | |
parent | 8886f367e433277cf7aa0c01b93a9d4348db47a8 (diff) | |
download | nextcloud-server-c19ce403f3ca0567645b7751df5b697509a460c2.tar.gz nextcloud-server-c19ce403f3ca0567645b7751df5b697509a460c2.zip |
fix(files_sharing): block downloading if neededfix/download-perms
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareControllerTest.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php index dae5a1d512a..0ed43da52cd 100644 --- a/apps/files_sharing/tests/Controller/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -42,6 +42,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; @@ -690,6 +691,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'); |