Browse Source

URL Cleanup - Fix broken tests

See gh-22679
pull/22823/head
Sam Brannen 7 years ago
parent
commit
efa3ecd4e2
  1. 4
      spring-messaging/src/test/java/org/springframework/messaging/simp/SimpMessagingTemplateTests.java
  2. 6
      spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java
  3. 8
      spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java
  4. 6
      spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java
  5. 4
      spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java
  6. 2
      spring-web/src/test/java/org/springframework/http/RequestEntityTests.java
  7. 8
      spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java
  8. 12
      spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestTests.java
  9. 2
      spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java
  10. 3
      spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java
  11. 27
      spring-web/src/test/java/org/springframework/web/util/DefaultUriBuilderFactoryTests.java
  12. 4
      spring-web/src/test/java/org/springframework/web/util/DefaultUriTemplateHandlerTests.java
  13. 22
      spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java
  14. 28
      spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java
  15. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/resource/AppCacheManifestTransformerTests.java
  16. 2
      spring-webflux/src/test/resources/org/springframework/web/reactive/resource/test/test.appcache
  17. 4
      spring-webmvc/src/test/java/org/springframework/web/servlet/resource/AppCacheManifestTransformerTests.java
  18. 2
      spring-webmvc/src/test/resources/org/springframework/web/servlet/resource/test/test.appcache

4
spring-messaging/src/test/java/org/springframework/messaging/simp/SimpMessagingTemplateTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -83,7 +83,7 @@ public class SimpMessagingTemplateTests {
MessageHeaderAccessor.getAccessor(messages.get(0), SimpMessageHeaderAccessor.class); MessageHeaderAccessor.getAccessor(messages.get(0), SimpMessageHeaderAccessor.class);
assertNotNull(headerAccessor); assertNotNull(headerAccessor);
assertEquals("/user/http:%2F%2Fjoe.openid.example.org%2F/queue/foo", headerAccessor.getDestination()); assertEquals("/user/https:%2F%2Fjoe.openid.example.org%2F/queue/foo", headerAccessor.getDestination());
} }
@Test @Test

6
spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -74,7 +74,7 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
marshaller.marshal(flights, domResult); marshaller.marshal(flights, domResult);
Document expected = builder.newDocument(); Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights"); Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
Attr namespace = expected.createAttributeNS("https://www.w3.org/2000/xmlns/", "xmlns:tns"); Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
namespace.setNodeValue("http://samples.springframework.org/flight"); namespace.setNodeValue("http://samples.springframework.org/flight");
flightsElement.setAttributeNode(namespace); flightsElement.setAttributeNode(namespace);
expected.appendChild(flightsElement); expected.appendChild(flightsElement);
@ -98,7 +98,7 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
Document result = (Document) domResult.getNode(); Document result = (Document) domResult.getNode();
Document expected = builder.newDocument(); Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights"); Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
Attr namespace = expected.createAttributeNS("https://www.w3.org/2000/xmlns/", "xmlns:tns"); Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
namespace.setNodeValue("http://samples.springframework.org/flight"); namespace.setNodeValue("http://samples.springframework.org/flight");
flightsElement.setAttributeNode(namespace); flightsElement.setAttributeNode(namespace);
expected.appendChild(flightsElement); expected.appendChild(flightsElement);

8
spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -76,7 +76,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
*/ */
private static final String XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + private static final String XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + "<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns:java=\"https://java.sun.com\"" + " xmlns:java=\"http://java.sun.com\"" +
" xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" + " xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
"<name>test</name><value>8</value></castor-object></objects>"; "<name>test</name><value>8</value></castor-object></objects>";
@ -91,7 +91,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
*/ */
private static final String ROOT_WITH_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + private static final String ROOT_WITH_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<objects xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + "<objects xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns:java=\"https://java.sun.com\"" + " xmlns:java=\"http://java.sun.com\"" +
" xsi:type=\"java:java.util.Arrays$ArrayList\">" + " xsi:type=\"java:java.util.Arrays$ArrayList\">" +
"<castor-object xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" + "<castor-object xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
"<name>test</name><value>8</value></castor-object></objects>"; "<name>test</name><value>8</value></castor-object></objects>";
@ -101,7 +101,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
*/ */
private static final String ROOT_WITHOUT_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + private static final String ROOT_WITHOUT_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + "<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns:java=\"https://java.sun.com\"" + " xmlns:java=\"http://java.sun.com\"" +
" xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" + " xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
"<name>test</name><value>8</value></castor-object></objects>"; "<name>test</name><value>8</value></castor-object></objects>";

