|
|
|
|
@@ -16,13 +16,9 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.test.web.servlet.htmlunit;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
@@ -32,19 +28,14 @@ import com.gargoylesoftware.htmlunit.FormEncodingType;
|
|
|
|
|
import com.gargoylesoftware.htmlunit.HttpMethod;
|
|
|
|
|
import com.gargoylesoftware.htmlunit.WebClient;
|
|
|
|
|
import com.gargoylesoftware.htmlunit.WebRequest;
|
|
|
|
|
import com.gargoylesoftware.htmlunit.util.KeyDataPair;
|
|
|
|
|
import com.gargoylesoftware.htmlunit.util.MimeType;
|
|
|
|
|
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
|
|
|
|
import jakarta.servlet.ServletContext;
|
|
|
|
|
import jakarta.servlet.http.Cookie;
|
|
|
|
|
import jakarta.servlet.http.HttpSession;
|
|
|
|
|
import jakarta.servlet.http.Part;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
|
|
|
import org.springframework.mock.web.MockHttpSession;
|
|
|
|
|
import org.springframework.mock.web.MockServletContext;
|
|
|
|
|
@@ -54,7 +45,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
|
|
|
import static org.assertj.core.api.SoftAssertions.assertSoftly;
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -78,7 +68,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
|
public void setup() throws Exception {
|
|
|
|
|
void setup() throws Exception {
|
|
|
|
|
webRequest = new WebRequest(new URL("https://example.com/test/this/here"));
|
|
|
|
|
webRequest.setHttpMethod(HttpMethod.GET);
|
|
|
|
|
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
|
|
|
|
|
@@ -88,19 +78,19 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
// --- constructor
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void constructorNullSessions() {
|
|
|
|
|
void constructorNullSessions() {
|
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
|
|
|
|
new HtmlUnitRequestBuilder(null, webClient, webRequest));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void constructorNullWebClient() {
|
|
|
|
|
void constructorNullWebClient() {
|
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
|
|
|
|
new HtmlUnitRequestBuilder(sessions, null, webRequest));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void constructorNullWebRequest() {
|
|
|
|
|
void constructorNullWebRequest() {
|
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
|
|
|
|
new HtmlUnitRequestBuilder(sessions, webClient, null));
|
|
|
|
|
}
|
|
|
|
|
@@ -110,7 +100,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
public void buildRequestBasicAuth() {
|
|
|
|
|
void buildRequestBasicAuth() {
|
|
|
|
|
String base64Credentials = "dXNlcm5hbWU6cGFzc3dvcmQ=";
|
|
|
|
|
String authzHeaderValue = "Basic: " + base64Credentials;
|
|
|
|
|
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(base64Credentials);
|
|
|
|
|
@@ -124,7 +114,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestCharacterEncoding() {
|
|
|
|
|
void buildRequestCharacterEncoding() {
|
|
|
|
|
webRequest.setCharset(StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -133,14 +123,14 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestDefaultCharacterEncoding() {
|
|
|
|
|
void buildRequestDefaultCharacterEncoding() {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getCharacterEncoding()).isEqualTo("ISO-8859-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestContentLength() {
|
|
|
|
|
void buildRequestContentLength() {
|
|
|
|
|
String content = "some content that has length";
|
|
|
|
|
webRequest.setHttpMethod(HttpMethod.POST);
|
|
|
|
|
webRequest.setRequestBody(content);
|
|
|
|
|
@@ -151,7 +141,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestContentType() {
|
|
|
|
|
void buildRequestContentType() {
|
|
|
|
|
String contentType = "text/html;charset=UTF-8";
|
|
|
|
|
webRequest.setAdditionalHeader("Content-Type", contentType);
|
|
|
|
|
|
|
|
|
|
@@ -162,7 +152,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // SPR-14916
|
|
|
|
|
public void buildRequestContentTypeWithFormSubmission() {
|
|
|
|
|
void buildRequestContentTypeWithFormSubmission() {
|
|
|
|
|
webRequest.setEncodingType(FormEncodingType.URL_ENCODED);
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -174,14 +164,14 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestContextPathUsesFirstSegmentByDefault() {
|
|
|
|
|
void buildRequestContextPathUsesFirstSegmentByDefault() {
|
|
|
|
|
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
|
|
|
|
|
|
|
|
|
assertThat(contextPath).isEqualTo("/test");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestContextPathUsesNoFirstSegmentWithDefault() throws MalformedURLException {
|
|
|
|
|
void buildRequestContextPathUsesNoFirstSegmentWithDefault() throws MalformedURLException {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/"));
|
|
|
|
|
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
|
|
|
|
|
|
|
|
|
@@ -189,7 +179,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestContextPathInvalid() {
|
|
|
|
|
void buildRequestContextPathInvalid() {
|
|
|
|
|
requestBuilder.setContextPath("/invalid");
|
|
|
|
|
|
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
|
|
|
|
@@ -197,7 +187,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestContextPathEmpty() {
|
|
|
|
|
void buildRequestContextPathEmpty() {
|
|
|
|
|
String expected = "";
|
|
|
|
|
requestBuilder.setContextPath(expected);
|
|
|
|
|
|
|
|
|
|
@@ -207,7 +197,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestContextPathExplicit() {
|
|
|
|
|
void buildRequestContextPathExplicit() {
|
|
|
|
|
String expected = "/test";
|
|
|
|
|
requestBuilder.setContextPath(expected);
|
|
|
|
|
|
|
|
|
|
@@ -217,7 +207,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestContextPathMulti() {
|
|
|
|
|
void buildRequestContextPathMulti() {
|
|
|
|
|
String expected = "/test/this";
|
|
|
|
|
requestBuilder.setContextPath(expected);
|
|
|
|
|
|
|
|
|
|
@@ -227,14 +217,14 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestCookiesNull() {
|
|
|
|
|
void buildRequestCookiesNull() {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getCookies()).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestCookiesSingle() {
|
|
|
|
|
void buildRequestCookiesSingle() {
|
|
|
|
|
webRequest.setAdditionalHeader("Cookie", "name=value");
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -246,7 +236,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestCookiesMulti() {
|
|
|
|
|
void buildRequestCookiesMulti() {
|
|
|
|
|
webRequest.setAdditionalHeader("Cookie", "name=value; name2=value2");
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -263,7 +253,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
public void buildRequestInputStream() throws Exception {
|
|
|
|
|
void buildRequestInputStream() throws Exception {
|
|
|
|
|
String content = "some content that has length";
|
|
|
|
|
webRequest.setHttpMethod(HttpMethod.POST);
|
|
|
|
|
webRequest.setRequestBody(content);
|
|
|
|
|
@@ -274,21 +264,21 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocalAddr() {
|
|
|
|
|
void buildRequestLocalAddr() {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getLocalAddr()).isEqualTo("127.0.0.1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocaleDefault() {
|
|
|
|
|
void buildRequestLocaleDefault() {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getLocale()).isEqualTo(Locale.getDefault());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocaleDa() {
|
|
|
|
|
void buildRequestLocaleDa() {
|
|
|
|
|
webRequest.setAdditionalHeader("Accept-Language", "da");
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -297,7 +287,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocaleEnGbQ08() {
|
|
|
|
|
void buildRequestLocaleEnGbQ08() {
|
|
|
|
|
webRequest.setAdditionalHeader("Accept-Language", "en-gb;q=0.8");
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -306,7 +296,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocaleEnQ07() {
|
|
|
|
|
void buildRequestLocaleEnQ07() {
|
|
|
|
|
webRequest.setAdditionalHeader("Accept-Language", "en");
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -315,7 +305,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocaleEnUs() {
|
|
|
|
|
void buildRequestLocaleEnUs() {
|
|
|
|
|
webRequest.setAdditionalHeader("Accept-Language", "en-US");
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -324,7 +314,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocaleFr() {
|
|
|
|
|
void buildRequestLocaleFr() {
|
|
|
|
|
webRequest.setAdditionalHeader("Accept-Language", "fr");
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -333,7 +323,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocaleMulti() {
|
|
|
|
|
void buildRequestLocaleMulti() {
|
|
|
|
|
webRequest.setAdditionalHeader("Accept-Language", "en-gb;q=0.8, da, en;q=0.7");
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -343,14 +333,14 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocalName() {
|
|
|
|
|
void buildRequestLocalName() {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getLocalName()).isEqualTo("localhost");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocalPort() throws Exception {
|
|
|
|
|
void buildRequestLocalPort() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
@@ -358,7 +348,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestLocalMissing() throws Exception {
|
|
|
|
|
void buildRequestLocalMissing() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("http://localhost/test/this"));
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
@@ -366,7 +356,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestMethods() {
|
|
|
|
|
void buildRequestMethods() {
|
|
|
|
|
for (HttpMethod expectedMethod : HttpMethod.values()) {
|
|
|
|
|
webRequest.setHttpMethod(expectedMethod);
|
|
|
|
|
String actualMethod = requestBuilder.buildRequest(servletContext).getMethod();
|
|
|
|
|
@@ -374,159 +364,41 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParam() {
|
|
|
|
|
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name", "value")));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
|
|
|
|
assertThat(actualRequest.getParameter("name")).isEqualTo("value");
|
|
|
|
|
}
|
|
|
|
|
// --- buildRequest with parameters
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithNullValue() {
|
|
|
|
|
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name", null)));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
|
|
|
|
assertThat(actualRequest.getParameter("name")).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithEmptyValue() {
|
|
|
|
|
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name", "")));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
|
|
|
|
assertThat(actualRequest.getParameter("name")).isEqualTo("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithValueSetToSpace() {
|
|
|
|
|
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name", " ")));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
|
|
|
|
assertThat(actualRequest.getParameter("name")).isEqualTo(" ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithMultipleRequestParams() {
|
|
|
|
|
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name1", "value1"), new NameValuePair("name2", "value2")));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(2);
|
|
|
|
|
assertThat(actualRequest.getParameter("name1")).isEqualTo("value1");
|
|
|
|
|
assertThat(actualRequest.getParameter("name2")).isEqualTo("value2");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // gh-24926
|
|
|
|
|
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithFileToUploadAsParameter() throws Exception {
|
|
|
|
|
webRequest.setRequestParameters(Collections.singletonList(
|
|
|
|
|
new KeyDataPair("key",
|
|
|
|
|
new ClassPathResource("org/springframework/test/web/htmlunit/test.txt").getFile(),
|
|
|
|
|
"test.txt", MimeType.TEXT_PLAIN, StandardCharsets.UTF_8)));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParts()).hasSize(1);
|
|
|
|
|
Part part = actualRequest.getPart("key");
|
|
|
|
|
assertThat(part).isNotNull();
|
|
|
|
|
assertThat(part.getName()).isEqualTo("key");
|
|
|
|
|
assertThat(IOUtils.toString(part.getInputStream(), StandardCharsets.UTF_8)).isEqualTo("test file");
|
|
|
|
|
assertThat(part.getSubmittedFileName()).isEqualTo("test.txt");
|
|
|
|
|
assertThat(part.getContentType()).isEqualTo(MimeType.TEXT_PLAIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // gh-27199
|
|
|
|
|
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithFileDataAsParameter() throws Exception {
|
|
|
|
|
String data = "{}";
|
|
|
|
|
KeyDataPair keyDataPair = new KeyDataPair("key", new File("test.json"), null, MimeType.APPLICATION_JSON, StandardCharsets.UTF_8);
|
|
|
|
|
keyDataPair.setData(data.getBytes());
|
|
|
|
|
|
|
|
|
|
webRequest.setRequestParameters(Collections.singletonList(keyDataPair));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParts()).hasSize(1);
|
|
|
|
|
Part part = actualRequest.getPart("key");
|
|
|
|
|
|
|
|
|
|
assertSoftly(softly -> {
|
|
|
|
|
softly.assertThat(part).as("part").isNotNull();
|
|
|
|
|
softly.assertThat(part.getName()).as("name").isEqualTo("key");
|
|
|
|
|
softly.assertThat(part.getSubmittedFileName()).as("file name").isEqualTo("test.json");
|
|
|
|
|
softly.assertThat(part.getContentType()).as("content type").isEqualTo(MimeType.APPLICATION_JSON);
|
|
|
|
|
try {
|
|
|
|
|
softly.assertThat(IOUtils.toString(part.getInputStream(), StandardCharsets.UTF_8)).as("content").isEqualTo(data);
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
softly.fail("failed to get InputStream", ex);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // gh-26799
|
|
|
|
|
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithNullFileToUploadAsParameter() throws Exception {
|
|
|
|
|
webRequest.setRequestParameters(Collections.singletonList(new KeyDataPair("key", null, null, null, (Charset) null)));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParts()).hasSize(1);
|
|
|
|
|
Part part = actualRequest.getPart("key");
|
|
|
|
|
|
|
|
|
|
assertSoftly(softly -> {
|
|
|
|
|
softly.assertThat(part).as("part").isNotNull();
|
|
|
|
|
softly.assertThat(part.getName()).as("name").isEqualTo("key");
|
|
|
|
|
softly.assertThat(part.getSize()).as("size").isEqualTo(0);
|
|
|
|
|
try {
|
|
|
|
|
softly.assertThat(part.getInputStream()).as("input stream").isEmpty();
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
softly.fail("failed to get InputStream", ex);
|
|
|
|
|
}
|
|
|
|
|
softly.assertThat(part.getSubmittedFileName()).as("filename").isEqualTo("");
|
|
|
|
|
softly.assertThat(part.getContentType()).as("content-type").isEqualTo("application/octet-stream");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapFromSingleQueryParam() throws Exception {
|
|
|
|
|
void buildRequestParameterMapFromSingleQueryParam() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example/?name=value"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
|
|
|
|
assertThat(actualRequest.getParameterMap()).hasSize(1);
|
|
|
|
|
assertThat(actualRequest.getParameter("name")).isEqualTo("value");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SPR-14177
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapDecodesParameterName() throws Exception {
|
|
|
|
|
void buildRequestParameterMapDecodesParameterName() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example/?row%5B0%5D=value"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
|
|
|
|
assertThat(actualRequest.getParameterMap()).hasSize(1);
|
|
|
|
|
assertThat(actualRequest.getParameter("row[0]")).isEqualTo("value");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapDecodesParameterValue() throws Exception {
|
|
|
|
|
void buildRequestParameterMapDecodesParameterValue() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example/?name=row%5B0%5D"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
|
|
|
|
assertThat(actualRequest.getParameterMap()).hasSize(1);
|
|
|
|
|
assertThat(actualRequest.getParameter("name")).isEqualTo("row[0]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapFromSingleQueryParamWithoutValueAndWithoutEqualsSign() throws Exception {
|
|
|
|
|
void buildRequestParameterMapFromSingleQueryParamWithoutValueAndWithoutEqualsSign() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example/?name"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -536,7 +408,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapFromSingleQueryParamWithoutValueButWithEqualsSign() throws Exception {
|
|
|
|
|
void buildRequestParameterMapFromSingleQueryParamWithoutValueButWithEqualsSign() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example/?name="));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -546,7 +418,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapFromSingleQueryParamWithValueSetToEncodedSpace() throws Exception {
|
|
|
|
|
void buildRequestParameterMapFromSingleQueryParamWithValueSetToEncodedSpace() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example/?name=%20"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -556,25 +428,25 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestParameterMapFromMultipleQueryParams() throws Exception {
|
|
|
|
|
void buildRequestParameterMapFromMultipleQueryParams() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example/?name=value¶m2=value+2"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getParameterMap().size()).isEqualTo(2);
|
|
|
|
|
assertThat(actualRequest.getParameterMap()).hasSize(2);
|
|
|
|
|
assertThat(actualRequest.getParameter("name")).isEqualTo("value");
|
|
|
|
|
assertThat(actualRequest.getParameter("param2")).isEqualTo("value 2");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestPathInfo() throws Exception {
|
|
|
|
|
void buildRequestPathInfo() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getPathInfo()).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestPathInfoNull() throws Exception {
|
|
|
|
|
void buildRequestPathInfoNull() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -583,7 +455,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestAndAntPathRequestMatcher() throws Exception {
|
|
|
|
|
void buildRequestAndAntPathRequestMatcher() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/app/login/authenticate"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -594,14 +466,14 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestProtocol() throws Exception {
|
|
|
|
|
void buildRequestProtocol() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getProtocol()).isEqualTo("HTTP/1.1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestQueryWithSingleQueryParam() throws Exception {
|
|
|
|
|
void buildRequestQueryWithSingleQueryParam() throws Exception {
|
|
|
|
|
String expectedQuery = "param=value";
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
|
|
|
|
|
|
|
|
|
@@ -611,7 +483,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestQueryWithSingleQueryParamWithoutValueAndWithoutEqualsSign() throws Exception {
|
|
|
|
|
void buildRequestQueryWithSingleQueryParamWithoutValueAndWithoutEqualsSign() throws Exception {
|
|
|
|
|
String expectedQuery = "param";
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
|
|
|
|
|
|
|
|
|
@@ -621,7 +493,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestQueryWithSingleQueryParamWithoutValueButWithEqualsSign() throws Exception {
|
|
|
|
|
void buildRequestQueryWithSingleQueryParamWithoutValueButWithEqualsSign() throws Exception {
|
|
|
|
|
String expectedQuery = "param=";
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
|
|
|
|
|
|
|
|
|
@@ -631,7 +503,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestQueryWithSingleQueryParamWithValueSetToEncodedSpace() throws Exception {
|
|
|
|
|
void buildRequestQueryWithSingleQueryParamWithValueSetToEncodedSpace() throws Exception {
|
|
|
|
|
String expectedQuery = "param=%20";
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
|
|
|
|
|
|
|
|
|
@@ -641,7 +513,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestQueryWithMultipleQueryParams() throws Exception {
|
|
|
|
|
void buildRequestQueryWithMultipleQueryParams() throws Exception {
|
|
|
|
|
String expectedQuery = "param1=value1¶m2=value2";
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
|
|
|
|
|
|
|
|
|
|
@@ -651,7 +523,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestReader() throws Exception {
|
|
|
|
|
void buildRequestReader() throws Exception {
|
|
|
|
|
String expectedBody = "request body";
|
|
|
|
|
webRequest.setHttpMethod(HttpMethod.POST);
|
|
|
|
|
webRequest.setRequestBody(expectedBody);
|
|
|
|
|
@@ -662,21 +534,21 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestRemoteAddr() throws Exception {
|
|
|
|
|
void buildRequestRemoteAddr() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getRemoteAddr()).isEqualTo("127.0.0.1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestRemoteHost() throws Exception {
|
|
|
|
|
void buildRequestRemoteHost() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getRemoteAddr()).isEqualTo("127.0.0.1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestRemotePort() throws Exception {
|
|
|
|
|
void buildRequestRemotePort() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
@@ -684,7 +556,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestRemotePort8080() throws Exception {
|
|
|
|
|
void buildRequestRemotePort8080() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com:8080/"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -693,7 +565,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestRemotePort80WithDefault() throws Exception {
|
|
|
|
|
void buildRequestRemotePort80WithDefault() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("http://company.example/"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -702,7 +574,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestRequestedSessionId() throws Exception {
|
|
|
|
|
void buildRequestRequestedSessionId() throws Exception {
|
|
|
|
|
String sessionId = "session-id";
|
|
|
|
|
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -711,26 +583,26 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestRequestedSessionIdNull() throws Exception {
|
|
|
|
|
void buildRequestRequestedSessionIdNull() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getRequestedSessionId()).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestUri() {
|
|
|
|
|
void buildRequestUri() {
|
|
|
|
|
String uri = requestBuilder.buildRequest(servletContext).getRequestURI();
|
|
|
|
|
assertThat(uri).isEqualTo("/test/this/here");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestUrl() {
|
|
|
|
|
void buildRequestUrl() {
|
|
|
|
|
String uri = requestBuilder.buildRequest(servletContext).getRequestURL().toString();
|
|
|
|
|
assertThat(uri).isEqualTo("https://example.com/test/this/here");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSchemeHttp() throws Exception {
|
|
|
|
|
void buildRequestSchemeHttp() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
@@ -738,7 +610,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSchemeHttps() throws Exception {
|
|
|
|
|
void buildRequestSchemeHttps() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/"));
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
@@ -746,14 +618,14 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestServerName() throws Exception {
|
|
|
|
|
void buildRequestServerName() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getServerName()).isEqualTo("example.com");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestServerPort() throws Exception {
|
|
|
|
|
void buildRequestServerPort() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
@@ -761,7 +633,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestServerPortDefault() throws Exception {
|
|
|
|
|
void buildRequestServerPortDefault() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("https://example.com/"));
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
@@ -769,21 +641,21 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestServletContext() throws Exception {
|
|
|
|
|
void buildRequestServletContext() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getServletContext()).isEqualTo(servletContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestServletPath() throws Exception {
|
|
|
|
|
void buildRequestServletPath() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getServletPath()).isEqualTo("/this/here");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // gh-27837
|
|
|
|
|
public void buildRequestServletPathWithEncodedUrl() throws Exception {
|
|
|
|
|
void buildRequestServletPathWithEncodedUrl() throws Exception {
|
|
|
|
|
webRequest.setUrl(new URL("http://localhost/test/Fr%C3%BChling%20Sommer%20Herbst%20Winter"));
|
|
|
|
|
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -793,7 +665,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSession() throws Exception {
|
|
|
|
|
void buildRequestSession() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
HttpSession newSession = actualRequest.getSession();
|
|
|
|
|
@@ -810,7 +682,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSessionWithExistingSession() throws Exception {
|
|
|
|
|
void buildRequestSessionWithExistingSession() throws Exception {
|
|
|
|
|
String sessionId = "session-id";
|
|
|
|
|
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -831,7 +703,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSessionTrue() throws Exception {
|
|
|
|
|
void buildRequestSessionTrue() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
HttpSession session = actualRequest.getSession(true);
|
|
|
|
|
@@ -839,7 +711,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSessionFalseIsNull() throws Exception {
|
|
|
|
|
void buildRequestSessionFalseIsNull() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
HttpSession session = actualRequest.getSession(false);
|
|
|
|
|
@@ -847,7 +719,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSessionFalseWithExistingSession() throws Exception {
|
|
|
|
|
void buildRequestSessionFalseWithExistingSession() throws Exception {
|
|
|
|
|
String sessionId = "session-id";
|
|
|
|
|
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
@@ -857,14 +729,14 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSessionIsNew() throws Exception {
|
|
|
|
|
void buildRequestSessionIsNew() throws Exception {
|
|
|
|
|
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
|
|
|
|
|
|
|
|
|
assertThat(actualRequest.getSession().isNew()).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSessionIsNewFalse() throws Exception {
|
|
|
|
|
void buildRequestSessionIsNewFalse() throws Exception {
|
|
|
|
|
String sessionId = "session-id";
|
|
|
|
|
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
|
|
|
|
|
|
|
|
|
|
@@ -874,7 +746,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void buildRequestSessionInvalidate() throws Exception {
|
|
|
|
|
void buildRequestSessionInvalidate() throws Exception {
|
|
|
|
|
String sessionId = "session-id";
|
|
|
|
|
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
|
|
|
|
|
|
|
|
|
|
@@ -898,33 +770,33 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
// --- setContextPath
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setContextPathNull() {
|
|
|
|
|
void setContextPathNull() {
|
|
|
|
|
requestBuilder.setContextPath(null);
|
|
|
|
|
|
|
|
|
|
assertThat(getContextPath()).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setContextPathEmptyString() {
|
|
|
|
|
void setContextPathEmptyString() {
|
|
|
|
|
requestBuilder.setContextPath("");
|
|
|
|
|
|
|
|
|
|
assertThat(getContextPath()).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setContextPathDoesNotStartWithSlash() {
|
|
|
|
|
void setContextPathDoesNotStartWithSlash() {
|
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
|
|
|
|
requestBuilder.setContextPath("abc/def"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setContextPathEndsWithSlash() {
|
|
|
|
|
void setContextPathEndsWithSlash() {
|
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
|
|
|
|
requestBuilder.setContextPath("/abc/def/"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setContextPath() {
|
|
|
|
|
void setContextPath() {
|
|
|
|
|
String expectedContextPath = "/abc/def";
|
|
|
|
|
requestBuilder.setContextPath(expectedContextPath);
|
|
|
|
|
|
|
|
|
|
@@ -932,7 +804,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mergeHeader() throws Exception {
|
|
|
|
|
void mergeHeader() throws Exception {
|
|
|
|
|
String headerName = "PARENT";
|
|
|
|
|
String headerValue = "VALUE";
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController())
|
|
|
|
|
@@ -943,7 +815,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mergeSession() throws Exception {
|
|
|
|
|
void mergeSession() throws Exception {
|
|
|
|
|
String attrName = "PARENT";
|
|
|
|
|
String attrValue = "VALUE";
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController())
|
|
|
|
|
@@ -954,7 +826,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mergeSessionNotInitialized() throws Exception {
|
|
|
|
|
void mergeSessionNotInitialized() throws Exception {
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController())
|
|
|
|
|
.defaultRequest(get("/"))
|
|
|
|
|
.build();
|
|
|
|
|
@@ -963,7 +835,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mergeParameter() throws Exception {
|
|
|
|
|
void mergeParameter() throws Exception {
|
|
|
|
|
String paramName = "PARENT";
|
|
|
|
|
String paramValue = "VALUE";
|
|
|
|
|
String paramValue2 = "VALUE2";
|
|
|
|
|
@@ -976,7 +848,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mergeCookie() throws Exception {
|
|
|
|
|
void mergeCookie() throws Exception {
|
|
|
|
|
String cookieName = "PARENT";
|
|
|
|
|
String cookieValue = "VALUE";
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController())
|
|
|
|
|
@@ -992,7 +864,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mergeRequestAttribute() throws Exception {
|
|
|
|
|
void mergeRequestAttribute() throws Exception {
|
|
|
|
|
String attrName = "PARENT";
|
|
|
|
|
String attrValue = "VALUE";
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController())
|
|
|
|
|
@@ -1003,7 +875,7 @@ public class HtmlUnitRequestBuilderTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // SPR-14584
|
|
|
|
|
public void mergeDoesNotCorruptPathInfoOnParent() throws Exception {
|
|
|
|
|
void mergeDoesNotCorruptPathInfoOnParent() throws Exception {
|
|
|
|
|
String pathInfo = "/foo/bar";
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController())
|
|
|
|
|
.defaultRequest(get("/"))
|
|
|
|
|
|