Skip to content

Commit 9ae432f

Browse files
committed
Add Filter Chain Validation Test
Issue gh-15982
1 parent 624a8fb commit 9ae432f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

+21
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
3434
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
3535
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
36+
import org.springframework.security.web.util.matcher.RequestMatcher;
37+
import org.springframework.security.web.util.matcher.RequestMatchers;
3638

3739
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3840
import static org.assertj.core.api.Assertions.assertThatNoException;
@@ -95,4 +97,23 @@ void validateWhenSameRequestMatchersArePresentThenUnreachableFilterChainExceptio
9597
.isThrownBy(() -> this.validator.validate(proxy));
9698
}
9799

100+
@Test
101+
void validateWhenSameComposedRequestMatchersArePresentThenUnreachableFilterChainException() {
102+
RequestMatcher matcher1 = RequestMatchers.anyOf(RequestMatchers.allOf(AntPathRequestMatcher.antMatcher("/api"),
103+
AntPathRequestMatcher.antMatcher("*.do")), AntPathRequestMatcher.antMatcher("/admin"));
104+
RequestMatcher matcher2 = RequestMatchers.anyOf(RequestMatchers.allOf(AntPathRequestMatcher.antMatcher("/api"),
105+
AntPathRequestMatcher.antMatcher("*.do")), AntPathRequestMatcher.antMatcher("/admin"));
106+
SecurityFilterChain chain1 = new DefaultSecurityFilterChain(matcher1, this.authenticationFilter,
107+
this.exceptionTranslationFilter, this.authorizationInterceptor);
108+
SecurityFilterChain chain2 = new DefaultSecurityFilterChain(matcher2, this.authenticationFilter,
109+
this.exceptionTranslationFilter, this.authorizationInterceptor);
110+
List<SecurityFilterChain> chains = new ArrayList<>();
111+
chains.add(chain2);
112+
chains.add(chain1);
113+
FilterChainProxy proxy = new FilterChainProxy(chains);
114+
115+
assertThatExceptionOfType(UnreachableFilterChainException.class)
116+
.isThrownBy(() -> this.validator.validate(proxy));
117+
}
118+
98119
}

0 commit comments

Comments
 (0)