Skip to content

Commit 8e45594

Browse files
committed
AUT-2677 Fix exception handling in OcspCertificateRevocationChecker and related tests
1 parent f528135 commit 8e45594

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/main/java/eu/webeid/ocsp/OcspCertificateRevocationChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
package eu.webeid.ocsp;
2424

25-
import eu.webeid.ocsp.client.OcspClient;
25+
import eu.webeid.ocsp.client.OcspClient;import eu.webeid.ocsp.exceptions.OCSPClientException;
2626
import eu.webeid.ocsp.protocol.DigestCalculatorImpl;
2727
import eu.webeid.ocsp.protocol.OcspRequestBuilder;
2828
import eu.webeid.ocsp.protocol.OcspResponseValidator;
@@ -139,7 +139,7 @@ public List<RevocationInfo> validateCertificateNotRevoked(X509Certificate subjec
139139

140140
return List.of(new RevocationInfo(ocspResponderUri, Map.of(RevocationInfo.KEY_OCSP_RESPONSE, response)));
141141

142-
} catch (OCSPException | CertificateException | OperatorCreationException | IOException e) {
142+
} catch (OCSPException | CertificateException | OperatorCreationException | IOException | OCSPClientException e) {
143143
throw new UserCertificateOCSPCheckFailedException(e, ocspResponderUri);
144144
}
145145
}

src/test/java/eu/webeid/ocsp/OcspCertificateRevocationCheckerTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import static org.assertj.core.api.Assertions.assertThatCode;
6666
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
6767
import static org.assertj.core.api.Assertions.assertThatThrownBy;
68+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
6869
import static org.junit.jupiter.api.Assertions.assertThrows;
6970
import static org.mockito.Mockito.mock;
7071
import static org.mockito.Mockito.mockStatic;
@@ -123,6 +124,8 @@ void whenOcspUrlIsInvalid_thenThrows() throws Exception {
123124
final OcspCertificateRevocationChecker validator = getOcspCertificateRevocationChecker(ocspServiceProvider);
124125
assertThatCode(() ->
125126
validator.validateCertificateNotRevoked(estEid2018Cert, testEsteid2018CA))
127+
.isInstanceOf(UserCertificateOCSPCheckFailedException.class)
128+
.cause()
126129
.isInstanceOf(OCSPClientException.class)
127130
.cause()
128131
.isInstanceOf(ConnectException.class);
@@ -132,10 +135,11 @@ void whenOcspUrlIsInvalid_thenThrows() throws Exception {
132135
void whenOcspRequestFails_thenThrows() throws Exception {
133136
final OcspServiceProvider ocspServiceProvider = getDesignatedOcspServiceProvider("http://demo.sk.ee/ocsps");
134137
final OcspCertificateRevocationChecker validator = getOcspCertificateRevocationChecker(ocspServiceProvider);
135-
OCSPClientException ex = assertThrows(OCSPClientException.class, () ->
138+
UserCertificateOCSPCheckFailedException ex = assertThrows(UserCertificateOCSPCheckFailedException.class, () ->
136139
validator.validateCertificateNotRevoked(estEid2018Cert, testEsteid2018CA));
137-
assertThat(ex).hasMessageStartingWith("OCSP request was not successful");
138-
assertThat(ex.getStatusCode()).isEqualTo(404);
140+
OCSPClientException ocspClientException = assertInstanceOf(OCSPClientException.class, ex.getCause());
141+
assertThat(ocspClientException).hasMessageStartingWith("OCSP request was not successful");
142+
assertThat(ocspClientException.getStatusCode()).isEqualTo(404);
139143
}
140144

141145
@Test
@@ -145,6 +149,8 @@ void whenOcspRequestHasInvalidBody_thenThrows() throws Exception {
145149
);
146150
assertThatCode(() ->
147151
validator.validateCertificateNotRevoked(estEid2018Cert, testEsteid2018CA))
152+
.isInstanceOf(UserCertificateOCSPCheckFailedException.class)
153+
.cause()
148154
.isInstanceOf(OCSPClientException.class)
149155
.cause()
150156
.isInstanceOf(IOException.class)

src/test/java/eu/webeid/ocsp/client/OcspClientOverrideTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class OcspClientOverrideTest extends AbstractTestWithValidator {
4848
void whenOcspClientIsOverridden_thenItIsUsed() throws JceException, CertificateException, IOException {
4949
final AuthTokenValidator validator = getAuthTokenValidatorWithOverriddenOcspClient(new OcpClientThatThrows());
5050
assertThatThrownBy(() -> validator.validate(validAuthToken, VALID_CHALLENGE_NONCE))
51+
.cause()
5152
.isInstanceOf(OcpClientThatThrowsException.class);
5253
}
5354

0 commit comments

Comments
 (0)