diff --git a/config/src/test/java/org/springframework/security/htmlunit/server/WebTestClientHtmlUnitDriverBuilder.java b/config/src/test/java/org/springframework/security/htmlunit/server/WebTestClientHtmlUnitDriverBuilder.java index c737902e9f..d4babc2bd6 100644 --- a/config/src/test/java/org/springframework/security/htmlunit/server/WebTestClientHtmlUnitDriverBuilder.java +++ b/config/src/test/java/org/springframework/security/htmlunit/server/WebTestClientHtmlUnitDriverBuilder.java @@ -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; }