Skip to content

Commit 8ad90d1

Browse files
committed
test(account): cover subadmin group policy capability
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent fca820a commit 8ad90d1

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/php/Unit/Service/AccountServiceTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCP\Files\IMimeTypeDetector;
4545
use OCP\Files\IRootFolder;
4646
use OCP\Files\NotFoundException;
47+
use OCP\Group\ISubAdmin;
4748
use OCP\IAppConfig;
4849
use OCP\IGroupManager;
4950
use OCP\IL10N;
@@ -77,6 +78,7 @@ final class AccountServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
7778
private ValidateHelper&MockObject $validateHelper;
7879
private IURLGenerator&MockObject $urlGenerator;
7980
private IGroupManager&MockObject $groupManager;
81+
private ISubAdmin&MockObject $subAdmin;
8082
private IdDocsService&MockObject $idDocsService;
8183
private SignerElementsService&MockObject $signerElementsService;
8284
private UserElementMapper&MockObject $userElementMapper;
@@ -114,6 +116,7 @@ public function setUp(): void {
114116
$this->urlGenerator = $this->createMock(IURLGenerator::class);
115117
$this->pkcs12Handler = $this->createMock(Pkcs12Handler::class);
116118
$this->groupManager = $this->createMock(IGroupManager::class);
119+
$this->subAdmin = $this->createMock(ISubAdmin::class);
117120
$this->idDocsService = $this->createMock(IdDocsService::class);
118121
$this->signerElementsService = $this->createMock(SignerElementsService::class);
119122
$this->userElementMapper = $this->createMock(UserElementMapper::class);
@@ -147,6 +150,7 @@ private function getService(): AccountService {
147150
$this->urlGenerator,
148151
$this->pkcs12Handler,
149152
$this->groupManager,
153+
$this->subAdmin,
150154
$this->idDocsService,
151155
$this->signerElementsService,
152156
$this->userElementMapper,
@@ -179,6 +183,25 @@ public function testDeletePfxRevokesCertificatesWithReasonAndDeletesPfx(): void
179183
$this->getService()->deletePfx($user);
180184
}
181185

186+
public function testGetConfigSetsCanManageGroupPoliciesForSubAdmin(): void {
187+
$user = $this->createMock(IUser::class);
188+
$user->method('getUID')->willReturn('group-admin-user');
189+
190+
$this->groupManager->method('isAdmin')
191+
->with('group-admin-user')
192+
->willReturn(false);
193+
194+
$this->subAdmin->expects($this->once())
195+
->method('isSubAdmin')
196+
->with($user)
197+
->willReturn(true);
198+
199+
$config = $this->getService()->getConfig($user);
200+
201+
$this->assertArrayHasKey('can_manage_group_policies', $config);
202+
$this->assertTrue($config['can_manage_group_policies']);
203+
}
204+
182205
#[DataProvider('provideValidateCertificateDataCases')]
183206
public function testValidateCertificateDataUsingDataProvider($arguments, $expectedErrorMessage):void {
184207
if (is_callable($arguments)) {

0 commit comments

Comments
 (0)