|
19 | 19 | use OCP\Share\Events\ShareCreatedEvent; |
20 | 20 | use OCP\Share\IManager; |
21 | 21 | use OCP\Share\IShare; |
| 22 | +use OCP\User\Exceptions\UserNotFoundException; |
22 | 23 | use PHPUnit\Framework\Attributes\DataProvider; |
23 | 24 | use PHPUnit\Framework\MockObject\MockObject; |
24 | 25 | use Psr\Clock\ClockInterface; |
@@ -117,6 +118,33 @@ public function testShareAddedFilterOwner() { |
117 | 118 | $this->sharesUpdatedListener->handle($event); |
118 | 119 | } |
119 | 120 |
|
| 121 | + public function testShareAddedSkipsUnresolvableUser(): void { |
| 122 | + $share = $this->createMock(IShare::class); |
| 123 | + $user1 = $this->createUser('user1', ''); |
| 124 | + $user2 = $this->createUser('user2', ''); |
| 125 | + |
| 126 | + $this->manager->method('getUsersForShare') |
| 127 | + ->willReturn([$user1, $user2]); |
| 128 | + |
| 129 | + $event = new ShareCreatedEvent($share); |
| 130 | + |
| 131 | + // user1 is an orphaned recipient that no backend can resolve |
| 132 | + $this->shareRecipientUpdater |
| 133 | + ->expects($this->exactly(2)) |
| 134 | + ->method('updateForAddedShare') |
| 135 | + ->willReturnCallback(function (IUser $user) use ($user1): void { |
| 136 | + if ($user === $user1) { |
| 137 | + throw new UserNotFoundException('Backends provided no user object'); |
| 138 | + } |
| 139 | + }); |
| 140 | + |
| 141 | + // the failure is logged, not thrown |
| 142 | + $this->logger->expects($this->once())->method('warning'); |
| 143 | + |
| 144 | + // must not throw: user2 is still processed |
| 145 | + $this->sharesUpdatedListener->handle($event); |
| 146 | + } |
| 147 | + |
120 | 148 | public function testShareAccessUpdated() { |
121 | 149 | $user1 = $this->createUser('user1', ''); |
122 | 150 | $user2 = $this->createUser('user2', ''); |
|
0 commit comments