From 8d403bf0075a5ab89c041bffa2cbe2b7738b79f9 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 27 Mar 2019 15:31:55 +0100 Subject: [PATCH] URL Cleanup - Fix broken tests See gh-22677 --- .../CustomNamespaceHandlerTests-context.xml | 6 ++-- .../simp/SimpMessagingTemplateTests.java | 4 +-- .../oxm/AbstractMarshallerTests.java | 6 ++-- .../oxm/castor/CastorMarshallerTests.java | 8 +++--- .../oxm/jaxb/Jaxb2UnmarshallerTests.java | 6 ++-- .../htmlunit/HtmlUnitRequestBuilderTests.java | 4 +-- .../http/RequestEntityTests.java | 4 +-- .../server/ServletServerHttpRequestTests.java | 3 +- ...uestPartServletServerHttpRequestTests.java | 3 +- .../util/DefaultUriTemplateHandlerTests.java | 2 +- .../web/util/UriComponentsBuilderTests.java | 24 ++++++++-------- .../web/util/WebUtilsTests.java | 28 +++++++++---------- .../AppCacheManifestTransformerTests.java | 4 +-- .../servlet/resource/test/appcache.manifest | 2 +- 14 files changed, 53 insertions(+), 51 deletions(-) diff --git a/spring-context/src/test/resources/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests-context.xml b/spring-context/src/test/resources/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests-context.xml index 17c9c7e8f5..46f6111b93 100644 --- a/spring-context/src/test/resources/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests-context.xml +++ b/spring-context/src/test/resources/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests-context.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:test="http://www.springframework.org/schema/beans/test" xmlns:util="http://www.springframework.org/schema/util" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd - http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd - http://www.springframework.org/schema/beans/test http://www.springframework.org/schema/beans/factory/xml/support/CustomNamespaceHandlerTests.xsd" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util-2.0.xsd + http://www.springframework.org/schema/beans/test https://www.springframework.org/schema/beans/factory/xml/support/CustomNamespaceHandlerTests.xsd" default-lazy-init="true"> diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/SimpMessagingTemplateTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/SimpMessagingTemplateTests.java index d5d4ad4eaa..77f66b56e3 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/SimpMessagingTemplateTests.java +++ b/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"); * 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); 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 diff --git a/spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java index 225decbd04..f871ee85e7 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java +++ b/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"); * you may not use this file except in compliance with the License. @@ -79,7 +79,7 @@ public abstract class AbstractMarshallerTests { marshaller.marshal(flights, domResult); Document expected = builder.newDocument(); 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"); flightsElement.setAttributeNode(namespace); expected.appendChild(flightsElement); @@ -103,7 +103,7 @@ public abstract class AbstractMarshallerTests { Document result = (Document) domResult.getNode(); Document expected = builder.newDocument(); 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"); flightsElement.setAttributeNode(namespace); expected.appendChild(flightsElement); diff --git a/spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java index 7c8901f9f0..45400ac459 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.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"); * you may not use this file except in compliance with the License. @@ -82,7 +82,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests" + "" + "test8"; @@ -97,7 +97,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests" + "" + "" + "test8"; @@ -107,7 +107,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests" + "" + "test8"; diff --git a/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java index 919d9b4504..f40cec6c78 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java +++ b/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"); * you may not use this file except in compliance with the License. @@ -91,9 +91,9 @@ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests")).willReturn(dataHandler); given(mimeContainer.getAttachment("696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png")).willReturn(dataHandler); String content = "" + "" + - "" + + "" + "" + "" + - "" + + "" + "" + "696cfb9a-4d2d-402f-bb5c-59fa69e7f0b3@spring-ws.png" + ""; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java index 2b1e812ee8..667e060f88 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java @@ -596,7 +596,7 @@ public class HtmlUnitRequestBuilderTests { @Test public void buildRequestRemotePort80WithDefault() throws Exception { - webRequest.setUrl(new URL("https://example.com/")); + webRequest.setUrl(new URL("http://example.com/")); MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext); @@ -628,7 +628,7 @@ public class HtmlUnitRequestBuilderTests { @Test public void buildRequestUrl() { 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 diff --git a/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java b/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java index 9d84f9151d..3e4ea9c070 100644 --- a/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java +++ b/spring-web/src/test/java/org/springframework/http/RequestEntityTests.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"); * you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ public class RequestEntityTests { URI uri = new UriTemplate("https://example.com/{foo}").expand("bar"); 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 path = "foo/bar"; URI expected = new URI("https://www.example.com/foo/bar"); diff --git a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java index cfdc888cbd..6f29fd97ea 100644 --- a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.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"); * you may not use this file except in compliance with the License. @@ -57,6 +57,7 @@ public class ServletServerHttpRequestTests { @Test public void getURI() throws Exception { URI uri = new URI("https://example.com/path?query"); + mockRequest.setScheme(uri.getScheme()); mockRequest.setServerName(uri.getHost()); mockRequest.setServerPort(uri.getPort()); mockRequest.setRequestURI(uri.getPath()); diff --git a/spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java b/spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java index bfbfe58805..ef93cb31d0 100644 --- a/spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java +++ b/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"); * 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"); URI uri = new URI("https://example.com/path?query"); + this.mockRequest.setScheme("https"); this.mockRequest.setServerName(uri.getHost()); this.mockRequest.setServerPort(uri.getPort()); this.mockRequest.setRequestURI(uri.getPath()); diff --git a/spring-web/src/test/java/org/springframework/web/util/DefaultUriTemplateHandlerTests.java b/spring-web/src/test/java/org/springframework/web/util/DefaultUriTemplateHandlerTests.java index 86c387646e..0790c64486 100644 --- a/spring-web/src/test/java/org/springframework/web/util/DefaultUriTemplateHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/DefaultUriTemplateHandlerTests.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"); * you may not use this file except in compliance with the License. diff --git a/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java b/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java index b6cbf4545f..0483921e91 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.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"); * you may not use this file except in compliance with the License. @@ -49,8 +49,8 @@ public class UriComponentsBuilderTests { @Test public void plain() throws URISyntaxException { UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); - UriComponents result = builder.scheme("http").host("example.com").path("foo").queryParam("bar").fragment("baz").build(); - assertEquals("http", result.getScheme()); + UriComponents result = builder.scheme("https").host("example.com").path("foo").queryParam("bar").fragment("baz").build(); + assertEquals("https", result.getScheme()); assertEquals("example.com", result.getHost()); assertEquals("foo", result.getPath()); assertEquals("bar", result.getQuery()); @@ -62,18 +62,18 @@ public class UriComponentsBuilderTests { @Test public void multipleFromSameBuilder() throws URISyntaxException { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance().scheme("http").host("example.com").pathSegment("foo"); + UriComponentsBuilder builder = UriComponentsBuilder.newInstance().scheme("https").host("example.com").pathSegment("foo"); UriComponents result1 = builder.build(); builder = builder.pathSegment("foo2").queryParam("bar").fragment("baz"); UriComponents result2 = builder.build(); - assertEquals("http", result1.getScheme()); + assertEquals("https", result1.getScheme()); assertEquals("example.com", result1.getHost()); assertEquals("/foo", result1.getPath()); URI expected = new URI("https://example.com/foo"); assertEquals("Invalid result URI", expected, result1.toUri()); - assertEquals("http", result2.getScheme()); + assertEquals("https", result2.getScheme()); assertEquals("example.com", result2.getHost()); assertEquals("/foo/foo2", result2.getPath()); assertEquals("bar", result2.getQuery()); @@ -105,7 +105,7 @@ public class UriComponentsBuilderTests { public void fromHierarchicalUri() throws URISyntaxException { URI uri = new URI("https://example.com/foo?bar#baz"); UriComponents result = UriComponentsBuilder.fromUri(uri).build(); - assertEquals("http", result.getScheme()); + assertEquals("https", result.getScheme()); assertEquals("example.com", result.getHost()); assertEquals("/foo", result.getPath()); assertEquals("bar", result.getQuery()); @@ -137,7 +137,7 @@ public class UriComponentsBuilderTests { @Test public void fromUriString() { UriComponents result = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc3986.txt").build(); - assertEquals("http", result.getScheme()); + assertEquals("https", result.getScheme()); assertNull(result.getUserInfo()); assertEquals("www.ietf.org", result.getHost()); assertEquals(-1, result.getPort()); @@ -149,7 +149,7 @@ public class UriComponentsBuilderTests { result = UriComponentsBuilder.fromUriString( "https://arjen:foobar@java.sun.com:80/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)") .build(); - assertEquals("http", result.getScheme()); + assertEquals("https", result.getScheme()); assertEquals("arjen:foobar", result.getUserInfo()); assertEquals("java.sun.com", result.getHost()); assertEquals(80, result.getPort()); @@ -266,7 +266,7 @@ public class UriComponentsBuilderTests { @Test //SPR-14761 public void fromHttpRequestWithForwardedIPv4Host() { MockHttpServletRequest request = new MockHttpServletRequest(); - request.setScheme("http"); + request.setScheme("https"); request.setServerName("localhost"); request.setServerPort(-1); request.setRequestURI("/mvc-showcase"); @@ -275,7 +275,7 @@ public class UriComponentsBuilderTests { HttpRequest httpRequest = new ServletServerHttpRequest(request); 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 @@ -449,7 +449,7 @@ public class UriComponentsBuilderTests { HttpRequest httpRequest = new ServletServerHttpRequest(request); 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 diff --git a/spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java index 4c53c44bf0..f7a105e53c 100644 --- a/spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/WebUtilsTests.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"); * you may not use this file except in compliance with the License. @@ -116,21 +116,21 @@ public class WebUtilsTests { @Test public void isValidOrigin() { List 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)); allowed = Collections.singletonList("*"); assertTrue(checkValidOrigin("mydomain1.com", -1, "http://mydomain2.com", allowed)); - allowed = Collections.singletonList("https://mydomain1.com"); - assertTrue(checkValidOrigin("mydomain2.com", -1, "https://mydomain1.com", allowed)); + allowed = Collections.singletonList("http://mydomain1.com"); + assertTrue(checkValidOrigin("mydomain2.com", -1, "http://mydomain1.com", allowed)); assertFalse(checkValidOrigin("mydomain2.com", -1, "http://mydomain3.com", allowed)); } @Test public void isSameOrigin() { - assertTrue(checkSameOrigin("mydomain1.com", -1, "https://mydomain1.com")); - assertTrue(checkSameOrigin("mydomain1.com", -1, "https://www.mydomain1.com/")); + assertTrue(checkSameOrigin("mydomain1.com", -1, "http://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:443")); assertTrue(checkSameOrigin("mydomain1.com", 123, "https://mydomain1.com:123")); @@ -142,14 +142,14 @@ public class WebUtilsTests { assertFalse(checkSameOrigin("mydomain1.com", -1, "invalid-origin")); // Handling of invalid origins as described in SPR-13478 - assertTrue(checkSameOrigin("mydomain1.com", -1, "https://mydomain1.com/")); - assertTrue(checkSameOrigin("mydomain1.com", -1, "https://www.mydomain1.com/")); - assertTrue(checkSameOrigin("mydomain1.com", -1, "https://mydomain1.com/path")); - assertTrue(checkSameOrigin("mydomain1.com", -1, "https://www.mydomain1.com/path")); - assertFalse(checkSameOrigin("mydomain2.com", -1, "https://mydomain1.com/")); - assertFalse(checkSameOrigin("mydomain2.com", -1, "https://www.mydomain1.com/")); - assertFalse(checkSameOrigin("mydomain2.com", -1, "https://mydomain1.com/path")); - assertFalse(checkSameOrigin("mydomain2.com", -1, "https://www.mydomain1.com/path")); + assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com/")); + assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com:80")); + assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com/path")); + assertTrue(checkSameOrigin("mydomain1.com", -1, "http://mydomain1.com:80/path")); + assertFalse(checkSameOrigin("mydomain2.com", -1, "http://mydomain1.com/")); + assertFalse(checkSameOrigin("mydomain2.com", -1, "http://mydomain1.com:80/")); + assertFalse(checkSameOrigin("mydomain2.com", -1, "http://mydomain1.com/path")); + assertFalse(checkSameOrigin("mydomain2.com", -1, "http://mydomain1.com:80/path")); // Handling of IPv6 hosts as described in SPR-13525 assertTrue(checkSameOrigin("[::1]", -1, "http://[::1]")); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/AppCacheManifestTransformerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/AppCacheManifestTransformerTests.java index c2e4dd63dc..04baaa743a 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/AppCacheManifestTransformerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/AppCacheManifestTransformerTests.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"); * you may not use this file except in compliance with the License. @@ -104,7 +104,7 @@ public class AppCacheManifestTransformerTests { assertThat("should not rewrite external resources", content, Matchers.containsString("//example.org/style.css")); 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, Matchers.containsString("# Hash: 4bf0338bcbeb0a5b3a4ec9ed8864107d")); diff --git a/spring-webmvc/src/test/resources/org/springframework/web/servlet/resource/test/appcache.manifest b/spring-webmvc/src/test/resources/org/springframework/web/servlet/resource/test/appcache.manifest index 986d1055a6..76e2f32a98 100644 --- a/spring-webmvc/src/test/resources/org/springframework/web/servlet/resource/test/appcache.manifest +++ b/spring-webmvc/src/test/resources/org/springframework/web/servlet/resource/test/appcache.manifest @@ -11,7 +11,7 @@ NETWORK: CACHE: js/bar.js -https://example.org/image.png +http://example.org/image.png FALLBACK: /main /static.html \ No newline at end of file