From 49557471a9977aa50af57f8e3a80922663f5bf09 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 12 Apr 2019 11:03:43 +0200 Subject: [PATCH 1/3] Upgrade to AspectJ 1.9.3, Mockito 2.27, OpenPDF 1.2.16, POI 4.1 --- build.gradle | 4 ++-- spring-webmvc/spring-webmvc.gradle | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index b76dc3b179..5f043e1e57 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ ext { !it.name.equals("spring-build-src") && !it.name.equals("spring-framework-bom") } - aspectjVersion = "1.9.2" + aspectjVersion = "1.9.3" freemarkerVersion = "2.3.28" groovyVersion = "2.5.6" hsqldbVersion = "2.4.1" @@ -157,7 +157,7 @@ configure(allprojects) { project -> testCompile("junit:junit:4.12") { exclude group: "org.hamcrest", module: "hamcrest-core" } - testCompile("org.mockito:mockito-core:2.26.0") { + testCompile("org.mockito:mockito-core:2.27.0") { exclude group: "org.hamcrest", module: "hamcrest-core" } testCompile("com.nhaarman:mockito-kotlin:1.6.0") { diff --git a/spring-webmvc/spring-webmvc.gradle b/spring-webmvc/spring-webmvc.gradle index 29e1180be2..1c0df13778 100644 --- a/spring-webmvc/spring-webmvc.gradle +++ b/spring-webmvc/spring-webmvc.gradle @@ -23,8 +23,8 @@ dependencies { optional("javax.xml.bind:jaxb-api:2.3.1") optional("org.webjars:webjars-locator-core:0.37") optional("com.rometools:rome:1.12.0") - optional("com.github.librepdf:openpdf:1.2.12") - optional("org.apache.poi:poi-ooxml:4.0.1") + optional("com.github.librepdf:openpdf:1.2.16") + optional("org.apache.poi:poi-ooxml:4.1.0") optional("org.freemarker:freemarker:${freemarkerVersion}") optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}") optional("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${jackson2Version}") From b07d46da99431167b7f0b5ee4b61d1483dbf2d95 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 12 Apr 2019 11:10:02 +0200 Subject: [PATCH 2/3] MockCookie compares attributes in case-insensitive manner Closes gh-22786 --- .../springframework/mock/web/MockCookie.java | 18 +++++++------ .../mock/web/MockCookieTests.java | 27 ++++++++++++++----- .../mock/web/test/MockCookie.java | 18 +++++++------ 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockCookie.java b/spring-test/src/main/java/org/springframework/mock/web/MockCookie.java index 197004da61..522a60038c 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockCookie.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockCookie.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"); * you may not use this file except in compliance with the License. @@ -20,12 +20,14 @@ import javax.servlet.http.Cookie; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * Extension of {@code Cookie} with extra attributes, as defined in * RFC 6265. * * @author Vedran Pavic + * @author Juergen Hoeller * @since 5.1 */ public class MockCookie extends Cookie { @@ -39,7 +41,7 @@ public class MockCookie extends Cookie { /** * Constructor with the cookie name and value. - * @param name the name + * @param name the name * @param value the value * @see Cookie#Cookie(String, String) */ @@ -86,22 +88,22 @@ public class MockCookie extends Cookie { MockCookie cookie = new MockCookie(name, value); for (String attribute : attributes) { - if (attribute.startsWith("Domain")) { + if (StringUtils.startsWithIgnoreCase(attribute, "Domain")) { cookie.setDomain(extractAttributeValue(attribute, setCookieHeader)); } - else if (attribute.startsWith("Max-Age")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "Max-Age")) { cookie.setMaxAge(Integer.parseInt(extractAttributeValue(attribute, setCookieHeader))); } - else if (attribute.startsWith("Path")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "Path")) { cookie.setPath(extractAttributeValue(attribute, setCookieHeader)); } - else if (attribute.startsWith("Secure")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "Secure")) { cookie.setSecure(true); } - else if (attribute.startsWith("HttpOnly")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "HttpOnly")) { cookie.setHttpOnly(true); } - else if (attribute.startsWith("SameSite")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "SameSite")) { cookie.setSameSite(extractAttributeValue(attribute, setCookieHeader)); } } diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java index f5ca99ab44..3180369f0a 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.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"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ public class MockCookieTests { @Rule public final ExpectedException exception = ExpectedException.none(); + @Test public void constructCookie() { MockCookie cookie = new MockCookie("SESSION", "123"); @@ -57,9 +58,7 @@ public class MockCookieTests { @Test public void parseHeaderWithoutAttributes() { - MockCookie cookie; - - cookie = MockCookie.parse("SESSION=123"); + MockCookie cookie = MockCookie.parse("SESSION=123"); assertCookie(cookie, "SESSION", "123"); cookie = MockCookie.parse("SESSION=123;"); @@ -80,6 +79,11 @@ public class MockCookieTests { assertEquals("Lax", cookie.getSameSite()); } + private void assertCookie(MockCookie cookie, String name, String value) { + assertEquals(name, cookie.getName()); + assertEquals(value, cookie.getValue()); + } + @Test public void parseNullHeader() { exception.expect(IllegalArgumentException.class); @@ -103,9 +107,18 @@ public class MockCookieTests { MockCookie.parse(header); } - private void assertCookie(MockCookie cookie, String name, String value) { - assertEquals(name, cookie.getName()); - assertEquals(value, cookie.getValue()); + @Test + public void parseHeaderWithAttributesCaseSensitivity() { + MockCookie cookie = MockCookie.parse( + "SESSION=123; domain=example.com; max-age=60; path=/; secure; httponly; samesite=Lax"); + + assertCookie(cookie, "SESSION", "123"); + assertEquals("example.com", cookie.getDomain()); + assertEquals(60, cookie.getMaxAge()); + assertEquals("/", cookie.getPath()); + assertTrue(cookie.getSecure()); + assertTrue(cookie.isHttpOnly()); + assertEquals("Lax", cookie.getSameSite()); } } diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.java index 3bf3c062a1..b7ac261942 100644 --- a/spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.java +++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.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"); * you may not use this file except in compliance with the License. @@ -20,12 +20,14 @@ import javax.servlet.http.Cookie; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * Extension of {@code Cookie} with extra attributes, as defined in * RFC 6265. * * @author Vedran Pavic + * @author Juergen Hoeller * @since 5.1 */ public class MockCookie extends Cookie { @@ -39,7 +41,7 @@ public class MockCookie extends Cookie { /** * Constructor with the cookie name and value. - * @param name the name + * @param name the name * @param value the value * @see Cookie#Cookie(String, String) */ @@ -86,22 +88,22 @@ public class MockCookie extends Cookie { MockCookie cookie = new MockCookie(name, value); for (String attribute : attributes) { - if (attribute.startsWith("Domain")) { + if (StringUtils.startsWithIgnoreCase(attribute, "Domain")) { cookie.setDomain(extractAttributeValue(attribute, setCookieHeader)); } - else if (attribute.startsWith("Max-Age")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "Max-Age")) { cookie.setMaxAge(Integer.parseInt(extractAttributeValue(attribute, setCookieHeader))); } - else if (attribute.startsWith("Path")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "Path")) { cookie.setPath(extractAttributeValue(attribute, setCookieHeader)); } - else if (attribute.startsWith("Secure")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "Secure")) { cookie.setSecure(true); } - else if (attribute.startsWith("HttpOnly")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "HttpOnly")) { cookie.setHttpOnly(true); } - else if (attribute.startsWith("SameSite")) { + else if (StringUtils.startsWithIgnoreCase(attribute, "SameSite")) { cookie.setSameSite(extractAttributeValue(attribute, setCookieHeader)); } } From 722cd179cfb1eb91957c05b3baa932e711f92a97 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 12 Apr 2019 11:10:11 +0200 Subject: [PATCH 3/3] Clean up property values registration in SimpleWebApplicationContext Closes gh-22787 --- .../web/servlet/SimpleWebApplicationContext.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java index f5d7f3f751..20344b47c0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.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. @@ -47,10 +47,6 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext { @Override public void refresh() throws BeansException { - MutablePropertyValues pvs = new MutablePropertyValues(); - pvs.add("commandClass", "org.springframework.tests.sample.beans.TestBean"); - pvs.add("formView", "form"); - registerSingleton("/locale.do", LocaleChecker.class); addMessage("test", Locale.ENGLISH, "test message"); @@ -63,7 +59,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext { registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class); registerSingleton("viewResolver", InternalResourceViewResolver.class); - pvs = new MutablePropertyValues(); + MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("location", "org/springframework/web/context/WEB-INF/sessionContext.xml"); registerSingleton("viewResolver2", XmlViewResolver.class, pvs); @@ -76,6 +72,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext { @Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + if (!(RequestContextUtils.findWebApplicationContext(request) instanceof SimpleWebApplicationContext)) { throw new ServletException("Incorrect WebApplicationContext"); }