Skip to content

Commit c2ca99e

Browse files
committed
fix(Share20\Manager): Ensure node is still accessible when checking share
Signed-off-by: provokateurin <[email protected]>
1 parent beea885 commit c2ca99e

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

lib/private/Share20/Manager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,15 @@ protected function checkShare(IShare $share): void {
14881488
$this->deleteShare($share);
14891489
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
14901490
}
1491+
1492+
try {
1493+
$share->getNode();
1494+
// Ignore share, file is still accessible
1495+
} catch (NotFoundException) {
1496+
// Access lost, but maybe only temporarily, so don't delete the share right away
1497+
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
1498+
}
1499+
14911500
if ($this->config->getAppValue('files_sharing', 'hide_disabled_user_shares', 'no') === 'yes') {
14921501
$uids = array_unique([$share->getShareOwner(),$share->getSharedBy()]);
14931502
foreach ($uids as $uid) {

tests/lib/Share20/ManagerTest.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use OCP\Files\Mount\IMountPoint;
2626
use OCP\Files\Mount\IShareOwnerlessMount;
2727
use OCP\Files\Node;
28+
use OCP\Files\NotFoundException;
2829
use OCP\Files\Storage\IStorage;
2930
use OCP\HintException;
3031
use OCP\IConfig;
@@ -667,6 +668,24 @@ public function testGetShareById(): void {
667668
}
668669

669670

671+
public function testGetShareByIdNodeAccessible(): void {
672+
$share = $this->createMock(IShare::class);
673+
$share
674+
->expects($this->once())
675+
->method('getNode')
676+
->willThrowException(new NotFoundException());
677+
678+
$this->defaultProvider
679+
->expects($this->once())
680+
->method('getShareById')
681+
->with(42)
682+
->willReturn($share);
683+
684+
$this->expectException(ShareNotFound::class);
685+
$this->manager->getShareById('default:42');
686+
}
687+
688+
670689
public function testGetExpiredShareById(): void {
671690
$this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
672691

@@ -2875,10 +2894,11 @@ public function testCreateShareOfIncomingFederatedShare(): void {
28752894
}
28762895

28772896
public function testGetSharesBy(): void {
2878-
$share = $this->manager->newShare();
2879-
28802897
$node = $this->createMock(Folder::class);
28812898

2899+
$share = $this->manager->newShare();
2900+
$share->setNode($node);
2901+
28822902
$this->defaultProvider->expects($this->once())
28832903
->method('getSharesBy')
28842904
->with(
@@ -2930,6 +2950,8 @@ public function testGetSharesByOwnerless(): void {
29302950
* deleted (as they are evaluated). but share 8 should still be there.
29312951
*/
29322952
public function testGetSharesByExpiredLinkShares(): void {
2953+
$node = $this->createMock(File::class);
2954+
29332955
$manager = $this->createManagerMock()
29342956
->setMethods(['deleteShare'])
29352957
->getMock();
@@ -2943,6 +2965,7 @@ public function testGetSharesByExpiredLinkShares(): void {
29432965
for ($i = 0; $i < 8; $i++) {
29442966
$share = $this->manager->newShare();
29452967
$share->setId($i);
2968+
$share->setNode($node);
29462969
$shares[] = $share;
29472970
}
29482971

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

2966-
$node = $this->createMock(File::class);
2967-
29682989
/*
29692990
* Simulate the getSharesBy call.
29702991
*/
@@ -3126,8 +3147,10 @@ public function testGetShareByTokenHideDisabledUser(): void {
31263147
$date = new \DateTime();
31273148
$date->setTime(0, 0, 0);
31283149
$date->add(new \DateInterval('P2D'));
3150+
$node = $this->createMock(File::class);
31293151
$share = $this->manager->newShare();
31303152
$share->setExpirationDate($date);
3153+
$share->setNode($node);
31313154
$share->setShareOwner('owner');
31323155
$share->setSharedBy('sharedBy');
31333156

@@ -3205,8 +3228,10 @@ public function testGetShareByTokenNotExpired(): void {
32053228
$date = new \DateTime();
32063229
$date->setTime(0, 0, 0);
32073230
$date->add(new \DateInterval('P2D'));
3231+
$node = $this->createMock(Folder::class);
32083232
$share = $this->manager->newShare();
32093233
$share->setExpirationDate($date);
3234+
$share->setNode($node);
32103235

32113236
$this->defaultProvider->expects($this->once())
32123237
->method('getShareByToken')

0 commit comments

Comments
 (0)