Skip to content

Commit 6755ba9

Browse files
test(password-identify): assert exception codes for cert errors
Expand certificate validation tests to assert LibresignException error codes. Cover 422 for revoked, expired, invalid, and revocation-status-unverifiable certificate scenarios. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 2a55cb5 commit 6755ba9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/php/Unit/Service/IdentifyMethod/PasswordTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ public static function providerValidateToSignWithError(): array {
136136
}
137137

138138
#[DataProvider('providerValidateToSignWithCertificateData')]
139-
public function testValidateToSignWithCertificateData(array $certificateData, bool $shouldThrow, string $expectedMessage = ''): void {
139+
public function testValidateToSignWithCertificateData(
140+
array $certificateData,
141+
bool $shouldThrow,
142+
string $expectedMessage = '',
143+
?int $expectedCode = null,
144+
): void {
140145
$this->pkcs12Handler = $this->getPkcs12Instance(['getPfxOfCurrentSigner', 'setCertificate', 'setPassword', 'readCertificate']);
141146
$this->pkcs12Handler->method('getPfxOfCurrentSigner')->willReturn('mock-pfx');
142147
$this->pkcs12Handler->method('setCertificate')->willReturnSelf();
@@ -153,6 +158,9 @@ public function testValidateToSignWithCertificateData(array $certificateData, bo
153158
if ($expectedMessage) {
154159
$this->expectExceptionMessage($expectedMessage);
155160
}
161+
if ($expectedCode !== null) {
162+
$this->expectExceptionCode($expectedCode);
163+
}
156164
}
157165

158166
$password->validateToSign();
@@ -183,13 +191,15 @@ public static function providerValidateToSignWithCertificateData(): array {
183191
],
184192
'shouldThrow' => true,
185193
'expectedMessage' => 'Certificate has expired',
194+
'expectedCode' => 422,
186195
],
187196
'invalid certificate - validTo_time_t is string' => [
188197
'certificateData' => [
189198
'validTo_time_t' => '1234567890',
190199
],
191200
'shouldThrow' => true,
192201
'expectedMessage' => 'Invalid certificate',
202+
'expectedCode' => 422,
193203
],
194204
'invalid certificate - validTo_time_t is null' => [
195205
'certificateData' => [
@@ -233,6 +243,7 @@ public static function providerValidateToSignWithCertificateData(): array {
233243
],
234244
'shouldThrow' => true,
235245
'expectedMessage' => 'Certificate has been revoked',
246+
'expectedCode' => 422,
236247
],
237248
'valid certificate with crl validation' => [
238249
'certificateData' => [
@@ -255,6 +266,7 @@ public static function providerValidateToSignWithCertificateData(): array {
255266
],
256267
'shouldThrow' => true,
257268
'expectedMessage' => 'Certificate revocation status could not be verified',
269+
'expectedCode' => 422,
258270
],
259271
'invalid certificate - crl validation empty string' => [
260272
'certificateData' => [

0 commit comments

Comments
 (0)