My Spring Boot application is connecting to third parties servers using a third librabry/framework.
One of these remote servers (not yet available) will require mutual TLS (HTTPS) connection. My code will provide the P12 and password to the framework in order to connect to this remote server. I need to test this part with JUnit integration test.
MockServer is already used for our JUnit IT but not yet for mutual TLS authentication and, as a newby, I'm quite confused on how to implement this.
Form the doc I added in my JUnit test the following configuration:
@BeforeAll
public static void initServer(){
// ensure https will use SSL context defined by MockServer to allow
// dynamically generated certificates to be accepted
HttpsURLConnection.setDefaultSSLSocketFactory(new KeyStoreFactory(new
MockServerLogger()).sslContext().getSocketFactory());
File certif = ResourceUtils.getFile("classpath:mtls/test-cert.crt");
ConfigurationProperties.tlsMutualAuthenticationCertificateChain(certif.getPath());
ConfigurationProperties.tlsMutualAuthenticationRequired(true);
mockServer = ClientAndServer.startClientAndServer(80,443);
etc…
}
But nothing works, I'm missing some code in my test?
In log I can see for i.e:
MockServerEventLog - no tls for connection
I cannot find any clear and simple tutorial for this use case. Any help would be greatfull.
So how to implement a full JUnit integration test using a MockServer with mutual TLS authentication?