Skip to content

Commit d96b4a0

Browse files
igorbolicjzheaux
authored andcommitted
Set the useTrailingSlashMatch to true for tests
The Spring MVC changed the default behavior for trailing slash match with spring-projects/spring-framework#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
1 parent 6510274 commit d96b4a0

File tree

12 files changed

+12
-6
lines changed

12 files changed

+12
-6
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/builders/WebSecurityTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static class LegacyMvcMatchingConfig implements WebMvcConfigurer {
232232
@Override
233233
public void configurePathMatch(PathMatchConfigurer configurer) {
234234
configurer.setUseSuffixPatternMatch(true);
235+
configurer.setUseTrailingSlashMatch(true);
235236
}
236237

237238
}

config/src/test/java/org/springframework/security/config/annotation/web/configurers/AuthorizeRequestsTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ static class LegacyMvcMatchingConfig implements WebMvcConfigurer {
662662
@Override
663663
public void configurePathMatch(PathMatchConfigurer configurer) {
664664
configurer.setUseSuffixPatternMatch(true);
665+
configurer.setUseTrailingSlashMatch(true);
665666
}
666667

667668
}

config/src/test/java/org/springframework/security/config/annotation/web/configurers/HttpSecurityRequestMatchersTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ static class LegacyMvcMatchingConfig implements WebMvcConfigurer {
491491
@Override
492492
public void configurePathMatch(PathMatchConfigurer configurer) {
493493
configurer.setUseSuffixPatternMatch(true);
494+
configurer.setUseTrailingSlashMatch(true);
494495
}
495496

496497
}

config/src/test/java/org/springframework/security/config/annotation/web/configurers/UrlAuthorizationConfigurerTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static class LegacyMvcMatchingConfig implements WebMvcConfigurer {
262262
@Override
263263
public void configurePathMatch(PathMatchConfigurer configurer) {
264264
configurer.setUseSuffixPatternMatch(true);
265+
configurer.setUseTrailingSlashMatch(true);
265266
}
266267

267268
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void cookies() {
7474
class HelloWorldController {
7575

7676
@ResponseBody
77-
@GetMapping(produces = MediaType.TEXT_HTML_VALUE)
77+
@GetMapping(path = "/", produces = MediaType.TEXT_HTML_VALUE)
7878
String index() {
7979
// @formatter:off
8080
return "<html>\n"

config/src/test/kotlin/org/springframework/security/config/annotation/web/AuthorizeHttpRequestsDslTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class AuthorizeHttpRequestsDslTests {
188188
open class LegacyMvcMatchingConfig : WebMvcConfigurer {
189189
override fun configurePathMatch(configurer: PathMatchConfigurer) {
190190
configurer.setUseSuffixPatternMatch(true)
191+
configurer.setUseTrailingSlashMatch(true)
191192
}
192193
}
193194

config/src/test/kotlin/org/springframework/security/config/annotation/web/AuthorizeRequestsDslTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class AuthorizeRequestsDslTests {
178178
open class LegacyMvcMatchingConfig : WebMvcConfigurer {
179179
override fun configurePathMatch(configurer: PathMatchConfigurer) {
180180
configurer.setUseSuffixPatternMatch(true)
181+
configurer.setUseTrailingSlashMatch(true)
181182
}
182183
}
183184

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class ServerJwtDslTests {
278278

279279
@RestController
280280
internal class BaseController {
281-
@GetMapping
281+
@GetMapping("/")
282282
fun index() {
283283
}
284284
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</http>
3434

3535
<mvc:annotation-driven>
36-
<mvc:path-matching suffix-pattern="true"/>
36+
<mvc:path-matching suffix-pattern="true" trailing-slash="true"/>
3737
</mvc:annotation-driven>
3838

3939
<b:bean name="path" class="org.springframework.security.config.http.InterceptUrlConfigTests.PathController"/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</http>
3434

3535
<mvc:annotation-driven>
36-
<mvc:path-matching suffix-pattern="true"/>
36+
<mvc:path-matching suffix-pattern="true" trailing-slash="true"/>
3737
</mvc:annotation-driven>
3838

3939
<b:bean name="path" class="org.springframework.security.config.http.InterceptUrlConfigTests.PathController"/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
9595
@RestController
9696
static class Controller {
9797

98-
@RequestMapping
98+
@RequestMapping("/")
9999
String hello() {
100100
return "Hello";
101101
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
8989
@RestController
9090
static class Controller {
9191

92-
@RequestMapping
92+
@RequestMapping("/")
9393
String hello() {
9494
return "Hello";
9595
}

0 commit comments

Comments
 (0)