浏览代码

Set the useTrailingSlashMatch to true for tests

The Spring MVC changed the default behavior for trailing slash match
with https://github.com/spring-projects/spring-framework/issues/28552.
This causes failures in Spring Security's tests.

Setting the `useTrailingSlashMatch` to `true` ensures that Spring
Security will work for users who have modified the default configuration.
Specifing the request mapper with trailing slash path ensures that the tests
are successful when default behavior is used.

Closes gh-11451
Igor Bolic 3 年之前
父节点
当前提交
d96b4a0463
共有 12 个文件被更改,包括 12 次插入6 次删除
  1. 1 0
      config/src/test/java/org/springframework/security/config/annotation/web/builders/WebSecurityTests.java
  2. 1 0
      config/src/test/java/org/springframework/security/config/annotation/web/configurers/AuthorizeRequestsTests.java
  3. 1 0
      config/src/test/java/org/springframework/security/config/annotation/web/configurers/HttpSecurityRequestMatchersTests.java
  4. 1 0
      config/src/test/java/org/springframework/security/config/annotation/web/configurers/UrlAuthorizationConfigurerTests.java
  5. 1 1
      config/src/test/java/org/springframework/security/htmlunit/server/WebTestClientHtmlUnitDriverBuilderTests.java
  6. 1 0
      config/src/test/kotlin/org/springframework/security/config/annotation/web/AuthorizeHttpRequestsDslTests.kt
  7. 1 0
      config/src/test/kotlin/org/springframework/security/config/annotation/web/AuthorizeRequestsDslTests.kt
  8. 1 1
      config/src/test/kotlin/org/springframework/security/config/web/server/ServerJwtDslTests.kt
  9. 1 1
      config/src/test/resources/org/springframework/security/config/http/InterceptUrlConfigTests-MvcMatchers.xml
  10. 1 1
      config/src/test/resources/org/springframework/security/config/http/InterceptUrlConfigTests-MvcMatchersServletPath.xml
  11. 1 1
      test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsAuthenticationStatelessTests.java
  12. 1 1
      test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsTestSecurityContextStatelessTests.java

+ 1 - 0
config/src/test/java/org/springframework/security/config/annotation/web/builders/WebSecurityTests.java

@@ -232,6 +232,7 @@ public class WebSecurityTests {
 		@Override
 		public void configurePathMatch(PathMatchConfigurer configurer) {
 			configurer.setUseSuffixPatternMatch(true);
+			configurer.setUseTrailingSlashMatch(true);
 		}
 
 	}

+ 1 - 0
config/src/test/java/org/springframework/security/config/annotation/web/configurers/AuthorizeRequestsTests.java

@@ -662,6 +662,7 @@ public class AuthorizeRequestsTests {
 		@Override
 		public void configurePathMatch(PathMatchConfigurer configurer) {
 			configurer.setUseSuffixPatternMatch(true);
+			configurer.setUseTrailingSlashMatch(true);
 		}
 
 	}

+ 1 - 0
config/src/test/java/org/springframework/security/config/annotation/web/configurers/HttpSecurityRequestMatchersTests.java

@@ -491,6 +491,7 @@ public class HttpSecurityRequestMatchersTests {
 		@Override
 		public void configurePathMatch(PathMatchConfigurer configurer) {
 			configurer.setUseSuffixPatternMatch(true);
+			configurer.setUseTrailingSlashMatch(true);
 		}
 
 	}

+ 1 - 0
config/src/test/java/org/springframework/security/config/annotation/web/configurers/UrlAuthorizationConfigurerTests.java

@@ -262,6 +262,7 @@ public class UrlAuthorizationConfigurerTests {
 		@Override
 		public void configurePathMatch(PathMatchConfigurer configurer) {
 			configurer.setUseSuffixPatternMatch(true);
+			configurer.setUseTrailingSlashMatch(true);
 		}
 
 	}

+ 1 - 1
config/src/test/java/org/springframework/security/htmlunit/server/WebTestClientHtmlUnitDriverBuilderTests.java

@@ -74,7 +74,7 @@ public class WebTestClientHtmlUnitDriverBuilderTests {
 	class HelloWorldController {
 
 		@ResponseBody
-		@GetMapping(produces = MediaType.TEXT_HTML_VALUE)
+		@GetMapping(path = "/", produces = MediaType.TEXT_HTML_VALUE)
 		String index() {
 			// @formatter:off
 			return "<html>\n"

+ 1 - 0
config/src/test/kotlin/org/springframework/security/config/annotation/web/AuthorizeHttpRequestsDslTests.kt

@@ -188,6 +188,7 @@ class AuthorizeHttpRequestsDslTests {
     open class LegacyMvcMatchingConfig : WebMvcConfigurer {
         override fun configurePathMatch(configurer: PathMatchConfigurer) {
             configurer.setUseSuffixPatternMatch(true)
+            configurer.setUseTrailingSlashMatch(true)
         }
     }
 

+ 1 - 0
config/src/test/kotlin/org/springframework/security/config/annotation/web/AuthorizeRequestsDslTests.kt

@@ -178,6 +178,7 @@ class AuthorizeRequestsDslTests {
     open class LegacyMvcMatchingConfig : WebMvcConfigurer {
         override fun configurePathMatch(configurer: PathMatchConfigurer) {
             configurer.setUseSuffixPatternMatch(true)
+            configurer.setUseTrailingSlashMatch(true)
         }
     }
 

+ 1 - 1
config/src/test/kotlin/org/springframework/security/config/web/server/ServerJwtDslTests.kt

@@ -278,7 +278,7 @@ class ServerJwtDslTests {
 
     @RestController
     internal class BaseController {
-        @GetMapping
+        @GetMapping("/")
         fun index() {
         }
     }

+ 1 - 1
config/src/test/resources/org/springframework/security/config/http/InterceptUrlConfigTests-MvcMatchers.xml

@@ -33,7 +33,7 @@
 	</http>
 
 	<mvc:annotation-driven>
-		<mvc:path-matching suffix-pattern="true"/>
+		<mvc:path-matching suffix-pattern="true" trailing-slash="true"/>
 	</mvc:annotation-driven>
 
 	<b:bean name="path" class="org.springframework.security.config.http.InterceptUrlConfigTests.PathController"/>

+ 1 - 1
config/src/test/resources/org/springframework/security/config/http/InterceptUrlConfigTests-MvcMatchersServletPath.xml

@@ -33,7 +33,7 @@
 	</http>
 
 	<mvc:annotation-driven>
-		<mvc:path-matching suffix-pattern="true"/>
+		<mvc:path-matching suffix-pattern="true" trailing-slash="true"/>
 	</mvc:annotation-driven>
 
 	<b:bean name="path" class="org.springframework.security.config.http.InterceptUrlConfigTests.PathController"/>

+ 1 - 1
test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsAuthenticationStatelessTests.java

@@ -95,7 +95,7 @@ public class SecurityMockMvcRequestPostProcessorsAuthenticationStatelessTests {
 		@RestController
 		static class Controller {
 
-			@RequestMapping
+			@RequestMapping("/")
 			String hello() {
 				return "Hello";
 			}

+ 1 - 1
test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsTestSecurityContextStatelessTests.java

@@ -89,7 +89,7 @@ public class SecurityMockMvcRequestPostProcessorsTestSecurityContextStatelessTes
 		@RestController
 		static class Controller {
 
-			@RequestMapping
+			@RequestMapping("/")
 			String hello() {
 				return "Hello";
 			}