diff options
author | Kate <26026535+provokateurin@users.noreply.github.com> | 2024-11-25 14:41:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-25 14:41:40 +0100 |
commit | 235b7d7c26930367533f2e845bb2180ba9151608 (patch) | |
tree | 26c2c38d2a3a3fe687866fb617647983987d44f3 /tests | |
parent | 5088b910ec4a8c003ec22822741f1664eab90175 (diff) | |
parent | 7c3a78ad7695eeebe37ed0b15def92599bf43d2f (diff) | |
download | nextcloud-server-235b7d7c26930367533f2e845bb2180ba9151608.tar.gz nextcloud-server-235b7d7c26930367533f2e845bb2180ba9151608.zip |
Merge pull request #49073 from nextcloud/feat/files_sharing/co-owner
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Share20/DefaultShareProviderTest.php | 85 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 102 |
2 files changed, 183 insertions, 4 deletions
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 0351504e1a7..394ca41c1ae 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -7,6 +7,7 @@ namespace Test\Share20; +use OC\Files\Node\Node; use OC\Share20\DefaultShareProvider; use OC\Share20\ShareAttributes; use OCP\AppFramework\Utility\ITimeFactory; @@ -3013,4 +3014,88 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals('token5', $share->getToken()); $this->assertEquals('myTarget5', $share->getTarget()); } + + + public function testGetSharesByPath(): void { + $qb = $this->dbConn->getQueryBuilder(); + + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(IShare::TYPE_USER), + 'uid_owner' => $qb->expr()->literal('user1'), + 'uid_initiator' => $qb->expr()->literal('user1'), + 'share_with' => $qb->expr()->literal('user2'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(1), + ]); + $qb->execute(); + + $id1 = $qb->getLastInsertId(); + + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP), + 'uid_owner' => $qb->expr()->literal('user1'), + 'uid_initiator' => $qb->expr()->literal('user1'), + 'share_with' => $qb->expr()->literal('user2'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(1), + ]); + $qb->execute(); + + $id2 = $qb->getLastInsertId(); + + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK), + 'uid_owner' => $qb->expr()->literal('user1'), + 'uid_initiator' => $qb->expr()->literal('user1'), + 'share_with' => $qb->expr()->literal('user2'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(1), + ]); + $qb->execute(); + + $id3 = $qb->getLastInsertId(); + + $ownerPath1 = $this->createMock(File::class); + $shareOwner1Folder = $this->createMock(Folder::class); + $shareOwner1Folder->method('getFirstNodeById')->willReturn($ownerPath1); + + $ownerPath2 = $this->createMock(File::class); + $shareOwner2Folder = $this->createMock(Folder::class); + $shareOwner2Folder->method('getFirstNodeById')->willReturn($ownerPath2); + + $ownerPath3 = $this->createMock(File::class); + $shareOwner3Folder = $this->createMock(Folder::class); + $shareOwner3Folder->method('getFirstNodeById')->willReturn($ownerPath3); + + $this->rootFolder + ->method('getUserFolder') + ->willReturnMap( + [ + ['shareOwner1', $shareOwner1Folder], + ['shareOwner2', $shareOwner2Folder], + ['shareOwner3', $shareOwner3Folder], + ] + ); + + $node = $this->createMock(Node::class); + $node + ->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $shares = $this->provider->getSharesByPath($node); + $this->assertCount(3, $shares); + + $this->assertEquals($id1, $shares[0]->getId()); + $this->assertEquals(IShare::TYPE_USER, $shares[0]->getShareType()); + + $this->assertEquals($id2, $shares[1]->getId()); + $this->assertEquals(IShare::TYPE_GROUP, $shares[1]->getShareType()); + + $this->assertEquals($id3, $shares[2]->getId()); + $this->assertEquals(IShare::TYPE_LINK, $shares[2]->getShareType()); + } } diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index a4c1dd3803d..79a88f9af9e 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -23,7 +23,9 @@ use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountManager; 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; @@ -666,6 +668,24 @@ class ManagerTest extends \Test\TestCase { } + 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); @@ -2874,10 +2894,11 @@ class ManagerTest extends \Test\TestCase { } 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( @@ -2895,6 +2916,31 @@ class ManagerTest extends \Test\TestCase { $this->assertSame($share, $shares[0]); } + public function testGetSharesByOwnerless(): void { + $mount = $this->createMock(IShareOwnerlessMount::class); + + $node = $this->createMock(Folder::class); + $node + ->expects($this->once()) + ->method('getMountPoint') + ->willReturn($mount); + + $share = $this->manager->newShare(); + $share->setNode($node); + $share->setShareType(IShare::TYPE_USER); + + $this->defaultProvider + ->expects($this->once()) + ->method('getSharesByPath') + ->with($this->equalTo($node)) + ->willReturn([$share]); + + $shares = $this->manager->getSharesBy('user', IShare::TYPE_USER, $node, true, 1, 1); + + $this->assertCount(1, $shares); + $this->assertSame($share, $shares[0]); + } + /** * Test to ensure we correctly remove expired link shares * @@ -2904,6 +2950,8 @@ class ManagerTest extends \Test\TestCase { * 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(); @@ -2917,6 +2965,7 @@ class ManagerTest extends \Test\TestCase { for ($i = 0; $i < 8; $i++) { $share = $this->manager->newShare(); $share->setId($i); + $share->setNode($node); $shares[] = $share; } @@ -2937,8 +2986,6 @@ class ManagerTest extends \Test\TestCase { $shares2[] = clone $shares[$i]; } - $node = $this->createMock(File::class); - /* * Simulate the getSharesBy call. */ @@ -3100,8 +3147,10 @@ class ManagerTest extends \Test\TestCase { $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'); @@ -3179,8 +3228,10 @@ class ManagerTest extends \Test\TestCase { $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') @@ -4493,6 +4544,49 @@ class ManagerTest extends \Test\TestCase { $this->assertSame($expects, $result); } + public function testGetSharesInFolderOwnerless(): void { + $factory = new DummyFactory2($this->createMock(IServerContainer::class)); + + $manager = $this->createManager($factory); + + $factory->setProvider($this->defaultProvider); + $extraProvider = $this->createMock(IShareProvider::class); + $factory->setSecondProvider($extraProvider); + + $share1 = $this->createMock(IShare::class); + $share2 = $this->createMock(IShare::class); + + $mount = $this->createMock(IShareOwnerlessMount::class); + + $file = $this->createMock(File::class); + $file + ->method('getId') + ->willReturn(1); + + $folder = $this->createMock(Folder::class); + $folder + ->method('getMountPoint') + ->willReturn($mount); + $folder + ->method('getDirectoryListing') + ->willReturn([$file]); + + $this->defaultProvider + ->method('getSharesByPath') + ->with($file) + ->willReturn([$share1]); + + $extraProvider + ->method('getSharesByPath') + ->with($file) + ->willReturn([$share2]); + + $this->assertSame([ + 1 => [$share1, $share2], + ], $manager->getSharesInFolder('user', $folder)); + } + + public function testGetAccessList(): void { $factory = new DummyFactory2($this->createMock(IServerContainer::class)); |