0

I have a service that exposes an API which I'd like to test. I'm running the service on localhost and it has a self-signed certificate.

I added the .p12 file to test/resources and on @BeforeAll:

    RestAssured
            .config()
            .sslConfig(
                    new SSLConfig().with().trustStoreType("PKCS12").and().relaxedHTTPSValidation().and()
                            .trustStore(ResourceUtils.getFile("classpath:cert.p12"), "mypassword"));

Also added this:

RestAssured.config().sslConfig(SSLConfig.sslConfig().allowAllHostnames());

Although, I'm getting the following error:

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

Why?

UPDATE:
On runtime I can see that RestAssured.config().getSSLConfig().getTrustStore() is null but how?

UPDATE 2: I don't mind that REST assured will trust all certificates (security isn't an issue)

IsaacLevon
  • 2,260
  • 4
  • 41
  • 83
  • perhaps if's failing to fetch your `cert.12` resource file. – TheoNeUpKID Sep 13 '20 at 15:03
  • @TheoNeUpKID, I double checked the file and its password (the file exists and the password is correct) – IsaacLevon Sep 13 '20 at 15:12
  • it could be an issue with the cert, the fact that your running an SSL locally, etc. checkout https://stackoverflow.com/questions/9578129/exception-javax-net-ssl-sslpeerunverifiedexception-peer-not-authenticated – TheoNeUpKID Sep 13 '20 at 15:21
  • @TheoNeUpKID, I edited my question (btw, the certificate isn't expired) – IsaacLevon Sep 13 '20 at 15:24

1 Answers1

1

Solved it (sort of) by adding relaxedHTTPSValidation() like so:

RestAssured.given().relaxedHTTPSValidation()

drawback: you have to do that for every HTTP call.

IsaacLevon
  • 2,260
  • 4
  • 41
  • 83