use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHostWithDefaultPort.
@Test
// SPR-11872
void fromHttpRequestWithForwardedHostWithDefaultPort() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(10080);
request.addHeader("X-Forwarded-Host", "example.org");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertThat(result.getHost()).isEqualTo("example.org");
assertThat(result.getPort()).isEqualTo(-1);
}
use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHostWithForwardedScheme.
@Test
void fromHttpRequestWithForwardedHostWithForwardedScheme() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(10080);
request.addHeader("X-Forwarded-Host", "example.org");
request.addHeader("X-Forwarded-Proto", "https");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertThat(result.getHost()).isEqualTo("example.org");
assertThat(result.getScheme()).isEqualTo("https");
assertThat(result.getPort()).isEqualTo(-1);
}
use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestForwardedHeaderQuoted.
@Test
void fromHttpRequestForwardedHeaderQuoted() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "proto=\"https\"; host=\"84.198.58.199\"");
request.setScheme("http");
request.setServerName("example.com");
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertThat(result.getScheme()).isEqualTo("https");
assertThat(result.getHost()).isEqualTo("84.198.58.199");
assertThat(result.getPath()).isEqualTo("/rest/mobile/users/1");
}
use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestResetsPort443.
// gh-17368, gh-27097
@ParameterizedTest
@ValueSource(strings = { "https", "wss" })
void fromHttpRequestResetsPort443(String protocol) {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("X-Forwarded-Proto", protocol);
request.addHeader("X-Forwarded-Host", "84.198.58.199");
request.addHeader("X-Forwarded-Port", 443);
request.setScheme("http");
request.setServerName("example.com");
request.setServerPort(80);
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertThat(result.getScheme()).isEqualTo(protocol);
assertThat(result.getHost()).isEqualTo("84.198.58.199");
assertThat(result.getPort()).isEqualTo(-1);
assertThat(result.getPath()).isEqualTo("/rest/mobile/users/1");
}
use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class WebUtilsTests method checkSameOrigin.
private boolean checkSameOrigin(String scheme, String serverName, int port, String originHeader) {
MockHttpServletRequest servletRequest = new MockHttpServletRequest();
servletRequest.setScheme(scheme);
servletRequest.setServerName(serverName);
if (port != -1) {
servletRequest.setServerPort(port);
}
servletRequest.addHeader(HttpHeaders.ORIGIN, originHeader);
ServletRequestContext context = new ServletRequestContext(null, servletRequest, new MockHttpServletResponse());
return WebUtils.isSameOrigin(context);
}
Aggregations