WebTestClientHtmlUnitDriverBuilder uses WebTestClient for localhost

Fixes gh-4815
This commit is contained in:
Rob Winch 2017-11-08 13:46:08 -06:00
parent 426c034c01
commit 3c7fb977fe
1 changed files with 6 additions and 1 deletions

View File

@ -17,8 +17,12 @@
package org.springframework.security.htmlunit.server;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebConnection;
import org.openqa.selenium.WebDriver;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection;
import org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection;
import org.springframework.test.web.servlet.htmlunit.HostRequestMatcher;
import org.springframework.test.web.servlet.htmlunit.webdriver.WebConnectionHtmlUnitDriver;
/**
@ -35,7 +39,8 @@ public class WebTestClientHtmlUnitDriverBuilder {
public WebDriver build() {
WebConnectionHtmlUnitDriver driver = new WebConnectionHtmlUnitDriver();
WebClient webClient = driver.getWebClient();
WebTestClientWebConnection connection = new WebTestClientWebConnection(this.webTestClient, webClient);
WebTestClientWebConnection webClientConnection = new WebTestClientWebConnection(this.webTestClient, webClient);
WebConnection connection = new DelegatingWebConnection(driver.getWebConnection(), new DelegateWebConnection(new HostRequestMatcher("localhost"), webClientConnection));
driver.setWebConnection(connection);
return driver;
}