From f27ac24b73adaf24a216e256303a2b2b62f306f0 Mon Sep 17 00:00:00 2001 From: Marcus Da Coregio Date: Thu, 27 Apr 2023 10:50:45 -0300 Subject: [PATCH] Change tests to use Internet Explore 11 --- .../example/Saml2LoginApplicationITests.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/servlet/spring-boot/java/saml2/login/src/integTest/java/example/Saml2LoginApplicationITests.java b/servlet/spring-boot/java/saml2/login/src/integTest/java/example/Saml2LoginApplicationITests.java index 7356c5234..7f99c5d66 100644 --- a/servlet/spring-boot/java/saml2/login/src/integTest/java/example/Saml2LoginApplicationITests.java +++ b/servlet/spring-boot/java/saml2/login/src/integTest/java/example/Saml2LoginApplicationITests.java @@ -16,10 +16,14 @@ package example; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.ElementNotFoundException; +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; @@ -33,7 +37,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.web.htmlunit.LocalHostWebClient; +import org.springframework.context.annotation.Bean; +import org.springframework.core.env.Environment; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder; +import org.springframework.util.Assert; import static org.assertj.core.api.Assertions.assertThat; @@ -108,4 +118,34 @@ private HtmlForm findForm(HtmlPage login) { throw new IllegalStateException("Could not resolve login form"); } + @TestConfiguration + static class WebClientConfiguration { + + @Bean + public MockMvcWebClientBuilder mockMvcWebClientBuilder(MockMvc mockMvc, Environment environment) { + return MockMvcWebClientBuilder.mockMvcSetup(mockMvc).withDelegate(new InternetExplorerLocalHostWebClient(environment)); + } + + } + + static class InternetExplorerLocalHostWebClient extends WebClient { + + private final Environment environment; + + public InternetExplorerLocalHostWebClient(Environment environment) { + super(BrowserVersion.INTERNET_EXPLORER); + Assert.notNull(environment, "Environment must not be null"); + this.environment = environment; + } + + @Override + public

P getPage(String url) throws IOException, FailingHttpStatusCodeException { + if (url.startsWith("/")) { + String port = this.environment.getProperty("local.server.port", "8080"); + url = "http://localhost:" + port + url; + } + return super.getPage(url); + } + } + }