mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-04 09:42:29 +00:00
Add Filter Chain Validation Test
Issue gh-15982
This commit is contained in:
parent
624a8fb252
commit
9ae432f0d2
@ -33,6 +33,8 @@ import org.springframework.security.web.access.intercept.FilterSecurityIntercept
|
|||||||
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
|
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
|
||||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
|
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
|
||||||
|
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||||
|
import org.springframework.security.web.util.matcher.RequestMatchers;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.assertj.core.api.Assertions.assertThatNoException;
|
import static org.assertj.core.api.Assertions.assertThatNoException;
|
||||||
@ -95,4 +97,23 @@ public class WebSecurityFilterChainValidatorTests {
|
|||||||
.isThrownBy(() -> this.validator.validate(proxy));
|
.isThrownBy(() -> this.validator.validate(proxy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validateWhenSameComposedRequestMatchersArePresentThenUnreachableFilterChainException() {
|
||||||
|
RequestMatcher matcher1 = RequestMatchers.anyOf(RequestMatchers.allOf(AntPathRequestMatcher.antMatcher("/api"),
|
||||||
|
AntPathRequestMatcher.antMatcher("*.do")), AntPathRequestMatcher.antMatcher("/admin"));
|
||||||
|
RequestMatcher matcher2 = RequestMatchers.anyOf(RequestMatchers.allOf(AntPathRequestMatcher.antMatcher("/api"),
|
||||||
|
AntPathRequestMatcher.antMatcher("*.do")), AntPathRequestMatcher.antMatcher("/admin"));
|
||||||
|
SecurityFilterChain chain1 = new DefaultSecurityFilterChain(matcher1, this.authenticationFilter,
|
||||||
|
this.exceptionTranslationFilter, this.authorizationInterceptor);
|
||||||
|
SecurityFilterChain chain2 = new DefaultSecurityFilterChain(matcher2, this.authenticationFilter,
|
||||||
|
this.exceptionTranslationFilter, this.authorizationInterceptor);
|
||||||
|
List<SecurityFilterChain> chains = new ArrayList<>();
|
||||||
|
chains.add(chain2);
|
||||||
|
chains.add(chain1);
|
||||||
|
FilterChainProxy proxy = new FilterChainProxy(chains);
|
||||||
|
|
||||||
|
assertThatExceptionOfType(UnreachableFilterChainException.class)
|
||||||
|
.isThrownBy(() -> this.validator.validate(proxy));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user