Skip to content

Commit db90023

Browse files
juliusknorrskjnldsv
authored andcommitted
Add tests for encoded group id
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 5252836 commit db90023

1 file changed

Lines changed: 74 additions & 10 deletions

File tree

apps/provisioning_api/tests/Controller/GroupsControllerTest.php

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ protected function setUp(): void {
7575
$this->userSession = $this->createMock(IUserSession::class);
7676
$this->accountManager = $this->createMock(AccountManager::class);
7777
$this->logger = $this->createMock(ILogger::class);
78-
78+
7979
$this->subAdminManager = $this->createMock(SubAdmin::class);
8080

8181
$this->groupManager
8282
->method('getSubAdmin')
8383
->willReturn($this->subAdminManager);
84-
84+
8585
$this->api = $this->getMockBuilder(GroupsController::class)
8686
->setConstructorArgs([
8787
'provisioning_api',
@@ -256,7 +256,6 @@ public function testGetGroupsDetails($search, $limit, $offset) {
256256
'disabled' => 11,
257257
'canAdd' => true,
258258
'canRemove' => true
259-
260259
]
261260
]], $result->getData());
262261
}
@@ -285,7 +284,7 @@ public function testGetGroupAsSubadmin() {
285284
$this->assertEquals(['users' => ['user1', 'user2']], $result->getData());
286285
}
287286

288-
287+
289288
public function testGetGroupAsIrrelevantSubadmin() {
290289
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
291290
$this->expectExceptionCode(403);
@@ -330,7 +329,7 @@ public function testGetGroupAsAdmin() {
330329
$this->assertEquals(['users' => ['user1', 'user2']], $result->getData());
331330
}
332331

333-
332+
334333
public function testGetGroupNonExisting() {
335334
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
336335
$this->expectExceptionMessage('The requested group could not be found');
@@ -341,7 +340,7 @@ public function testGetGroupNonExisting() {
341340
$this->api->getGroup($this->getUniqueID());
342341
}
343342

344-
343+
345344
public function testGetSubAdminsOfGroupsNotExists() {
346345
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
347346
$this->expectExceptionMessage('Group does not exist');
@@ -388,7 +387,7 @@ public function testGetSubAdminsOfGroupEmptyList() {
388387
$this->assertEquals([], $result->getData());
389388
}
390389

391-
390+
392391
public function testAddGroupEmptyGroup() {
393392
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
394393
$this->expectExceptionMessage('Invalid group name');
@@ -397,7 +396,7 @@ public function testAddGroupEmptyGroup() {
397396
$this->api->addGroup('');
398397
}
399398

400-
399+
401400
public function testAddGroupExistingGroup() {
402401
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
403402
$this->expectExceptionCode(102);
@@ -438,15 +437,15 @@ public function testAddGroupWithSpecialChar() {
438437
$this->api->addGroup('Iñtërnâtiônàlizætiøn');
439438
}
440439

441-
440+
442441
public function testDeleteGroupNonExisting() {
443442
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
444443
$this->expectExceptionCode(101);
445444

446445
$this->api->deleteGroup('NonExistingGroup');
447446
}
448447

449-
448+
450449
public function testDeleteAdminGroup() {
451450
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
452451
$this->expectExceptionCode(102);
@@ -478,6 +477,25 @@ public function testDeleteGroup() {
478477
$this->api->deleteGroup('ExistingGroup');
479478
}
480479

480+
public function testDeleteGroupEncoding() {
481+
$this->groupManager
482+
->method('groupExists')
483+
->with('ExistingGroup A/B')
484+
->willReturn('true');
485+
486+
$group = $this->createGroup('ExistingGroup');
487+
$this->groupManager
488+
->method('get')
489+
->with('ExistingGroup A/B')
490+
->willReturn($group);
491+
$group
492+
->expects($this->once())
493+
->method('delete')
494+
->willReturn(true);
495+
496+
$this->api->deleteGroup(urlencode('ExistingGroup A/B'));
497+
}
498+
481499
public function testGetGroupUsersDetails() {
482500
$gid = 'ncg1';
483501

@@ -523,4 +541,50 @@ public function testGetGroupUsersDetails() {
523541

524542
$this->api->getGroupUsersDetails($gid);
525543
}
544+
545+
public function testGetGroupUsersDetailsEncoded() {
546+
$gid = 'Department A/B C/D';
547+
548+
$this->asAdmin();
549+
$this->useAccountManager();
550+
551+
$users = [
552+
'ncu1' => $this->createUser('ncu1'), # regular
553+
'ncu2' => $this->createUser('ncu2'), # the zombie
554+
];
555+
$users['ncu2']->expects($this->atLeastOnce())
556+
->method('getHome')
557+
->willThrowException(new NoUserException());
558+
559+
$this->userManager->expects($this->any())
560+
->method('get')
561+
->willReturnCallback(function(string $uid) use ($users) {
562+
return isset($users[$uid]) ? $users[$uid] : null;
563+
});
564+
565+
$group = $this->createGroup($gid);
566+
$group->expects($this->once())
567+
->method('searchUsers')
568+
->with('', null, 0)
569+
->willReturn(array_values($users));
570+
571+
$this->groupManager
572+
->method('get')
573+
->with($gid)
574+
->willReturn($group);
575+
$this->groupManager->expects($this->any())
576+
->method('getUserGroups')
577+
->willReturn([$group]);
578+
579+
/** @var \PHPUnit_Framework_MockObject_MockObject */
580+
$this->subAdminManager->expects($this->any())
581+
->method('isSubAdminOfGroup')
582+
->willReturn(false);
583+
$this->subAdminManager->expects($this->any())
584+
->method('getSubAdminsGroups')
585+
->willReturn([]);
586+
587+
588+
$this->api->getGroupUsersDetails(urlencode($gid));
589+
}
526590
}

0 commit comments

Comments
 (0)