diff options
author | Thomas Citharel <tcit@tcit.fr> | 2021-02-15 16:12:33 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2021-05-26 11:19:59 +0200 |
commit | 1c0d975654f71a1ac6a3d30ece915fa6e55397da (patch) | |
tree | 9499160ad9d01b7ee2e28b711e4e1cf6a5493586 /apps/dav/tests | |
parent | e4b5645883d89ee3aca4105c1bde6ae4939f927c (diff) | |
download | nextcloud-server-1c0d975654f71a1ac6a3d30ece915fa6e55397da.tar.gz nextcloud-server-1c0d975654f71a1ac6a3d30ece915fa6e55397da.zip |
Make dav respect disallowing sharing with groups
Closes #25390
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/DAV/GroupPrincipalTest.php | 73 |
1 files changed, 49 insertions, 24 deletions
diff --git a/apps/dav/tests/unit/DAV/GroupPrincipalTest.php b/apps/dav/tests/unit/DAV/GroupPrincipalTest.php index ba079fb9cad..7e80930bc76 100644 --- a/apps/dav/tests/unit/DAV/GroupPrincipalTest.php +++ b/apps/dav/tests/unit/DAV/GroupPrincipalTest.php @@ -38,19 +38,20 @@ use OCP\IGroupManager; use OCP\IUser; use OCP\IUserSession; use OCP\Share\IManager; +use PHPUnit\Framework\MockObject\MockObject; use Sabre\DAV\PropPatch; class GroupPrincipalTest extends \Test\TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|MockObject */ private $config; - /** @var IGroupManager | \PHPUnit\Framework\MockObject\MockObject */ + /** @var IGroupManager | MockObject */ private $groupManager; - /** @var IUserSession | \PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession | MockObject */ private $userSession; - /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */ + /** @var IManager | MockObject */ private $shareManager; /** @var GroupPrincipalBackend */ @@ -224,13 +225,22 @@ class GroupPrincipalTest extends \Test\TestCase { /** * @dataProvider searchPrincipalsDataProvider + * @param bool $sharingEnabled + * @param bool $groupSharingEnabled + * @param bool $groupsOnly + * @param string $test + * @param array $result */ - public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $result) { + public function testSearchPrincipals(bool $sharingEnabled, bool $groupSharingEnabled, bool $groupsOnly, string $test, array $result): void { $this->shareManager->expects($this->once()) ->method('shareAPIEnabled') ->willReturn($sharingEnabled); - if ($sharingEnabled) { + $this->shareManager->expects($sharingEnabled ? $this->once() : $this->never()) + ->method('allowGroupSharing') + ->willReturn($groupSharingEnabled); + + if ($sharingEnabled && $groupSharingEnabled) { $this->shareManager->expects($this->once()) ->method('shareWithGroupMembersOnly') ->willReturn($groupsOnly); @@ -264,7 +274,7 @@ class GroupPrincipalTest extends \Test\TestCase { $group5 = $this->createMock(IGroup::class); $group5->method('getGID')->willReturn('group5'); - if ($sharingEnabled) { + if ($sharingEnabled && $groupSharingEnabled) { $this->groupManager->expects($this->once()) ->method('search') ->with('Foo') @@ -280,24 +290,35 @@ class GroupPrincipalTest extends \Test\TestCase { public function searchPrincipalsDataProvider() { return [ - [true, false, 'allof', ['principals/groups/group1', 'principals/groups/group2', 'principals/groups/group3', 'principals/groups/group4', 'principals/groups/group5']], - [true, false, 'anyof', ['principals/groups/group1', 'principals/groups/group2', 'principals/groups/group3', 'principals/groups/group4', 'principals/groups/group5']], - [true, true, 'allof', ['principals/groups/group1', 'principals/groups/group2', 'principals/groups/group5']], - [true, true, 'anyof', ['principals/groups/group1', 'principals/groups/group2', 'principals/groups/group5']], - [false, false, 'allof', []], - [false, false, 'anyof', []], + [true, true, false, 'allof', ['principals/groups/group1', 'principals/groups/group2', 'principals/groups/group3', 'principals/groups/group4', 'principals/groups/group5']], + [true, true, false, 'anyof', ['principals/groups/group1', 'principals/groups/group2', 'principals/groups/group3', 'principals/groups/group4', 'principals/groups/group5']], + [true, true, true, 'allof', ['principals/groups/group1', 'principals/groups/group2', 'principals/groups/group5']], + [true, true, true, 'anyof', ['principals/groups/group1', 'principals/groups/group2', 'principals/groups/group5']], + [true, false, false, 'allof', []], + [false, true, false, 'anyof', []], + [false, false, false, 'allof', []], + [false, false, false, 'anyof', []], ]; } /** * @dataProvider findByUriDataProvider + * @param bool $sharingEnabled + * @param bool $groupSharingEnabled + * @param bool $groupsOnly + * @param string $findUri + * @param string|null $result */ - public function testFindByUri($sharingEnabled, $groupsOnly, $findUri, $result) { + public function testFindByUri(bool $sharingEnabled, bool $groupSharingEnabled, bool $groupsOnly, string $findUri, ?string $result): void { $this->shareManager->expects($this->once()) ->method('shareAPIEnabled') ->willReturn($sharingEnabled); - if ($sharingEnabled) { + $this->shareManager->expects($sharingEnabled ? $this->once() : $this->never()) + ->method('allowGroupSharing') + ->willReturn($groupSharingEnabled); + + if ($sharingEnabled && $groupSharingEnabled) { $this->shareManager->expects($this->once()) ->method('shareWithGroupMembersOnly') ->willReturn($groupsOnly); @@ -325,19 +346,23 @@ class GroupPrincipalTest extends \Test\TestCase { public function findByUriDataProvider() { return [ - [false, false, 'principal:principals/groups/group1', null], - [false, false, 'principal:principals/groups/group3', null], - [false, true, 'principal:principals/groups/group1', null], - [false, true, 'principal:principals/groups/group3', null], - [true, true, 'principal:principals/groups/group1', 'principals/groups/group1'], - [true, true, 'principal:principals/groups/group3', null], - [true, false, 'principal:principals/groups/group1', 'principals/groups/group1'], - [true, false, 'principal:principals/groups/group3', 'principals/groups/group3'], + [false, false, false, 'principal:principals/groups/group1', null], + [false, false, false, 'principal:principals/groups/group3', null], + [false, true, false, 'principal:principals/groups/group1', null], + [false, true, false, 'principal:principals/groups/group3', null], + [false, false, true, 'principal:principals/groups/group1', null], + [false, false, true, 'principal:principals/groups/group3', null], + [true, false, true, 'principal:principals/groups/group1', null], + [true, false, true, 'principal:principals/groups/group3', null], + [true, true, true, 'principal:principals/groups/group1', 'principals/groups/group1'], + [true, true, true, 'principal:principals/groups/group3', null], + [true, true, false, 'principal:principals/groups/group1', 'principals/groups/group1'], + [true, true, false, 'principal:principals/groups/group3', 'principals/groups/group3'], ]; } /** - * @return Group|\PHPUnit\Framework\MockObject\MockObject + * @return Group|MockObject */ private function mockGroup($gid) { $fooGroup = $this->createMock(Group::class); |