I have the following code to check if my response body contains a specific value. I use Gatling with Java. I have modified the returns in ocspStatusCheck so it returns with a failure in each case, to check if it is properly shown in the logs and in the report, but the requests are still marked as OK.
private ChainBuilder ocsp() {
...
.doIf(session -> !session.getBoolean("usePost"))
.then(
exec(
http("OCSP GET request")
.get("#{ocspUrlGet}")
.header("Accept", "application/ocsp-response")
.check(ocspStatusCheck)
.check(status().is(200))
)
);
}
CheckBuilder ocspStatusCheck = bodyBytes().transform((byte[] rawBytes) -> {
try {
OCSPResp ocspResp = new OCSPResp(rawBytes);
BasicOCSPResp basic = (BasicOCSPResp) ocspResp.getResponseObject();
for (SingleResp srsp : basic.getResponses()) {
BigInteger certid = srsp.getCertID().getSerialNumber();
if (new BigInteger(ocspRequest.getSerial(), 16).equals(certid)) {
CertificateStatus stat = srsp.getCertStatus();
if (stat == CertificateStatus.GOOD) {
// return Validation.TrueSuccess();
return new Failure("OCSP processing error: ");
}
}
}
return new Failure("Certificate serial number " + ocspRequest.getSerial() + " not found in OCSP response or its status was not GOOD.");
} catch (Exception e) {
// Catch any parsing or processing errors and return a Failure
return new Failure("OCSP processing error: " + e.getMessage());
}
});
I have not found any other way to implement a custom check with Gatling. Can anyone help me solve this issue?
You should use the `validate` step instead, see https://docs.gatling.io/concepts/checks/#validate