summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-04-02 19:37:40 +0200
committernpmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>2020-04-11 07:31:52 +0000
commited3aba1561125f679805582aae2a37dd811d0013 (patch)
tree3d5c8a9b42487b49365a13c65789b236a32062e8 /apps/provisioning_api
parent73cfc8dff971331a0583ea80ac56906b5243d56d (diff)
downloadnextcloud-server-ed3aba1561125f679805582aae2a37dd811d0013.tar.gz
nextcloud-server-ed3aba1561125f679805582aae2a37dd811d0013.zip
Add tests for encoded group id
Signed-off-by: Julius Härtl <jus@bitgrid.net> Signed-off-by: npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/tests/Controller/GroupsControllerTest.php83
1 files changed, 74 insertions, 9 deletions
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
index 742f621c6a4..fc971b115da 100644
--- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
@@ -74,13 +74,13 @@ class GroupsControllerTest extends \Test\TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->accountManager = $this->createMock(AccountManager::class);
$this->logger = $this->createMock(ILogger::class);
-
+
$this->subAdminManager = $this->createMock(SubAdmin::class);
$this->groupManager
->method('getSubAdmin')
->willReturn($this->subAdminManager);
-
+
$this->api = $this->getMockBuilder(GroupsController::class)
->setConstructorArgs([
'provisioning_api',
@@ -286,7 +286,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->assertEquals(['users' => ['user1', 'user2']], $result->getData());
}
-
+
public function testGetGroupAsIrrelevantSubadmin() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionCode(403);
@@ -331,7 +331,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->assertEquals(['users' => ['user1', 'user2']], $result->getData());
}
-
+
public function testGetGroupNonExisting() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionMessage('The requested group could not be found');
@@ -342,7 +342,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->getGroup($this->getUniqueID());
}
-
+
public function testGetSubAdminsOfGroupsNotExists() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionMessage('Group does not exist');
@@ -389,7 +389,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->assertEquals([], $result->getData());
}
-
+
public function testAddGroupEmptyGroup() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionMessage('Invalid group name');
@@ -398,7 +398,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->addGroup('');
}
-
+
public function testAddGroupExistingGroup() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionCode(102);
@@ -439,7 +439,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->addGroup('Iñtërnâtiônàlizætiøn');
}
-
+
public function testDeleteGroupNonExisting() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionCode(101);
@@ -447,7 +447,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->deleteGroup('NonExistingGroup');
}
-
+
public function testDeleteAdminGroup() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionCode(102);
@@ -479,6 +479,25 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->deleteGroup('ExistingGroup');
}
+ public function testDeleteGroupEncoding() {
+ $this->groupManager
+ ->method('groupExists')
+ ->with('ExistingGroup A/B')
+ ->willReturn('true');
+
+ $group = $this->createGroup('ExistingGroup');
+ $this->groupManager
+ ->method('get')
+ ->with('ExistingGroup A/B')
+ ->willReturn($group);
+ $group
+ ->expects($this->once())
+ ->method('delete')
+ ->willReturn(true);
+
+ $this->api->deleteGroup(urlencode('ExistingGroup A/B'));
+ }
+
public function testGetGroupUsersDetails() {
$gid = 'ncg1';
@@ -524,4 +543,50 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->getGroupUsersDetails($gid);
}
+
+ public function testGetGroupUsersDetailsEncoded() {
+ $gid = 'Department A/B C/D';
+
+ $this->asAdmin();
+ $this->useAccountManager();
+
+ $users = [
+ 'ncu1' => $this->createUser('ncu1'), # regular
+ 'ncu2' => $this->createUser('ncu2'), # the zombie
+ ];
+ $users['ncu2']->expects($this->atLeastOnce())
+ ->method('getHome')
+ ->willThrowException(new NoUserException());
+
+ $this->userManager->expects($this->any())
+ ->method('get')
+ ->willReturnCallback(function(string $uid) use ($users) {
+ return isset($users[$uid]) ? $users[$uid] : null;
+ });
+
+ $group = $this->createGroup($gid);
+ $group->expects($this->once())
+ ->method('searchUsers')
+ ->with('', null, 0)
+ ->willReturn(array_values($users));
+
+ $this->groupManager
+ ->method('get')
+ ->with($gid)
+ ->willReturn($group);
+ $this->groupManager->expects($this->any())
+ ->method('getUserGroups')
+ ->willReturn([$group]);
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ $this->subAdminManager->expects($this->any())
+ ->method('isSubAdminOfGroup')
+ ->willReturn(false);
+ $this->subAdminManager->expects($this->any())
+ ->method('getSubAdminsGroups')
+ ->willReturn([]);
+
+
+ $this->api->getGroupUsersDetails(urlencode($gid));
+ }
}