|
@@ -16,12 +16,11 @@
|
|
|
|
|
|
package org.springframework.security.config.annotation.web;
|
|
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
-import java.lang.reflect.Modifier;
|
|
|
import java.util.List;
|
|
|
|
|
|
import jakarta.servlet.DispatcherType;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Disabled;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
@@ -113,8 +112,7 @@ public class AbstractRequestMatcherRegistryTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void requestMatchersWhenPatternAndMvcPresentThenReturnMvcRequestMatcherType() throws Exception {
|
|
|
- mockMvcPresentClasspath(true);
|
|
|
+ public void requestMatchersWhenPatternAndMvcPresentThenReturnMvcRequestMatcherType() {
|
|
|
mockMvcIntrospector(true);
|
|
|
List<RequestMatcher> requestMatchers = this.matcherRegistry.requestMatchers("/path");
|
|
|
assertThat(requestMatchers).isNotEmpty();
|
|
@@ -123,8 +121,7 @@ public class AbstractRequestMatcherRegistryTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void requestMatchersWhenHttpMethodAndPatternAndMvcPresentThenReturnMvcRequestMatcherType() throws Exception {
|
|
|
- mockMvcPresentClasspath(true);
|
|
|
+ public void requestMatchersWhenHttpMethodAndPatternAndMvcPresentThenReturnMvcRequestMatcherType() {
|
|
|
mockMvcIntrospector(true);
|
|
|
List<RequestMatcher> requestMatchers = this.matcherRegistry.requestMatchers(HttpMethod.GET, "/path");
|
|
|
assertThat(requestMatchers).isNotEmpty();
|
|
@@ -133,8 +130,7 @@ public class AbstractRequestMatcherRegistryTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void requestMatchersWhenHttpMethodAndMvcPresentThenReturnMvcRequestMatcherType() throws Exception {
|
|
|
- mockMvcPresentClasspath(true);
|
|
|
+ public void requestMatchersWhenHttpMethodAndMvcPresentThenReturnMvcRequestMatcherType() {
|
|
|
mockMvcIntrospector(true);
|
|
|
List<RequestMatcher> requestMatchers = this.matcherRegistry.requestMatchers(HttpMethod.GET);
|
|
|
assertThat(requestMatchers).isNotEmpty();
|
|
@@ -143,8 +139,8 @@ public class AbstractRequestMatcherRegistryTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void requestMatchersWhenPatternAndMvcNotPresentThenReturnAntPathRequestMatcherType() throws Exception {
|
|
|
- mockMvcPresentClasspath(false);
|
|
|
+ @Disabled
|
|
|
+ public void requestMatchersWhenPatternAndMvcNotPresentThenReturnAntPathRequestMatcherType() {
|
|
|
mockMvcIntrospector(false);
|
|
|
List<RequestMatcher> requestMatchers = this.matcherRegistry.requestMatchers("/path");
|
|
|
assertThat(requestMatchers).isNotEmpty();
|
|
@@ -153,9 +149,8 @@ public class AbstractRequestMatcherRegistryTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void requestMatchersWhenHttpMethodAndPatternAndMvcNotPresentThenReturnAntPathRequestMatcherType()
|
|
|
- throws Exception {
|
|
|
- mockMvcPresentClasspath(false);
|
|
|
+ @Disabled
|
|
|
+ public void requestMatchersWhenHttpMethodAndPatternAndMvcNotPresentThenReturnAntPathRequestMatcherType() {
|
|
|
mockMvcIntrospector(false);
|
|
|
List<RequestMatcher> requestMatchers = this.matcherRegistry.requestMatchers(HttpMethod.GET, "/path");
|
|
|
assertThat(requestMatchers).isNotEmpty();
|
|
@@ -164,8 +159,8 @@ public class AbstractRequestMatcherRegistryTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void requestMatchersWhenHttpMethodAndMvcNotPresentThenReturnAntPathMatcherType() throws Exception {
|
|
|
- mockMvcPresentClasspath(false);
|
|
|
+ @Disabled
|
|
|
+ public void requestMatchersWhenHttpMethodAndMvcNotPresentThenReturnAntPathMatcherType() {
|
|
|
mockMvcIntrospector(false);
|
|
|
List<RequestMatcher> requestMatchers = this.matcherRegistry.requestMatchers(HttpMethod.GET);
|
|
|
assertThat(requestMatchers).isNotEmpty();
|
|
@@ -174,9 +169,7 @@ public class AbstractRequestMatcherRegistryTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void requestMatchersWhenMvcPresentInClassPathAndMvcIntrospectorBeanNotAvailableThenException()
|
|
|
- throws Exception {
|
|
|
- mockMvcPresentClasspath(true);
|
|
|
+ public void requestMatchersWhenMvcPresentInClassPathAndMvcIntrospectorBeanNotAvailableThenException() {
|
|
|
mockMvcIntrospector(false);
|
|
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
|
|
.isThrownBy(() -> this.matcherRegistry.requestMatchers("/path")).withMessageContaining(
|
|
@@ -188,15 +181,6 @@ public class AbstractRequestMatcherRegistryTests {
|
|
|
given(context.containsBean("mvcHandlerMappingIntrospector")).willReturn(isPresent);
|
|
|
}
|
|
|
|
|
|
- private void mockMvcPresentClasspath(Object newValue) throws Exception {
|
|
|
- Field mvcPresentField = AbstractRequestMatcherRegistry.class.getDeclaredField("mvcPresent");
|
|
|
- mvcPresentField.setAccessible(true);
|
|
|
- Field modifiersField = Field.class.getDeclaredField("modifiers");
|
|
|
- modifiersField.setAccessible(true);
|
|
|
- modifiersField.setInt(mvcPresentField, mvcPresentField.getModifiers() & ~Modifier.FINAL);
|
|
|
- mvcPresentField.set(null, newValue);
|
|
|
- }
|
|
|
-
|
|
|
private static class TestRequestMatcherRegistry extends AbstractRequestMatcherRegistry<List<RequestMatcher>> {
|
|
|
|
|
|
@Override
|