|
18 | 18 | use OCP\Files\Folder; |
19 | 19 | use OCP\Files\IRootFolder; |
20 | 20 | use OCP\Files\Mount\IMountPoint; |
| 21 | +use OCP\Files\Mount\IShareOwnerlessMount; |
21 | 22 | use OCP\Files\NotFoundException; |
22 | 23 | use OCP\Files\Storage\IStorage; |
23 | 24 | use OCP\IConfig; |
@@ -232,10 +233,20 @@ public function testDeleteShareLocked(): void { |
232 | 233 | $this->expectExceptionMessage('Could not delete share'); |
233 | 234 |
|
234 | 235 | $node = $this->getMockBuilder(File::class)->getMock(); |
| 236 | + $node->method('getId')->willReturn(1); |
235 | 237 |
|
236 | 238 | $share = $this->newShare(); |
237 | 239 | $share->setNode($node); |
238 | 240 |
|
| 241 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
| 242 | + $this->rootFolder->method('getUserFolder') |
| 243 | + ->with($this->currentUser) |
| 244 | + ->willReturn($userFolder); |
| 245 | + |
| 246 | + $userFolder->method('getFirstNodeById') |
| 247 | + ->with($share->getNodeId()) |
| 248 | + ->willReturn($node); |
| 249 | + |
239 | 250 | $this->shareManager |
240 | 251 | ->expects($this->once()) |
241 | 252 | ->method('getShareById') |
@@ -476,6 +487,62 @@ public function testDeleteSharedWithGroupIDontBelongTo(): void { |
476 | 487 | $this->ocs->deleteShare(42); |
477 | 488 | } |
478 | 489 |
|
| 490 | + public function testDeleteShareOwnerless(): void { |
| 491 | + $ocs = $this->mockFormatShare(); |
| 492 | + |
| 493 | + $mount = $this->createMock(IShareOwnerlessMount::class); |
| 494 | + |
| 495 | + $file = $this->createMock(File::class); |
| 496 | + $file |
| 497 | + ->expects($this->exactly(2)) |
| 498 | + ->method('getPermissions') |
| 499 | + ->willReturn(Constants::PERMISSION_SHARE); |
| 500 | + $file |
| 501 | + ->expects($this->once()) |
| 502 | + ->method('getMountPoint') |
| 503 | + ->willReturn($mount); |
| 504 | + |
| 505 | + $userFolder = $this->createMock(Folder::class); |
| 506 | + $userFolder |
| 507 | + ->expects($this->exactly(2)) |
| 508 | + ->method('getFirstNodeById') |
| 509 | + ->with(2) |
| 510 | + ->willReturn($file); |
| 511 | + |
| 512 | + $this->rootFolder |
| 513 | + ->method('getUserFolder') |
| 514 | + ->with($this->currentUser) |
| 515 | + ->willReturn($userFolder); |
| 516 | + |
| 517 | + $share = $this->createMock(IShare::class); |
| 518 | + $share |
| 519 | + ->expects($this->once()) |
| 520 | + ->method('getNode') |
| 521 | + ->willReturn($file); |
| 522 | + $share |
| 523 | + ->expects($this->exactly(2)) |
| 524 | + ->method('getNodeId') |
| 525 | + ->willReturn(2); |
| 526 | + $share |
| 527 | + ->expects($this->exactly(2)) |
| 528 | + ->method('getPermissions') |
| 529 | + ->willReturn(Constants::PERMISSION_SHARE); |
| 530 | + |
| 531 | + $this->shareManager |
| 532 | + ->expects($this->once()) |
| 533 | + ->method('getShareById') |
| 534 | + ->with('ocinternal:1', $this->currentUser) |
| 535 | + ->willReturn($share); |
| 536 | + |
| 537 | + $this->shareManager |
| 538 | + ->expects($this->once()) |
| 539 | + ->method('deleteShare') |
| 540 | + ->with($share); |
| 541 | + |
| 542 | + $result = $ocs->deleteShare(1); |
| 543 | + $this->assertInstanceOf(DataResponse::class, $result); |
| 544 | + } |
| 545 | + |
479 | 546 | /* |
480 | 547 | * FIXME: Enable once we have a federated Share Provider |
481 | 548 |
|
@@ -3748,6 +3815,63 @@ public function testUpdateShareCanIncreasePermissionsIfOwner(): void { |
3748 | 3815 | $this->assertInstanceOf(DataResponse::class, $result); |
3749 | 3816 | } |
3750 | 3817 |
|
| 3818 | + public function testUpdateShareOwnerless(): void { |
| 3819 | + $ocs = $this->mockFormatShare(); |
| 3820 | + |
| 3821 | + $mount = $this->createMock(IShareOwnerlessMount::class); |
| 3822 | + |
| 3823 | + $file = $this->createMock(File::class); |
| 3824 | + $file |
| 3825 | + ->expects($this->exactly(2)) |
| 3826 | + ->method('getPermissions') |
| 3827 | + ->willReturn(Constants::PERMISSION_SHARE); |
| 3828 | + $file |
| 3829 | + ->expects($this->once()) |
| 3830 | + ->method('getMountPoint') |
| 3831 | + ->willReturn($mount); |
| 3832 | + |
| 3833 | + $userFolder = $this->createMock(Folder::class); |
| 3834 | + $userFolder |
| 3835 | + ->expects($this->exactly(2)) |
| 3836 | + ->method('getFirstNodeById') |
| 3837 | + ->with(2) |
| 3838 | + ->willReturn($file); |
| 3839 | + |
| 3840 | + $this->rootFolder |
| 3841 | + ->method('getUserFolder') |
| 3842 | + ->with($this->currentUser) |
| 3843 | + ->willReturn($userFolder); |
| 3844 | + |
| 3845 | + $share = $this->createMock(IShare::class); |
| 3846 | + $share |
| 3847 | + ->expects($this->once()) |
| 3848 | + ->method('getNode') |
| 3849 | + ->willReturn($file); |
| 3850 | + $share |
| 3851 | + ->expects($this->exactly(2)) |
| 3852 | + ->method('getNodeId') |
| 3853 | + ->willReturn(2); |
| 3854 | + $share |
| 3855 | + ->expects($this->exactly(2)) |
| 3856 | + ->method('getPermissions') |
| 3857 | + ->willReturn(Constants::PERMISSION_SHARE); |
| 3858 | + |
| 3859 | + $this->shareManager |
| 3860 | + ->expects($this->once()) |
| 3861 | + ->method('getShareById') |
| 3862 | + ->with('ocinternal:1', $this->currentUser) |
| 3863 | + ->willReturn($share); |
| 3864 | + |
| 3865 | + $this->shareManager |
| 3866 | + ->expects($this->once()) |
| 3867 | + ->method('updateShare') |
| 3868 | + ->with($share) |
| 3869 | + ->willReturn($share); |
| 3870 | + |
| 3871 | + $result = $ocs->updateShare(1, Constants::PERMISSION_ALL); |
| 3872 | + $this->assertInstanceOf(DataResponse::class, $result); |
| 3873 | + } |
| 3874 | + |
3751 | 3875 | public function dataFormatShare() { |
3752 | 3876 | $file = $this->getMockBuilder(File::class)->getMock(); |
3753 | 3877 | $folder = $this->getMockBuilder(Folder::class)->getMock(); |
|
0 commit comments