Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

java - Does MockRestServiceServer support mutual TLS and if so, how to configure it?

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...