2222
2323package eu .webeid .ocsp ;
2424
25+ import eu .webeid .ocsp .exceptions .OCSPClientException ;
2526import eu .webeid .security .exceptions .CertificateExpiredException ;
2627import eu .webeid .security .exceptions .CertificateNotTrustedException ;
2728import eu .webeid .security .exceptions .JceException ;
6061import static eu .webeid .security .testutil .DateMocker .mockDate ;
6162import static eu .webeid .ocsp .service .OcspServiceMaker .getAiaOcspServiceProvider ;
6263import static eu .webeid .ocsp .service .OcspServiceMaker .getDesignatedOcspServiceProvider ;
64+ import static org .assertj .core .api .Assertions .assertThat ;
6365import static org .assertj .core .api .Assertions .assertThatCode ;
6466import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
6567import static org .assertj .core .api .Assertions .assertThatThrownBy ;
68+ import static org .junit .jupiter .api .Assertions .assertThrows ;
6669import static org .mockito .Mockito .mock ;
6770import static org .mockito .Mockito .mockStatic ;
6871import static org .mockito .Mockito .when ;
6972
70- // TODO Fix failing tests
71- @ Disabled
7273public class OcspCertificateRevocationCheckerTest extends AbstractTestWithValidator {
7374
7475 private final OcspClient ocspClient = OcspClientImpl .build (Duration .ofSeconds (5 ));
@@ -122,7 +123,7 @@ void whenOcspUrlIsInvalid_thenThrows() throws Exception {
122123 final OcspCertificateRevocationChecker validator = getOcspCertificateRevocationChecker (ocspServiceProvider );
123124 assertThatCode (() ->
124125 validator .validateCertificateNotRevoked (estEid2018Cert , testEsteid2018CA ))
125- .isInstanceOf (UserCertificateOCSPCheckFailedException .class )
126+ .isInstanceOf (OCSPClientException .class )
126127 .cause ()
127128 .isInstanceOf (ConnectException .class );
128129 }
@@ -131,12 +132,10 @@ void whenOcspUrlIsInvalid_thenThrows() throws Exception {
131132 void whenOcspRequestFails_thenThrows () throws Exception {
132133 final OcspServiceProvider ocspServiceProvider = getDesignatedOcspServiceProvider ("http://demo.sk.ee/ocsps" );
133134 final OcspCertificateRevocationChecker validator = getOcspCertificateRevocationChecker (ocspServiceProvider );
134- assertThatCode (() ->
135- validator .validateCertificateNotRevoked (estEid2018Cert , testEsteid2018CA ))
136- .isInstanceOf (UserCertificateOCSPCheckFailedException .class )
137- .cause ()
138- .isInstanceOf (IOException .class )
139- .hasMessageStartingWith ("OCSP request was not successful, response: (POST http://demo.sk.ee/ocsps) 404" );
135+ OCSPClientException ex = assertThrows (OCSPClientException .class , () ->
136+ validator .validateCertificateNotRevoked (estEid2018Cert , testEsteid2018CA ));
137+ assertThat (ex ).hasMessageStartingWith ("OCSP request was not successful" );
138+ assertThat (ex .getStatusCode ()).isEqualTo (404 );
140139 }
141140
142141 @ Test
@@ -146,7 +145,7 @@ void whenOcspRequestHasInvalidBody_thenThrows() throws Exception {
146145 );
147146 assertThatCode (() ->
148147 validator .validateCertificateNotRevoked (estEid2018Cert , testEsteid2018CA ))
149- .isInstanceOf (UserCertificateOCSPCheckFailedException .class )
148+ .isInstanceOf (OCSPClientException .class )
150149 .cause ()
151150 .isInstanceOf (IOException .class )
152151 .hasMessage ("DEF length 110 object truncated by 105" );
@@ -410,7 +409,7 @@ private OcspClient getMockClient(HttpResponse<byte[]> response) {
410409 try {
411410 return new OCSPResp (Objects .requireNonNull (response .body ()));
412411 } catch (IOException e ) {
413- throw new RuntimeException (e );
412+ throw new OCSPClientException (e );
414413 }
415414 };
416415 }
0 commit comments