2017-10-19 102 views
1

我在集成測試中使用Spring WebFlux WebTestClient。我使用WebTestClient.bindToServer()創建客戶端。經測試的服務器通過HTTPS提供資源。我有下面的代碼:禁用WebTestClient的TLS證書檢查

WebTestClient webTestClient = WebTestClient.bindToServer() 
    .baseUrl("https://secured.example.com") 
    .build(); 
webTestClient.get().uri("/index.html") 
    .exchange() 
    .expectStatus().isOk(); 

沒有必要在測試中使用有效證書。我如何配置WebTestClient來信任所有證書?

P.S.我可以配置WebClient來信任每個人。但WebTestClient更適合編寫測試。

+0

你能告訴我們你的配置,這可能有助於回答這個問題嗎?始終包含您擁有的代碼和任何試圖解決問題的嘗試,以便爲我們提供更多背景。關於如何提出好問題的有用資源(以及更快得到解答)https://stackoverflow.com/help/how-to-ask – Moseleyi

+0

其實,我有點困惑。我來自https://spring.io/questions,但似乎這樣的問題並不意味着快速的答案。 –

回答

0

您可以使用您可以提供給WebTestClient的自定義ClientHttpConnector進行配置。

// create a custom connector and customize TLS configuration there. 
ReactorClientHttpConnector connector = new ReactorClientHttpConnector(options -> options...); 
WebTestClient client = WebTestClient.bindToServer(connector); 

這已經在最近SPR-16168固定。

+0

Brian,我是創建[SPR-16168](https://jira.spring.io/browse/SPR-16168)的人。值得補充的是,這些更改將在幾天內發佈的版本5.0.2中提供。 –