|
42 | 42 | use OCP\Security\ISecureRandom;
|
43 | 43 | use OCP\Server;
|
44 | 44 | use OCP\Share\Exceptions\ShareNotFound;
|
| 45 | +use OCP\Share\IAttributes; |
45 | 46 | use OCP\Share\IPublicShareTemplateFactory;
|
46 | 47 | use OCP\Share\IShare;
|
47 | 48 | use PHPUnit\Framework\MockObject\MockObject;
|
@@ -690,6 +691,34 @@ public function testDownloadShareWithCreateOnlyShare(): void {
|
690 | 691 | $this->assertEquals($expectedResponse, $response);
|
691 | 692 | }
|
692 | 693 |
|
| 694 | + public function testDownloadShareWithoutDownloadPermission(): void { |
| 695 | + $attributes = $this->createMock(IAttributes::class); |
| 696 | + $attributes->expects(self::once()) |
| 697 | + ->method('getAttribute') |
| 698 | + ->with('permissions', 'download') |
| 699 | + ->willReturn(false); |
| 700 | + |
| 701 | + $share = $this->createMock(IShare::class); |
| 702 | + $share->method('getPassword')->willReturn('password'); |
| 703 | + $share->expects(self::once()) |
| 704 | + ->method('getPermissions') |
| 705 | + ->willReturn(Constants::PERMISSION_READ); |
| 706 | + $share->expects(self::once()) |
| 707 | + ->method('getAttributes') |
| 708 | + ->willReturn($attributes); |
| 709 | + |
| 710 | + $this->shareManager |
| 711 | + ->expects(self::once()) |
| 712 | + ->method('getShareByToken') |
| 713 | + ->with('validtoken') |
| 714 | + ->willReturn($share); |
| 715 | + |
| 716 | + // Test with a password protected share and no authentication |
| 717 | + $response = $this->shareController->downloadShare('validtoken'); |
| 718 | + $expectedResponse = new DataResponse('Share has no download permission'); |
| 719 | + $this->assertEquals($expectedResponse, $response); |
| 720 | + } |
| 721 | + |
693 | 722 | public function testDisabledOwner(): void {
|
694 | 723 | $this->shareController->setToken('token');
|
695 | 724 |
|
|
0 commit comments