RestAssured API call failed due to SSL handshake issue

47 Views Asked by At

I need to run my rest-assured automated tests on an environment that don't have SSL certificate, the test failed at the first call with the following exception

javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:371)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:314)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:309)

I updated the code to use the following specifications: first I tried

    public static void addHeadersToRequestsSpecifications(Map<String, String> authHeaders, String cookieValue) {
    API.addRequestSpec(new RequestSpecBuilder()
            .setConfig(RestAssuredConfig.newConfig().sslConfig(new SSLConfig().relaxedHTTPSValidation()))
            .addHeader("cookie", cookieValue)
            .addHeader("Accept", "application/json, text/plain, */*")
            .addHeader(TOKEN, authHeaders.get(this.token))
            .addFilter(new AllureRestAssured())
            .build());
}

and then I tried:

 public static void addHeadersToRequestsSpecifications(Map<String, String> authHeaders, String cookieValue) {
    API.addRequestSpec(new RequestSpecBuilder()
            .setConfig(RestAssured.config().sslConfig(new SSLConfig().allowAllHostnames()))
            .addHeader("cookie", cookieValue)
            .addHeader("Accept", "application/json, text/plain, */*")
            .addHeader(TOKEN, authHeaders.get(this.token))
            .addFilter(new AllureRestAssured())
            .build());
}

in both cases the same error still reproduces, how can I disable SSL verification?

Im using Java version: 17.0.4

rest-assured version: 5.1.1

1

There are 1 best solutions below

0
Hakan54 On

You can use the relaxedHTTPSValidation() option which just disables the ssl verification. Example code would be:

given().relaxedHTTPSValidation().when().post("https://my_server.com")

See also this answer posted on for a similar question: How to make HTTPS GET call with certificate in Rest-Assured java