|
32 | 32 | use OCP\IUserManager; |
33 | 33 | use OCP\Security\ISecureRandom; |
34 | 34 | use OCP\Server; |
| 35 | +use OCP\Share\Exceptions\AlreadySharedException; |
35 | 36 | use OCP\Share\IManager; |
36 | 37 | use OCP\Share\IShare; |
37 | 38 | use PHPUnit\Framework\MockObject\MockObject; |
@@ -418,6 +419,66 @@ public function testCreateAlreadyShared(): void { |
418 | 419 | } |
419 | 420 | } |
420 | 421 |
|
| 422 | + public static function dataTestCreateAlreadySharedWithEquivalentCloudId(): array { |
| 423 | + return [ |
| 424 | + ['user@server.com'], |
| 425 | + ['user@server.com/'], |
| 426 | + ['user@server.com/index.php'], |
| 427 | + ]; |
| 428 | + } |
| 429 | + |
| 430 | + /** |
| 431 | + * Sharing a node with a recipient it is already shared with has to be |
| 432 | + * rejected with an AlreadySharedException, for every spelling that |
| 433 | + * normalizes to the same cloud ID. |
| 434 | + */ |
| 435 | + #[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestCreateAlreadySharedWithEquivalentCloudId')] |
| 436 | + public function testCreateAlreadySharedWithEquivalentCloudId(string $shareWith): void { |
| 437 | + $node = $this->createMock(File::class); |
| 438 | + $node->method('getId')->willReturn(42); |
| 439 | + $node->method('getName')->willReturn('myFile'); |
| 440 | + |
| 441 | + $this->addressHandler->expects($this->any())->method('splitUserRemote') |
| 442 | + ->willReturn(['user', 'server.com']); |
| 443 | + $this->addressHandler->expects($this->any())->method('generateRemoteURL') |
| 444 | + ->willReturn('http://localhost/'); |
| 445 | + $this->tokenHandler->method('generateToken')->willReturn('token'); |
| 446 | + $this->contactsManager->expects($this->any())->method('search') |
| 447 | + ->willReturn([]); |
| 448 | + $this->notifications->expects($this->once()) |
| 449 | + ->method('sendRemoteShare') |
| 450 | + ->willReturn(true); |
| 451 | + |
| 452 | + $share = $this->shareManager->newShare(); |
| 453 | + $share->setSharedWith('user@server.com') |
| 454 | + ->setSharedBy('sharedBy') |
| 455 | + ->setShareOwner('shareOwner') |
| 456 | + ->setPermissions(19) |
| 457 | + ->setShareType(IShare::TYPE_REMOTE) |
| 458 | + ->setNode($node) |
| 459 | + ->setTarget(''); |
| 460 | + $existingShare = $this->provider->create($share); |
| 461 | + |
| 462 | + // a recipient of the node re-sharing it with the same account |
| 463 | + $duplicate = $this->shareManager->newShare(); |
| 464 | + $duplicate->setSharedWith($shareWith) |
| 465 | + ->setSharedBy('otherRecipient') |
| 466 | + ->setShareOwner('shareOwner') |
| 467 | + ->setPermissions(19) |
| 468 | + ->setShareType(IShare::TYPE_REMOTE) |
| 469 | + ->setNode($node) |
| 470 | + ->setTarget(''); |
| 471 | + |
| 472 | + try { |
| 473 | + $this->provider->create($duplicate); |
| 474 | + $this->fail('Expected an AlreadySharedException'); |
| 475 | + } catch (AlreadySharedException $e) { |
| 476 | + $this->assertEquals($existingShare->getId(), $e->getExistingShare()->getId()); |
| 477 | + } |
| 478 | + |
| 479 | + $this->assertCount(1, $this->provider->getSharesByPath($node)); |
| 480 | + } |
| 481 | + |
421 | 482 | #[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestUpdate')] |
422 | 483 | public function testUpdate(string $owner, string $sharedBy, ?\DateTime $expirationDate): void { |
423 | 484 | $this->provider = $this->getMockBuilder(FederatedShareProvider::class) |
|
0 commit comments