Fix http URLs

See gh-22839
This commit is contained in:
Rob Winch
2019-04-23 16:35:28 -05:00
committed by Stephane Nicoll
parent b5fba14ab8
commit fde92793b5
36 changed files with 215 additions and 207 deletions

View File

@@ -42,30 +42,30 @@ public class MockRestRequestMatchersTests {
@Test
public void requestTo() throws Exception {
this.request.setURI(new URI("http://www.foo.com/bar"));
this.request.setURI(new URI("http://www.foo.example/bar"));
MockRestRequestMatchers.requestTo("http://www.foo.com/bar").match(this.request);
MockRestRequestMatchers.requestTo("http://www.foo.example/bar").match(this.request);
}
@Test // SPR-15819
public void requestToUriTemplate() throws Exception {
this.request.setURI(new URI("http://www.foo.com/bar"));
this.request.setURI(new URI("http://www.foo.example/bar"));
MockRestRequestMatchers.requestToUriTemplate("http://www.foo.com/{bar}", "bar").match(this.request);
MockRestRequestMatchers.requestToUriTemplate("http://www.foo.example/{bar}", "bar").match(this.request);
}
@Test
public void requestToNoMatch() throws Exception {
this.request.setURI(new URI("http://www.foo.com/bar"));
this.request.setURI(new URI("http://www.foo.example/bar"));
assertThatThrownBy(
() -> MockRestRequestMatchers.requestTo("http://www.foo.com/wrong").match(this.request))
() -> MockRestRequestMatchers.requestTo("http://www.foo.example/wrong").match(this.request))
.isInstanceOf(AssertionError.class);
}
@Test
public void requestToContains() throws Exception {
this.request.setURI(new URI("http://www.foo.com/bar"));
this.request.setURI(new URI("http://www.foo.example/bar"));
MockRestRequestMatchers.requestTo(containsString("bar")).match(this.request);
}
@@ -157,14 +157,14 @@ public class MockRestRequestMatchersTests {
@Test
public void queryParam() throws Exception {
this.request.setURI(new URI("http://www.foo.com/a?foo=bar&foo=baz"));
this.request.setURI(new URI("http://www.foo.example/a?foo=bar&foo=baz"));
MockRestRequestMatchers.queryParam("foo", "bar", "baz").match(this.request);
}
@Test
public void queryParamMissing() throws Exception {
this.request.setURI(new URI("http://www.foo.com/a"));
this.request.setURI(new URI("http://www.foo.example/a"));
assertThatThrownBy(() -> MockRestRequestMatchers.queryParam("foo", "bar").match(this.request))
.isInstanceOf(AssertionError.class)
@@ -173,7 +173,7 @@ public class MockRestRequestMatchersTests {
@Test
public void queryParamMissingValue() throws Exception {
this.request.setURI(new URI("http://www.foo.com/a?foo=bar&foo=baz"));
this.request.setURI(new URI("http://www.foo.example/a?foo=bar&foo=baz"));
assertThatThrownBy(() -> MockRestRequestMatchers.queryParam("foo", "bad").match(this.request))
.isInstanceOf(AssertionError.class)
@@ -182,14 +182,14 @@ public class MockRestRequestMatchersTests {
@Test
public void queryParamContains() throws Exception {
this.request.setURI(new URI("http://www.foo.com/a?foo=bar&foo=baz"));
this.request.setURI(new URI("http://www.foo.example/a?foo=bar&foo=baz"));
MockRestRequestMatchers.queryParam("foo", containsString("ba")).match(this.request);
}
@Test
public void queryParamContainsWithMissingValue() throws Exception {
this.request.setURI(new URI("http://www.foo.com/a?foo=bar&foo=baz"));
this.request.setURI(new URI("http://www.foo.example/a?foo=bar&foo=baz"));
assertThatThrownBy(() -> MockRestRequestMatchers.queryParam("foo", containsString("bx")).match(this.request))
.isInstanceOf(AssertionError.class)

View File

@@ -31,14 +31,14 @@ public class HostRequestMatcherTests extends AbstractWebRequestMatcherTests {
public void localhost() throws Exception {
WebRequestMatcher matcher = new HostRequestMatcher("localhost");
assertMatches(matcher, "http://localhost/jquery-1.11.0.min.js");
assertDoesNotMatch(matcher, "http://example.com/jquery-1.11.0.min.js");
assertDoesNotMatch(matcher, "http://company.example/jquery-1.11.0.min.js");
}
@Test
public void multipleHosts() throws Exception {
WebRequestMatcher matcher = new HostRequestMatcher("localhost", "example.com");
assertMatches(matcher, "http://localhost/jquery-1.11.0.min.js");
assertMatches(matcher, "http://example.com/jquery-1.11.0.min.js");
assertMatches(matcher, "https://example.com/jquery-1.11.0.min.js");
}
@Test

View File

@@ -71,7 +71,7 @@ public class HtmlUnitRequestBuilderTests {
@Before
public void setup() throws Exception {
webRequest = new WebRequest(new URL("http://example.com:80/test/this/here"));
webRequest = new WebRequest(new URL("https://example.com/test/this/here"));
webRequest.setHttpMethod(HttpMethod.GET);
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
}
@@ -174,7 +174,7 @@ public class HtmlUnitRequestBuilderTests {
@Test
public void buildRequestContextPathUsesNoFirstSegmentWithDefault() throws MalformedURLException {
webRequest.setUrl(new URL("http://example.com/"));
webRequest.setUrl(new URL("https://example.com/"));
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
assertThat(contextPath).isEqualTo("");
@@ -342,7 +342,8 @@ public class HtmlUnitRequestBuilderTests {
}
@Test
public void buildRequestLocalPort() {
public void buildRequestLocalPort() throws Exception {
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
assertThat(actualRequest.getLocalPort()).isEqualTo(80);
@@ -599,6 +600,7 @@ public class HtmlUnitRequestBuilderTests {
@Test
public void buildRequestRemotePort() throws Exception {
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
assertThat(actualRequest.getRemotePort()).isEqualTo(80);
@@ -615,7 +617,7 @@ public class HtmlUnitRequestBuilderTests {
@Test
public void buildRequestRemotePort80WithDefault() throws Exception {
webRequest.setUrl(new URL("http://example.com/"));
webRequest.setUrl(new URL("http://company.example/"));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
@@ -647,11 +649,12 @@ public class HtmlUnitRequestBuilderTests {
@Test
public void buildRequestUrl() {
String uri = requestBuilder.buildRequest(servletContext).getRequestURL().toString();
assertThat(uri).isEqualTo("http://example.com/test/this/here");
assertThat(uri).isEqualTo("https://example.com/test/this/here");
}
@Test
public void buildRequestSchemeHttp() throws Exception {
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
assertThat(actualRequest.getScheme()).isEqualTo("http");
@@ -674,6 +677,7 @@ public class HtmlUnitRequestBuilderTests {
@Test
public void buildRequestServerPort() throws Exception {
webRequest.setUrl(new URL("http://localhost:80/test/this/here"));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
assertThat(actualRequest.getServerPort()).isEqualTo(80);

View File

@@ -108,13 +108,13 @@ public class MockMvcConnectionBuilderSupportTests {
assertMockMvcUsed(conn, "http://localhost/");
assertMockMvcUsed(conn, "https://example.com/");
assertMockMvcNotUsed(conn, "http://other.com/");
assertMockMvcNotUsed(conn, "http://other.example/");
}
@Test
public void mockMvcAlwaysUseMockMvc() throws Exception {
WebConnection conn = this.builder.alwaysUseMockMvc().createConnection(this.client);
assertMockMvcUsed(conn, "http://other.com/");
assertMockMvcUsed(conn, "http://other.example/");
}
@Test

View File

@@ -50,7 +50,7 @@ public class MockWebResponseBuilderTests {
@Before
public void setup() throws Exception {
this.webRequest = new WebRequest(new URL("http://example.com:80/test/this/here"));
this.webRequest = new WebRequest(new URL("http://company.example:80/test/this/here"));
this.responseBuilder = new MockWebResponseBuilder(System.currentTimeMillis(), this.webRequest, this.response);
}
@@ -66,7 +66,7 @@ public class MockWebResponseBuilderTests {
@Test
public void constructorWithNullResponse() throws Exception {
assertThatIllegalArgumentException().isThrownBy(() ->
new MockWebResponseBuilder(0L, new WebRequest(new URL("http://example.com:80/test/this/here")), null));
new MockWebResponseBuilder(0L, new WebRequest(new URL("http://company.example:80/test/this/here")), null));
}