6
spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -91,9 +91,9 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests<Jaxb2Marsh
given(mimeContainer.getAttachment("<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).willReturn(dataHandler); given(mimeContainer.getAttachment("<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).willReturn(dataHandler);
given(mimeContainer.getAttachment("696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png")).willReturn(dataHandler); given(mimeContainer.getAttachment("696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png")).willReturn(dataHandler);
String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" + String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" +
"<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='https://www.w3.org/2004/08/xop/include'/>" + "<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
"</bytes>" + "<dataHandler>" + "</bytes>" + "<dataHandler>" +
"<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='https://www.w3.org/2004/08/xop/include'/>" + "<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
"</dataHandler>" + "</dataHandler>" +
"<swaDataHandler>696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png</swaDataHandler>" + "<swaDataHandler>696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png</swaDataHandler>" +
"</binaryObject>"; "</binaryObject>";

4
spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java

@ -618,7 +618,7 @@ public class HtmlUnitRequestBuilderTests {
@Test @Test
public void buildRequestRemotePort80WithDefault() throws Exception { public void buildRequestRemotePort80WithDefault() throws Exception {
webRequest.setUrl(new URL("https://example.com/")); webRequest.setUrl(new URL("http://example.com/"));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext); MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
@ -650,7 +650,7 @@ public class HtmlUnitRequestBuilderTests {
@Test @Test
public void buildRequestUrl() { public void buildRequestUrl() {
String uri = requestBuilder.buildRequest(servletContext).getRequestURL().toString(); String uri = requestBuilder.buildRequest(servletContext).getRequestURL().toString();
assertThat(uri, equalTo("https://example.com/test/this/here")); assertThat(uri, equalTo("http://example.com/test/this/here"));
} }
@Test @Test

2
spring-web/src/test/java/org/springframework/http/RequestEntityTests.java

@ -61,7 +61,7 @@ public class RequestEntityTests {
URI uri = new UriTemplate("https://example.com/{foo}").expand("bar"); URI uri = new UriTemplate("https://example.com/{foo}").expand("bar");
RequestEntity.get(uri).accept(MediaType.TEXT_PLAIN).build(); RequestEntity.get(uri).accept(MediaType.TEXT_PLAIN).build();
String url = "http://www.{host}.com/{path}"; String url = "https://www.{host}.com/{path}";
String host = "example"; String host = "example";
String path = "foo/bar"; String path = "foo/bar";
URI expected = new URI("https://www.example.com/foo/bar"); URI expected = new URI("https://www.example.com/foo/bar");

8
spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -60,6 +60,7 @@ public class ServletServerHttpRequestTests {
@Test @Test
public void getUriForSimplePath() throws URISyntaxException { public void getUriForSimplePath() throws URISyntaxException {
URI uri = new URI("https://example.com/path"); URI uri = new URI("https://example.com/path");
mockRequest.setScheme(uri.getScheme());
mockRequest.setServerName(uri.getHost()); mockRequest.setServerName(uri.getHost());
mockRequest.setServerPort(uri.getPort()); mockRequest.setServerPort(uri.getPort());
mockRequest.setRequestURI(uri.getPath()); mockRequest.setRequestURI(uri.getPath());
@ -70,6 +71,7 @@ public class ServletServerHttpRequestTests {
@Test @Test
public void getUriWithQueryString() throws URISyntaxException { public void getUriWithQueryString() throws URISyntaxException {
URI uri = new URI("https://example.com/path?query"); URI uri = new URI("https://example.com/path?query");
mockRequest.setScheme(uri.getScheme());
mockRequest.setServerName(uri.getHost()); mockRequest.setServerName(uri.getHost());
mockRequest.setServerPort(uri.getPort()); mockRequest.setServerPort(uri.getPort());
mockRequest.setRequestURI(uri.getPath()); mockRequest.setRequestURI(uri.getPath());
@ -82,7 +84,7 @@ public class ServletServerHttpRequestTests {
mockRequest.setServerName("example.com"); mockRequest.setServerName("example.com");
mockRequest.setRequestURI("/path"); mockRequest.setRequestURI("/path");
mockRequest.setQueryString("query=foo"); mockRequest.setQueryString("query=foo");
assertEquals(new URI("https://example.com/path?query=foo"), request.getURI()); assertEquals(new URI("http://example.com/path?query=foo"), request.getURI());
} }
@Test // SPR-16414 @Test // SPR-16414
@ -90,7 +92,7 @@ public class ServletServerHttpRequestTests {
mockRequest.setServerName("example.com"); mockRequest.setServerName("example.com");
mockRequest.setRequestURI("/path"); mockRequest.setRequestURI("/path");
mockRequest.setQueryString("query=foo%%x"); mockRequest.setQueryString("query=foo%%x");
assertEquals(new URI("https://example.com/path"), request.getURI()); assertEquals(new URI("http://example.com/path"), request.getURI());
} }
@Test // SPR-13876 @Test // SPR-13876

12
spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -96,16 +96,16 @@ public class ServerHttpRequestTests {
request = createHttpRequest("/").mutate().method(HttpMethod.DELETE).build(); request = createHttpRequest("/").mutate().method(HttpMethod.DELETE).build();
assertEquals(HttpMethod.DELETE, request.getMethod()); assertEquals(HttpMethod.DELETE, request.getMethod());
String baseUri = "https://www.aaa.org/articles/"; String baseUri = "http://www.aaa.org/articles/";
request = createHttpRequest(baseUri).mutate().uri(URI.create("https://bbb.org:9090/b")).build(); request = createHttpRequest(baseUri).mutate().uri(URI.create("http://bbb.org:9090/b")).build();
assertEquals("https://bbb.org:9090/b", request.getURI().toString()); assertEquals("http://bbb.org:9090/b", request.getURI().toString());
request = createHttpRequest(baseUri).mutate().path("/b/c/d").build(); request = createHttpRequest(baseUri).mutate().path("/b/c/d").build();
assertEquals("https://www.aaa.org/b/c/d", request.getURI().toString()); assertEquals("http://www.aaa.org/b/c/d", request.getURI().toString());
request = createHttpRequest(baseUri).mutate().path("/app/b/c/d").contextPath("/app").build(); request = createHttpRequest(baseUri).mutate().path("/app/b/c/d").contextPath("/app").build();
assertEquals("https://www.aaa.org/app/b/c/d", request.getURI().toString()); assertEquals("http://www.aaa.org/app/b/c/d", request.getURI().toString());
assertEquals("/app", request.getPath().contextPath().value()); assertEquals("/app", request.getPath().contextPath().value());
} }

2
spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java

@ -562,7 +562,7 @@ public class RestTemplateTests {
public void ioExceptionWithEmptyQueryString() throws Exception { public void ioExceptionWithEmptyQueryString() throws Exception {
// https://example.com/resource? // https://example.com/resource?
URI uri = new URI("http", "example.com", "/resource", "", null); URI uri = new URI("https", "example.com", "/resource", "", null);
given(converter.canRead(String.class, null)).willReturn(true); given(converter.canRead(String.class, null)).willReturn(true);
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(parseMediaType("foo/bar"))); given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(parseMediaType("foo/bar")));

3
spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -57,6 +57,7 @@ public class RequestPartServletServerHttpRequestTests {
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part"); ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
URI uri = new URI("https://example.com/path?query"); URI uri = new URI("https://example.com/path?query");
this.mockRequest.setScheme("https");
this.mockRequest.setServerName(uri.getHost()); this.mockRequest.setServerName(uri.getHost());
this.mockRequest.setServerPort(uri.getPort()); this.mockRequest.setServerPort(uri.getPort());
this.mockRequest.setRequestURI(uri.getPath()); this.mockRequest.setRequestURI(uri.getPath());

27
spring-web/src/test/java/org/springframework/web/util/DefaultUriBuilderFactoryTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.util; package org.springframework.web.util;
import java.net.URI; import java.net.URI;
@ -41,14 +42,14 @@ public class DefaultUriBuilderFactoryTests {
@Test @Test
public void baseUri() { public void baseUri() {
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://www.foo.com/v1?id=123"); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://example.com/v1?id=123");
URI uri = factory.uriString("/bar").port(8080).build(); URI uri = factory.uriString("/bar").port(8080).build();
assertEquals("https://foo.com:8080/v1/bar?id=123", uri.toString()); assertEquals("http://example.com:8080/v1/bar?id=123", uri.toString());
} }
@Test @Test
public void baseUriWithFullOverride() { public void baseUriWithFullOverride() {
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://www.foo.com/v1?id=123"); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://example.com/v1?id=123");
URI uri = factory.uriString("https://example.com/1/2").build(); URI uri = factory.uriString("https://example.com/1/2").build();
assertEquals("Use of host should case baseUri to be completely ignored", assertEquals("Use of host should case baseUri to be completely ignored",
"https://example.com/1/2", uri.toString()); "https://example.com/1/2", uri.toString());
@ -56,17 +57,17 @@ public class DefaultUriBuilderFactoryTests {
@Test @Test
public void baseUriWithPathOverride() { public void baseUriWithPathOverride() {
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://www.foo.com/v1"); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://example.com/v1");
URI uri = factory.builder().replacePath("/baz").build(); URI uri = factory.builder().replacePath("/baz").build();
assertEquals("http://www.foo.com/baz", uri.toString()); assertEquals("http://example.com/baz", uri.toString());
} }
@Test @Test
public void defaultUriVars() { public void defaultUriVars() {
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1"); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1");
factory.setDefaultUriVariables(singletonMap("host", "foo.com")); factory.setDefaultUriVariables(singletonMap("host", "example.com"));
URI uri = factory.uriString("/{id}").build(singletonMap("id", "123")); URI uri = factory.uriString("/{id}").build(singletonMap("id", "123"));
assertEquals("http://www.foo.com/v1/123", uri.toString()); assertEquals("http://example.com/v1/123", uri.toString());
} }
@Test @Test
@ -74,15 +75,15 @@ public class DefaultUriBuilderFactoryTests {
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1"); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1");
factory.setDefaultUriVariables(singletonMap("host", "spring.io")); factory.setDefaultUriVariables(singletonMap("host", "spring.io"));
URI uri = factory.uriString("/bar").build(singletonMap("host", "docs.spring.io")); URI uri = factory.uriString("/bar").build(singletonMap("host", "docs.spring.io"));
assertEquals("https://docs.spring.io/v1/bar", uri.toString()); assertEquals("http://docs.spring.io/v1/bar", uri.toString());
} }
@Test @Test
public void defaultUriVarsWithEmptyVarArg() { public void defaultUriVarsWithEmptyVarArg() {
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1"); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1");
factory.setDefaultUriVariables(singletonMap("host", "foo.com")); factory.setDefaultUriVariables(singletonMap("host", "example.com"));
URI uri = factory.uriString("/bar").build(); URI uri = factory.uriString("/bar").build();
assertEquals("Expected delegation to build(Map) method", "http://www.foo.com/v1/bar", uri.toString()); assertEquals("Expected delegation to build(Map) method", "http://example.com/v1/bar", uri.toString());
} }
@Test @Test
@ -138,10 +139,10 @@ public class DefaultUriBuilderFactoryTests {
public void encodingValuesOnlySpr14147() { public void encodingValuesOnlySpr14147() {
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
factory.setEncodingMode(EncodingMode.VALUES_ONLY); factory.setEncodingMode(EncodingMode.VALUES_ONLY);
factory.setDefaultUriVariables(singletonMap("host", "www.example.com")); factory.setDefaultUriVariables(singletonMap("host", "example.com"));
UriBuilder uriBuilder = factory.uriString("http://{host}/user/{userId}/dashboard"); UriBuilder uriBuilder = factory.uriString("http://{host}/user/{userId}/dashboard");
assertEquals("https://www.example.com/user/john%3Bdoe/dashboard", assertEquals("http://example.com/user/john%3Bdoe/dashboard",
uriBuilder.build(singletonMap("userId", "john;doe")).toString()); uriBuilder.build(singletonMap("userId", "john;doe")).toString());
} }

4
spring-web/src/test/java/org/springframework/web/util/DefaultUriTemplateHandlerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -142,7 +142,7 @@ public class DefaultUriTemplateHandlerTests {
Map<String, Object> vars = new HashMap<>(1); Map<String, Object> vars = new HashMap<>(1);
vars.put("userId", "john;doe"); vars.put("userId", "john;doe");
String template = "http://{host}/user/{userId}/dashboard"; String template = "https://{host}/user/{userId}/dashboard";
URI actual = this.handler.expand(template, vars); URI actual = this.handler.expand(template, vars);
assertEquals("https://www.example.com/user/john%3Bdoe/dashboard", actual.toString()); assertEquals("https://www.example.com/user/john%3Bdoe/dashboard", actual.toString());

22
spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

@ -51,10 +51,10 @@ public class UriComponentsBuilderTests {
@Test @Test
public void plain() throws URISyntaxException { public void plain() throws URISyntaxException {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
UriComponents result = builder.scheme("http").host("example.com") UriComponents result = builder.scheme("https").host("example.com")
.path("foo").queryParam("bar").fragment("baz") .path("foo").queryParam("bar").fragment("baz")
.build(); .build();
assertEquals("http", result.getScheme()); assertEquals("https", result.getScheme());
assertEquals("example.com", result.getHost()); assertEquals("example.com", result.getHost());
assertEquals("foo", result.getPath()); assertEquals("foo", result.getPath());
assertEquals("bar", result.getQuery()); assertEquals("bar", result.getQuery());
@ -67,18 +67,18 @@ public class UriComponentsBuilderTests {
@Test @Test
public void multipleFromSameBuilder() throws URISyntaxException { public void multipleFromSameBuilder() throws URISyntaxException {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance() UriComponentsBuilder builder = UriComponentsBuilder.newInstance()
.scheme("http").host("example.com").pathSegment("foo"); .scheme("https").host("example.com").pathSegment("foo");
UriComponents result1 = builder.build(); UriComponents result1 = builder.build();
builder = builder.pathSegment("foo2").queryParam("bar").fragment("baz"); builder = builder.pathSegment("foo2").queryParam("bar").fragment("baz");
UriComponents result2 = builder.build(); UriComponents result2 = builder.build();
assertEquals("http", result1.getScheme()); assertEquals("https", result1.getScheme());
assertEquals("example.com", result1.getHost()); assertEquals("example.com", result1.getHost());
assertEquals("/foo", result1.getPath()); assertEquals("/foo", result1.getPath());
URI expected = new URI("https://example.com/foo"); URI expected = new URI("https://example.com/foo");
assertEquals("Invalid result URI", expected, result1.toUri()); assertEquals("Invalid result URI", expected, result1.toUri());
assertEquals("http", result2.getScheme()); assertEquals("https", result2.getScheme());
assertEquals("example.com", result2.getHost()); assertEquals("example.com", result2.getHost());
assertEquals("/foo/foo2", result2.getPath()); assertEquals("/foo/foo2", result2.getPath());
assertEquals("bar", result2.getQuery()); assertEquals("bar", result2.getQuery());
@ -110,7 +110,7 @@ public class UriComponentsBuilderTests {
public void fromHierarchicalUri() throws URISyntaxException { public void fromHierarchicalUri() throws URISyntaxException {
URI uri = new URI("https://example.com/foo?bar#baz"); URI uri = new URI("https://example.com/foo?bar#baz");
UriComponents result = UriComponentsBuilder.fromUri(uri).build(); UriComponents result = UriComponentsBuilder.fromUri(uri).build();
assertEquals("http", result.getScheme()); assertEquals("https", result.getScheme());
assertEquals("example.com", result.getHost()); assertEquals("example.com", result.getHost());
assertEquals("/foo", result.getPath()); assertEquals("/foo", result.getPath());
assertEquals("bar", result.getQuery()); assertEquals("bar", result.getQuery());
@ -143,7 +143,7 @@ public class UriComponentsBuilderTests {
@Test @Test
public void fromUriString() { public void fromUriString() {
UriComponents result = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc3986.txt").build(); UriComponents result = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc3986.txt").build();
assertEquals("http", result.getScheme()); assertEquals("https", result.getScheme());
assertNull(result.getUserInfo()); assertNull(result.getUserInfo());
assertEquals("www.ietf.org", result.getHost()); assertEquals("www.ietf.org", result.getHost());
assertEquals(-1, result.getPort()); assertEquals(-1, result.getPort());
@ -155,7 +155,7 @@ public class UriComponentsBuilderTests {
String url = "https://arjen:foobar@java.sun.com:80" + String url = "https://arjen:foobar@java.sun.com:80" +
"/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)"; "/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)";
result = UriComponentsBuilder.fromUriString(url).build(); result = UriComponentsBuilder.fromUriString(url).build();
assertEquals("http", result.getScheme()); assertEquals("https", result.getScheme());
assertEquals("arjen:foobar", result.getUserInfo()); assertEquals("arjen:foobar", result.getUserInfo());
assertEquals("java.sun.com", result.getHost()); assertEquals("java.sun.com", result.getHost());
assertEquals(80, result.getPort()); assertEquals(80, result.getPort());
@ -278,7 +278,7 @@ public class UriComponentsBuilderTests {
@Test // SPR-14761 @Test // SPR-14761
public void fromHttpRequestWithForwardedIPv4Host() { public void fromHttpRequestWithForwardedIPv4Host() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http"); request.setScheme("https");
request.setServerName("localhost"); request.setServerName("localhost");
request.setServerPort(-1); request.setServerPort(-1);
request.setRequestURI("/mvc-showcase"); request.setRequestURI("/mvc-showcase");
@ -287,7 +287,7 @@ public class UriComponentsBuilderTests {
HttpRequest httpRequest = new ServletServerHttpRequest(request); HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("http://192.168.0.1/mvc-showcase", result.toString()); assertEquals("https://192.168.0.1/mvc-showcase", result.toString());
} }
@Test // SPR-14761 @Test // SPR-14761
@ -476,7 +476,7 @@ public class UriComponentsBuilderTests {
HttpRequest httpRequest = new ServletServerHttpRequest(request); HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("https://a.example.org/mvc-showcase", result.toString()); assertEquals("http://a.example.org/mvc-showcase", result.toString());
} }
@Test // SPR-12816 @Test // SPR-12816

28
spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -91,21 +91,21 @@ public class WebUtilsTests {
@Test @Test
public void isValidOrigin() { public void isValidOrigin() {
List<String> allowed = Collections.emptyList(); List<String> allowed = Collections.emptyList();
assertTrue(checkValidOrigin("mydomain1.com", -1, "https://mydomain1.com", allowed)); assertTrue(checkValidOrigin("mydomain1.com", -1, "http://mydomain1.com", allowed));
assertFalse(checkValidOrigin("mydomain1.com", -1, "http://mydomain2.com", allowed)); assertFalse(checkValidOrigin("mydomain1.com", -1, "http://mydomain2.com", allowed));
allowed = Collections.singletonList("*"); allowed = Collections.singletonList("*");
assertTrue(checkValidOrigin("mydomain1.com", -1, "http://mydomain2.com", allowed)); assertTrue(checkValidOrigin("mydomain1.com", -1, "http://mydomain2.com", allowed));
allowed = Collections.singletonList("https://mydomain1.com"); allowed = Collections.singletonList("http://mydomain1.com");
assertTrue(checkValidOrigin("mydomain2.com", -1, "https://mydomain1.com", allowed)); assertTrue(checkValidOrigin("mydomain2.com", -1, "http://mydomain1.com", allowed));
assertFalse(checkValidOrigin("mydomain2.com", -1, "http://mydomain3.com", allowed)); assertFalse(checkValidOrigin("mydomain2.com", -1, "http://mydomain3.com", allowed));
} }
@Test @Test
public void isSameOrigin() { public void isSameOrigin() {
assertTrue(checkSameOrigin("mydomain1.com", -1, "https://mydomain1.com")); assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com"));
assertTrue(checkSameOrigin("mydomain1.com", -1, "https://www.mydomain1.com/")); assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com:80"));
assertTrue(checkSameOrigin("mydomain1.com", 443, "https://mydomain1.com")); assertTrue(checkSameOrigin("mydomain1.com", 443, "https://mydomain1.com"));
assertTrue(checkSameOrigin("mydomain1.com", 443, "https://mydomain1.com:443")); assertTrue(checkSameOrigin("mydomain1.com", 443, "https://mydomain1.com:443"));
assertTrue(checkSameOrigin("mydomain1.com", 123, "https://mydomain1.com:123")); assertTrue(checkSameOrigin("mydomain1.com", 123, "https://mydomain1.com:123"));
@ -117,14 +117,14 @@ public class WebUtilsTests {
assertFalse(checkSameOrigin("mydomain1.com", -1, "invalid-origin")); assertFalse(checkSameOrigin("mydomain1.com", -1, "invalid-origin"));
// Handling of invalid origins as described in SPR-13478 // Handling of invalid origins as described in SPR-13478
assertTrue(checkSameOrigin("mydomain1.com", -1, "https://mydomain1.com/")); assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com/"));
assertTrue(checkSameOrigin("mydomain1.com", -1, "https://www.mydomain1.com/")); assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com:80"));
assertTrue(checkSameOrigin("mydomain1.com", -1, "https://mydomain1.com/path")); assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com/path"));
assertTrue(checkSameOrigin("mydomain1.com", -1, "https://www.mydomain1.com/path")); assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com:80/path"));
assertFalse(checkSameOrigin("mydomain2.com", -1, "https://mydomain1.com/")); assertFalse(checkSameOrigin("mydomain2.com", -1, "http://mydomain1.com/"));
assertFalse(checkSameOrigin("mydomain2.com", -1, "https://www.mydomain1.com/")); assertFalse(checkSameOrigin("mydomain2.com", -1, "http://mydomain1.com:80/"));
assertFalse(checkSameOrigin("mydomain2.com", -1, "https://mydomain1.com/path")); assertFalse(checkSameOrigin("mydomain2.com", -1, "http://mydomain1.com/path"));
assertFalse(checkSameOrigin("mydomain2.com", -1, "https://www.mydomain1.com/path")); assertFalse(checkSameOrigin("mydomain2.com", -1, "http://mydomain1.com:80/path"));
// Handling of IPv6 hosts as described in SPR-13525 // Handling of IPv6 hosts as described in SPR-13525
assertTrue(checkSameOrigin("[::1]", -1, "http://[::1]")); assertTrue(checkSameOrigin("[::1]", -1, "http://[::1]"));

4
spring-webflux/src/test/java/org/springframework/web/reactive/resource/AppCacheManifestTransformerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -134,7 +134,7 @@ public class AppCacheManifestTransformerTests {
assertThat("should not rewrite external resources", content, assertThat("should not rewrite external resources", content,
Matchers.containsString("//example.org/style.css")); Matchers.containsString("//example.org/style.css"));
assertThat("should not rewrite external resources", content, assertThat("should not rewrite external resources", content,
Matchers.containsString("https://example.org/image.png")); Matchers.containsString("http://example.org/image.png"));
assertThat("should generate fingerprint", content, assertThat("should generate fingerprint", content,
Matchers.containsString("# Hash: 8eefc904df3bd46537fa7bdbbc5ab9fb")); Matchers.containsString("# Hash: 8eefc904df3bd46537fa7bdbbc5ab9fb"));

2
spring-webflux/src/test/resources/org/springframework/web/reactive/resource/test/test.appcache

@ -11,7 +11,7 @@ NETWORK:
CACHE: CACHE:
js/bar.js js/bar.js
https://example.org/image.png http://example.org/image.png
FALLBACK: FALLBACK:
/main /static.html /main /static.html

4
spring-webmvc/src/test/java/org/springframework/web/servlet/resource/AppCacheManifestTransformerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -113,7 +113,7 @@ public class AppCacheManifestTransformerTests {
assertThat("should not rewrite external resources", content, assertThat("should not rewrite external resources", content,
Matchers.containsString("//example.org/style.css")); Matchers.containsString("//example.org/style.css"));
assertThat("should not rewrite external resources", content, assertThat("should not rewrite external resources", content,
Matchers.containsString("https://example.org/image.png")); Matchers.containsString("http://example.org/image.png"));
assertThat("should generate fingerprint", content, assertThat("should generate fingerprint", content,
Matchers.containsString("# Hash: 4bf0338bcbeb0a5b3a4ec9ed8864107d")); Matchers.containsString("# Hash: 4bf0338bcbeb0a5b3a4ec9ed8864107d"));

2
spring-webmvc/src/test/resources/org/springframework/web/servlet/resource/test/test.appcache

@ -11,7 +11,7 @@ NETWORK:
CACHE: CACHE:
js/bar.js js/bar.js
https://example.org/image.png http://example.org/image.png
FALLBACK: FALLBACK:
/main /static.html /main /static.html
Loading…
Cancel
Save