We use org.springframework.test.web.client.MockRestServiceServer
in our IT tests to verify our RestTemplate
handling. Now, I need to include also some tests for mutual authentication and I'm not sure if this is possible and how to achieve that. Does MockRestServiceServer
support that or do I need to go for something else?
As I haven't found a way, I went for com.github.tomakehurst.wiremock.WireMockServer which works pretty good. Here is how I set it up, please note that I needed to add keyManagerPassword as well (I'm not sure why, but it's simply the one of the keystore)
public WireMockServer mutualTlsMock;
@BeforeEach
void setUp() {
mutualTlsMock = new WireMockServer(options()
.httpsPort(8443)
.needClientAuth(true)
.keystorePath("path/to/my/keystore.jks")
.keystorePassword("keystorePassword")
.keyManagerPassword("keystorePassword")
.trustStorePath("path/to/my/keystore.jks")
.trustStorePassword("keystorePassword"));
mutualTlsMock.start();
}
@AfterEach
void shutdown() {
mutualTlsMock.shutdown();
}