Skip to content

Commit 2a55cb5

Browse files
test(account): validate revocation call on pfx deletion
Inject CrlService in AccountService test setup and assert deletePfx behavior. Verify revocation is called with owner UID, reason code, and reason text before deleting the PFX. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 49a2fe8 commit 2a55cb5

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/php/Unit/Service/AccountServiceTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
use OCA\Libresign\Db\SignRequestMapper;
1818
use OCA\Libresign\Db\UserElement;
1919
use OCA\Libresign\Db\UserElementMapper;
20+
use OCA\Libresign\Enum\CRLReason;
2021
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
2122
use OCA\Libresign\Handler\SignEngine\Pkcs12Handler;
2223
use OCA\Libresign\Helper\FileUploadHelper;
2324
use OCA\Libresign\Helper\ValidateHelper;
2425
use OCA\Libresign\Service\AccountService;
26+
use OCA\Libresign\Service\Crl\CrlService;
2527
use OCA\Libresign\Service\FolderService;
2628
use OCA\Libresign\Service\IdDocsService;
2729
use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod;
@@ -81,6 +83,7 @@ final class AccountServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
8183
private RequestSignatureService&MockObject $requestSignatureService;
8284
private Pkcs12Handler&MockObject $pkcs12Handler;
8385
private FileUploadHelper&MockObject $uploadHelper;
86+
private CrlService&MockObject $crlService;
8487

8588
public function setUp(): void {
8689
parent::setUp();
@@ -115,6 +118,7 @@ public function setUp(): void {
115118
$this->clientService = $this->createMock(ClientService::class);
116119
$this->timeFactory = $this->createMock(TimeFactory::class);
117120
$this->uploadHelper = $this->createMock(FileUploadHelper::class);
121+
$this->crlService = $this->createMock(CrlService::class);
118122
}
119123

120124
private function getService(): AccountService {
@@ -146,10 +150,32 @@ private function getService(): AccountService {
146150
$this->folderService,
147151
$this->clientService,
148152
$this->timeFactory,
149-
$this->uploadHelper
153+
$this->uploadHelper,
154+
$this->crlService
150155
);
151156
}
152157

158+
public function testDeletePfxRevokesCertificatesWithReasonAndDeletesPfx(): void {
159+
$user = $this->createMock(IUser::class);
160+
$user->method('getUID')->willReturn('admin');
161+
162+
$this->crlService->expects($this->once())
163+
->method('revokeUserCertificates')
164+
->with(
165+
'admin',
166+
CRLReason::CESSATION_OF_OPERATION,
167+
'Certificate deleted by account owner.',
168+
'admin'
169+
)
170+
->willReturn(1);
171+
172+
$this->pkcs12Handler->expects($this->once())
173+
->method('deletePfx')
174+
->with('admin');
175+
176+
$this->getService()->deletePfx($user);
177+
}
178+
153179
#[DataProvider('provideValidateCertificateDataCases')]
154180
public function testValidateCertificateDataUsingDataProvider($arguments, $expectedErrorMessage):void {
155181
if (is_callable($arguments)) {

0 commit comments

Comments
 (0)