Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/files_sharing/lib/Listener/SharesUpdatedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\Share\Events\ShareMovedEvent;
use OCP\Share\Events\ShareTransferredEvent;
use OCP\Share\IManager;
use OCP\User\Exceptions\UserNotFoundException;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -135,7 +136,17 @@ private function markOrRun(IUser $user, callable $callback): void {
$elapsed = $now - $this->firstRun;

if ($this->cutOffMarkTime === -1.0 || $elapsed < $this->cutOffMarkTime) {
$callback();
try {
$callback();
} catch (UserNotFoundException $e) {
// A share recipient may reference a user id that no backend can resolve anymore
// (e.g. with LazyUser::getUID()) - like remnant / incorrectly removed user.
// Skip this recipient instead of aborting the share operation.
$this->logger->warning(
'Skipping share mount update for unresolvable user ' . $user->getUID(),
['app' => Application::APP_ID, 'exception' => $e],
);
}
} else {
$this->markUserForRefresh($user);
}
Expand Down
28 changes: 28 additions & 0 deletions apps/files_sharing/tests/SharesUpdatedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\IManager;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Clock\ClockInterface;
Expand Down Expand Up @@ -117,6 +118,33 @@ public function testShareAddedFilterOwner() {
$this->sharesUpdatedListener->handle($event);
}

public function testShareAddedSkipsUnresolvableUser(): void {
$share = $this->createMock(IShare::class);
$user1 = $this->createUser('user1', '');
$user2 = $this->createUser('user2', '');

$this->manager->method('getUsersForShare')
->willReturn([$user1, $user2]);

$event = new ShareCreatedEvent($share);

// user1 is an orphaned recipient that no backend can resolve
$this->shareRecipientUpdater
->expects($this->exactly(2))
->method('updateForAddedShare')
->willReturnCallback(function (IUser $user) use ($user1): void {
if ($user === $user1) {
throw new UserNotFoundException('Backends provided no user object');
}
});

// the failure is logged, not thrown
$this->logger->expects($this->once())->method('warning');

// must not throw: user2 is still processed
$this->sharesUpdatedListener->handle($event);
}

public function testShareAccessUpdated() {
$user1 = $this->createUser('user1', '');
$user2 = $this->createUser('user2', '');
Expand Down
Loading