aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Share20
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-12-22 21:44:21 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2017-04-13 12:58:50 +0200
commit2cbac3357ba445a3a4cd073e119efb871ea0f719 (patch)
tree42f12e6334f0f14b8f122bf1355f325366123396 /tests/lib/Share20
parent97f8ca6595caf051eae9c9261bdbd481c9dd4be1 (diff)
downloadnextcloud-server-2cbac3357ba445a3a4cd073e119efb871ea0f719.tar.gz
nextcloud-server-2cbac3357ba445a3a4cd073e119efb871ea0f719.zip
Offload acceslist creation to providers
* This allows for effective queries. * Introduce currentAccess parameter to speciy if the users needs to have currently acces (deleted incomming group share). (For notifications) Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/lib/Share20')
-rw-r--r--tests/lib/Share20/DefaultShareProviderTest.php175
-rw-r--r--tests/lib/Share20/ManagerTest.php98
2 files changed, 232 insertions, 41 deletions
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php
index fce5668440d..ccc9f0f5112 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -2434,4 +2434,179 @@ class DefaultShareProviderTest extends \Test\TestCase {
$u3->delete();
$g1->delete();
}
+
+ public function testGetAccessListNoCurrentAccessRequired() {
+ $userManager = \OC::$server->getUserManager();
+ $groupManager = \OC::$server->getGroupManager();
+ $rootFolder = \OC::$server->getRootFolder();
+
+ $provider = new DefaultShareProvider(
+ $this->dbConn,
+ $userManager,
+ $groupManager,
+ $rootFolder
+ );
+
+ $u1 = $userManager->createUser('testShare1', 'test');
+ $u2 = $userManager->createUser('testShare2', 'test');
+ $u3 = $userManager->createUser('testShare3', 'test');
+ $u4 = $userManager->createUser('testShare4', 'test');
+ $u5 = $userManager->createUser('testShare5', 'test');
+
+ $g1 = $groupManager->createGroup('group1');
+ $g1->addUser($u3);
+ $g1->addUser($u4);
+
+ $u1Folder = $rootFolder->getUserFolder($u1->getUID());
+ $folder1 = $u1Folder->newFolder('foo');
+ $folder2 = $folder1->newFolder('baz');
+ $file1 = $folder2->newFile('bar');
+
+ $shareManager = \OC::$server->getShareManager();
+ $share1 = $shareManager->newShare();
+ $share1->setNode($folder1)
+ ->setSharedBy($u1->getUID())
+ ->setSharedWith($u2->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share1 = $this->provider->create($share1);
+
+ $share2 = $shareManager->newShare();
+ $share2->setNode($folder2)
+ ->setSharedBy($u2->getUID())
+ ->setSharedWith($g1->getGID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share2 = $this->provider->create($share2);
+
+ $shareManager->deleteFromSelf($share2, $u4->getUID());
+
+ $share3 = $shareManager->newShare();
+ $share3->setNode($file1)
+ ->setSharedBy($u3->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share3 = $this->provider->create($share3);
+
+ $share4 = $shareManager->newShare();
+ $share4->setNode($file1)
+ ->setSharedBy($u3->getUID())
+ ->setSharedWith($u5->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share4 = $this->provider->create($share4);
+
+ $result = $provider->getAccessList([$folder1, $folder2, $file1], false);
+
+ $this->assertCount(4, $result['users']);
+ $this->assertContains('testShare2', $result['users']);
+ $this->assertContains('testShare3', $result['users']);
+ $this->assertContains('testShare4', $result['users']);
+ $this->assertContains('testShare5', $result['users']);
+ $this->assertTrue($result['public']);
+ $this->assertFalse($result['remote']);
+
+ $provider->delete($share1);
+ $provider->delete($share2);
+ $provider->delete($share3);
+ $provider->delete($share4);
+
+ $u1->delete();
+ $u2->delete();
+ $u3->delete();
+ $u4->delete();
+ $u5->delete();
+ $g1->delete();
+ }
+
+ public function testGetAccessListCurrentAccessRequired() {
+ $userManager = \OC::$server->getUserManager();
+ $groupManager = \OC::$server->getGroupManager();
+ $rootFolder = \OC::$server->getRootFolder();
+
+ $provider = new DefaultShareProvider(
+ $this->dbConn,
+ $userManager,
+ $groupManager,
+ $rootFolder
+ );
+
+ $u1 = $userManager->createUser('testShare1', 'test');
+ $u2 = $userManager->createUser('testShare2', 'test');
+ $u3 = $userManager->createUser('testShare3', 'test');
+ $u4 = $userManager->createUser('testShare4', 'test');
+ $u5 = $userManager->createUser('testShare5', 'test');
+
+ $g1 = $groupManager->createGroup('group1');
+ $g1->addUser($u3);
+ $g1->addUser($u4);
+
+ $u1Folder = $rootFolder->getUserFolder($u1->getUID());
+ $folder1 = $u1Folder->newFolder('foo');
+ $folder2 = $folder1->newFolder('baz');
+ $file1 = $folder2->newFile('bar');
+
+ $shareManager = \OC::$server->getShareManager();
+ $share1 = $shareManager->newShare();
+ $share1->setNode($folder1)
+ ->setSharedBy($u1->getUID())
+ ->setSharedWith($u2->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share1 = $this->provider->create($share1);
+
+ $share2 = $shareManager->newShare();
+ $share2->setNode($folder2)
+ ->setSharedBy($u2->getUID())
+ ->setSharedWith($g1->getGID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share2 = $this->provider->create($share2);
+
+ $shareManager->deleteFromSelf($share2, $u4->getUID());
+
+ $share3 = $shareManager->newShare();
+ $share3->setNode($file1)
+ ->setSharedBy($u3->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share3 = $this->provider->create($share3);
+
+ $share4 = $shareManager->newShare();
+ $share4->setNode($file1)
+ ->setSharedBy($u3->getUID())
+ ->setSharedWith($u5->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share4 = $this->provider->create($share4);
+
+ $result = $provider->getAccessList([$folder1, $folder2, $file1], true);
+
+ $this->assertCount(3, $result['users']);
+ $this->assertContains('testShare2', $result['users']);
+ $this->assertContains('testShare3', $result['users']);
+ $this->assertContains('testShare5', $result['users']);
+ $this->assertTrue($result['public']);
+ $this->assertFalse($result['remote']);
+
+ $provider->delete($share1);
+ $provider->delete($share2);
+ $provider->delete($share3);
+ $provider->delete($share4);
+
+ $u1->delete();
+ $u2->delete();
+ $u3->delete();
+ $u4->delete();
+ $u5->delete();
+ $g1->delete();
+ }
}
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index abfe2ca9c12..ab42cb4813b 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -2738,6 +2738,26 @@ class ManagerTest extends \Test\TestCase {
}
public function testGetAccessList() {
+ $factory = new DummyFactory2($this->createMock(IServerContainer::class));
+
+ $manager = new Manager(
+ $this->logger,
+ $this->config,
+ $this->secureRandom,
+ $this->hasher,
+ $this->mountManager,
+ $this->groupManager,
+ $this->l,
+ $factory,
+ $this->userManager,
+ $this->rootFolder,
+ $this->eventDispatcher
+ );
+
+ $factory->setProvider($this->defaultProvider);
+ $extraProvider = $this->createMock(IShareProvider::class);
+ $factory->setSecondProvider($extraProvider);
+
$owner = $this->createMock(IUser::class);
$owner->expects($this->once())
->method('getUID')
@@ -2769,60 +2789,56 @@ class ManagerTest extends \Test\TestCase {
$userFolder->method('getPath')
->willReturn('/owner/files');
- $userShare = $this->createMock(IShare::class);
- $userShare->method('getShareType')
- ->willReturn(\OCP\Share::SHARE_TYPE_USER);
- $userShare->method('getSharedWith')
- ->willReturn('user1');
- $groupShare = $this->createMock(IShare::class);
- $groupShare->method('getShareType')
- ->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
- $groupShare->method('getSharedWith')
- ->willReturn('group1');
- $publicShare = $this->createMock(IShare::class);
- $publicShare->method('getShareType')
- ->willReturn(\OCP\Share::SHARE_TYPE_LINK);
- $remoteShare = $this->createMock(IShare::class);
- $remoteShare->method('getShareType')
- ->willReturn(\OCP\Share::SHARE_TYPE_REMOTE);
-
$this->userManager->method('userExists')
- ->with($this->equalTo('user1'))
+ ->with($this->equalTo('owner'))
->willReturn(true);
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')
- ->willReturn('user2');
- $group1 = $this->createMock(IGroup::class);
- $this->groupManager->method('get')
- ->with($this->equalTo('group1'))
- ->willReturn($group1);
- $group1->method('getUsers')
- ->willReturn([$user2]);
-
- $this->defaultProvider->expects($this->any())
- ->method('getSharesByPath')
- ->will($this->returnCallback(function(Node $path) use ($file, $folder, $userShare, $groupShare, $publicShare, $remoteShare) {
- if ($path === $file) {
- return [$userShare, $publicShare];
- } else if ($path === $folder) {
- return [$groupShare, $remoteShare];
- } else {
- return [];
- }
- }));
+ $this->defaultProvider->method('getAccessList')
+ ->with(
+ $this->equalTo([$file, $folder]),
+ true
+ )
+ ->willReturn([
+ 'users' => [
+ 'user1',
+ 'user2',
+ 'user3',
+ ],
+ 'remote' => false,
+ 'public' => true,
+ ]);
+
+ $extraProvider->method('getAccessList')
+ ->with(
+ $this->equalTo([$file, $folder]),
+ true
+ )
+ ->willReturn([
+ 'users' => [
+ 'user3',
+ 'user4',
+ 'user5',
+ ],
+ 'remote' => true,
+ 'public' => false,
+ ]);
$this->rootFolder->method('getUserFolder')
->with($this->equalTo('owner'))
->willReturn($userFolder);
$expected = [
- 'users' => ['owner', 'user1', 'user2'],
+ 'users' => ['owner', 'user1', 'user2', 'user3', 'user4', 'user5'],
'public' => true,
'remote' => true,
];
- $this->assertEquals($expected, $this->manager->getAccessList($node));
+ $result = $manager->getAccessList($node, true, true);
+
+ $this->assertSame($expected['public'], $result['public']);
+ $this->assertSame($expected['remote'], $result['remote']);
+ $this->assertSame(array_values($expected['users']), array_values($result['users']));
+
}
}