Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(Share20\Manager): Ensure node is still accessible when checking s…
…hare

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Nov 25, 2024
commit c2ca99e2f641396b6823c1e675afd3ecb486e744
9 changes: 9 additions & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,15 @@ protected function checkShare(IShare $share): void {
$this->deleteShare($share);
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
}

try {
$share->getNode();
// Ignore share, file is still accessible
} catch (NotFoundException) {
// Access lost, but maybe only temporarily, so don't delete the share right away
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
}

if ($this->config->getAppValue('files_sharing', 'hide_disabled_user_shares', 'no') === 'yes') {
$uids = array_unique([$share->getShareOwner(),$share->getSharedBy()]);
foreach ($uids as $uid) {
Expand Down
33 changes: 29 additions & 4 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Mount\IShareOwnerlessMount;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
use OCP\HintException;
use OCP\IConfig;
Expand Down Expand Up @@ -667,6 +668,24 @@ public function testGetShareById(): void {
}


public function testGetShareByIdNodeAccessible(): void {
$share = $this->createMock(IShare::class);
$share
->expects($this->once())
->method('getNode')
->willThrowException(new NotFoundException());

$this->defaultProvider
->expects($this->once())
->method('getShareById')
->with(42)
->willReturn($share);

$this->expectException(ShareNotFound::class);
$this->manager->getShareById('default:42');
}


public function testGetExpiredShareById(): void {
$this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);

Expand Down Expand Up @@ -2875,10 +2894,11 @@ public function testCreateShareOfIncomingFederatedShare(): void {
}

public function testGetSharesBy(): void {
$share = $this->manager->newShare();

$node = $this->createMock(Folder::class);

$share = $this->manager->newShare();
$share->setNode($node);

$this->defaultProvider->expects($this->once())
->method('getSharesBy')
->with(
Expand Down Expand Up @@ -2930,6 +2950,8 @@ public function testGetSharesByOwnerless(): void {
* deleted (as they are evaluated). but share 8 should still be there.
*/
public function testGetSharesByExpiredLinkShares(): void {
$node = $this->createMock(File::class);

$manager = $this->createManagerMock()
->setMethods(['deleteShare'])
->getMock();
Expand All @@ -2943,6 +2965,7 @@ public function testGetSharesByExpiredLinkShares(): void {
for ($i = 0; $i < 8; $i++) {
$share = $this->manager->newShare();
$share->setId($i);
$share->setNode($node);
$shares[] = $share;
}

Expand All @@ -2963,8 +2986,6 @@ public function testGetSharesByExpiredLinkShares(): void {
$shares2[] = clone $shares[$i];
}

$node = $this->createMock(File::class);

/*
* Simulate the getSharesBy call.
*/
Expand Down Expand Up @@ -3126,8 +3147,10 @@ public function testGetShareByTokenHideDisabledUser(): void {
$date = new \DateTime();
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P2D'));
$node = $this->createMock(File::class);
$share = $this->manager->newShare();
$share->setExpirationDate($date);
$share->setNode($node);
$share->setShareOwner('owner');
$share->setSharedBy('sharedBy');

Expand Down Expand Up @@ -3205,8 +3228,10 @@ public function testGetShareByTokenNotExpired(): void {
$date = new \DateTime();
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P2D'));
$node = $this->createMock(Folder::class);
$share = $this->manager->newShare();
$share->setExpirationDate($date);
$share->setNode($node);

$this->defaultProvider->expects($this->once())
->method('getShareByToken')
Expand Down