@@ -139,7 +139,6 @@ public static function providerValidateToSignWithError(): array {
139139 public function testValidateToSignWithCertificateData (
140140 array $ certificateData ,
141141 bool $ shouldThrow ,
142- string $ expectedMessage = '' ,
143142 ?int $ expectedCode = null ,
144143 ): void {
145144 $ this ->pkcs12Handler = $ this ->getPkcs12Instance (['getPfxOfCurrentSigner ' , 'setCertificate ' , 'setPassword ' , 'readCertificate ' ]);
@@ -149,15 +148,13 @@ public function testValidateToSignWithCertificateData(
149148 $ this ->pkcs12Handler ->method ('readCertificate ' )->willReturn ($ certificateData );
150149
151150 $ this ->identifyService ->method ('getL10n ' )->willReturn ($ this ->l10n );
151+ $ this ->identifyService ->method ('getAppConfig ' )->willReturn ($ this ->appConfig );
152152
153153 $ password = $ this ->getClass ();
154154 $ password ->setCodeSentByUser ('senha ' );
155155
156156 if ($ shouldThrow ) {
157157 $ this ->expectException (LibresignException::class);
158- if ($ expectedMessage ) {
159- $ this ->expectExceptionMessage ($ expectedMessage );
160- }
161158 if ($ expectedCode !== null ) {
162159 $ this ->expectExceptionCode ($ expectedCode );
163160 }
@@ -190,59 +187,51 @@ public static function providerValidateToSignWithCertificateData(): array {
190187 'validTo_time_t ' => $ pastTimestamp ,
191188 ],
192189 'shouldThrow ' => true ,
193- 'expectedMessage ' => 'Certificate has expired ' ,
194190 'expectedCode ' => 422 ,
195191 ],
196192 'invalid certificate - validTo_time_t is string ' => [
197193 'certificateData ' => [
198194 'validTo_time_t ' => '1234567890 ' ,
199195 ],
200196 'shouldThrow ' => true ,
201- 'expectedMessage ' => 'Invalid certificate ' ,
202197 'expectedCode ' => 422 ,
203198 ],
204199 'invalid certificate - validTo_time_t is null ' => [
205200 'certificateData ' => [
206201 'validTo_time_t ' => null ,
207202 ],
208203 'shouldThrow ' => true ,
209- 'expectedMessage ' => 'Invalid certificate ' ,
210204 ],
211205 'invalid certificate - validTo_time_t is float ' => [
212206 'certificateData ' => [
213207 'validTo_time_t ' => 1234567890.5 ,
214208 ],
215209 'shouldThrow ' => true ,
216- 'expectedMessage ' => 'Invalid certificate ' ,
217210 ],
218211 'invalid certificate - validTo_time_t is boolean true ' => [
219212 'certificateData ' => [
220213 'validTo_time_t ' => true ,
221214 ],
222215 'shouldThrow ' => true ,
223- 'expectedMessage ' => 'Invalid certificate ' ,
224216 ],
225217 'invalid certificate - validTo_time_t is boolean false ' => [
226218 'certificateData ' => [
227219 'validTo_time_t ' => false ,
228220 ],
229221 'shouldThrow ' => true ,
230- 'expectedMessage ' => 'Invalid certificate ' ,
231222 ],
232223 'invalid certificate - validTo_time_t is array ' => [
233224 'certificateData ' => [
234225 'validTo_time_t ' => ['timestamp ' => 1234567890 ],
235226 ],
236227 'shouldThrow ' => true ,
237- 'expectedMessage ' => 'Invalid certificate ' ,
238228 ],
239229 'revoked certificate ' => [
240230 'certificateData ' => [
241231 'validTo_time_t ' => $ futureTimestamp ,
242232 'crl_validation ' => CrlValidationStatus::REVOKED ,
243233 ],
244234 'shouldThrow ' => true ,
245- 'expectedMessage ' => 'Certificate has been revoked ' ,
246235 'expectedCode ' => 422 ,
247236 ],
248237 'valid certificate with crl validation ' => [
@@ -265,7 +254,6 @@ public static function providerValidateToSignWithCertificateData(): array {
265254 'crl_validation ' => 'failed ' ,
266255 ],
267256 'shouldThrow ' => true ,
268- 'expectedMessage ' => 'Certificate revocation status could not be verified ' ,
269257 'expectedCode ' => 422 ,
270258 ],
271259 'invalid certificate - crl validation empty string ' => [
@@ -274,55 +262,95 @@ public static function providerValidateToSignWithCertificateData(): array {
274262 'crl_validation ' => '' ,
275263 ],
276264 'shouldThrow ' => true ,
277- 'expectedMessage ' => 'Certificate revocation status could not be verified ' ,
278265 ],
279266 'invalid certificate - crl validation null ' => [
280267 'certificateData ' => [
281268 'validTo_time_t ' => $ futureTimestamp ,
282269 'crl_validation ' => null ,
283270 ],
284271 'shouldThrow ' => true ,
285- 'expectedMessage ' => 'Certificate revocation status could not be verified ' ,
286272 ],
287273 'invalid certificate - crl urls_inaccessible ' => [
288274 'certificateData ' => [
289275 'validTo_time_t ' => $ futureTimestamp ,
290276 'crl_validation ' => CrlValidationStatus::URLS_INACCESSIBLE ,
291277 ],
292278 'shouldThrow ' => true ,
293- 'expectedMessage ' => 'Certificate revocation status could not be verified ' ,
294279 ],
295280 'invalid certificate - crl validation_failed ' => [
296281 'certificateData ' => [
297282 'validTo_time_t ' => $ futureTimestamp ,
298283 'crl_validation ' => CrlValidationStatus::VALIDATION_FAILED ,
299284 ],
300285 'shouldThrow ' => true ,
301- 'expectedMessage ' => 'Certificate revocation status could not be verified ' ,
302286 ],
303287 'invalid certificate - crl validation_error ' => [
304288 'certificateData ' => [
305289 'validTo_time_t ' => $ futureTimestamp ,
306290 'crl_validation ' => CrlValidationStatus::VALIDATION_ERROR ,
307291 ],
308292 'shouldThrow ' => true ,
309- 'expectedMessage ' => 'Certificate revocation status could not be verified ' ,
293+ ],
294+ 'invalid certificate - crl no_urls ' => [
295+ 'certificateData ' => [
296+ 'validTo_time_t ' => $ futureTimestamp ,
297+ 'crl_validation ' => CrlValidationStatus::NO_URLS ,
298+ ],
299+ 'shouldThrow ' => true ,
300+ ],
301+ 'invalid certificate - crl missing ' => [
302+ 'certificateData ' => [
303+ 'validTo_time_t ' => $ futureTimestamp ,
304+ 'crl_validation ' => CrlValidationStatus::MISSING ,
305+ ],
306+ 'shouldThrow ' => true ,
310307 ],
311308 'revoked and expired certificate ' => [
312309 'certificateData ' => [
313310 'validTo_time_t ' => $ pastTimestamp ,
314311 'crl_validation ' => CrlValidationStatus::REVOKED ,
315312 ],
316313 'shouldThrow ' => true ,
317- 'expectedMessage ' => 'Certificate has been revoked ' , // revocation is checked first
314+ ],
315+ 'crl missing - but validation enabled (default) still blocks ' => [
316+ 'certificateData ' => [
317+ 'validTo_time_t ' => $ futureTimestamp ,
318+ 'crl_validation ' => CrlValidationStatus::MISSING ,
319+ ],
320+ 'shouldThrow ' => true ,
321+ 'expectedCode ' => 422 ,
318322 ],
319323 'valid certificate - old date but valid (1970s timestamp) ' => [
320324 'certificateData ' => [
321325 'validTo_time_t ' => 31536000 , // 1971-01-01
322326 ],
323327 'shouldThrow ' => true ,
324- 'expectedMessage ' => 'Certificate has expired ' ,
325328 ],
326329 ];
327330 }
331+
332+ public function testValidateToSignWithMissingCrlWhenExternalValidationDisabled (): void {
333+ $ appConfig = $ this ->createMock (\OCP \IAppConfig::class);
334+ $ appConfig ->method ('getValueBool ' )
335+ ->with (Application::APP_ID , 'crl_external_validation_enabled ' , true )
336+ ->willReturn (false );
337+
338+ $ this ->pkcs12Handler = $ this ->getPkcs12Instance (['getPfxOfCurrentSigner ' , 'setCertificate ' , 'setPassword ' , 'readCertificate ' ]);
339+ $ this ->pkcs12Handler ->method ('getPfxOfCurrentSigner ' )->willReturn ('mock-pfx ' );
340+ $ this ->pkcs12Handler ->method ('setCertificate ' )->willReturnSelf ();
341+ $ this ->pkcs12Handler ->method ('setPassword ' )->willReturnSelf ();
342+ $ this ->pkcs12Handler ->method ('readCertificate ' )->willReturn ([
343+ 'validTo_time_t ' => (new \DateTime ('+50 years ' ))->getTimestamp (),
344+ 'crl_validation ' => CrlValidationStatus::MISSING ,
345+ ]);
346+ $ this ->identifyService ->method ('getL10n ' )->willReturn ($ this ->l10n );
347+ $ this ->identifyService ->method ('getAppConfig ' )->willReturn ($ appConfig );
348+
349+ $ password = $ this ->getClass ();
350+ $ password ->setCodeSentByUser ('senha ' );
351+ $ password ->validateToSign ();
352+
353+ // If we reach here, signing was allowed (no exception thrown).
354+ $ this ->expectNotToPerformAssertions ();
355+ }
328356}
0 commit comments