use of org.springframework.web.server.WebFilter in project spring-framework by spring-projects.
the class WebFilterTests method testWebFilter.
@Test
public void testWebFilter() throws Exception {
WebFilter filter = (exchange, chain) -> {
DataBuffer buffer = DefaultDataBufferFactory.sharedInstance.allocateBuffer();
buffer.write("It works!".getBytes(StandardCharsets.UTF_8));
return exchange.getResponse().writeWith(Mono.just(buffer));
};
WebTestClient client = WebTestClient.bindToWebHandler(exchange -> Mono.empty()).webFilter(filter).build();
client.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("It works!");
}
use of org.springframework.web.server.WebFilter in project spring-security by spring-projects.
the class ReactorContextWebFilterTests method filterWhenMainContextThenDoesNotOverride.
@Test
public // gh-4962
void filterWhenMainContextThenDoesNotOverride() {
given(this.repository.load(any())).willReturn(this.securityContext.mono());
String contextKey = "main";
WebFilter mainContextWebFilter = (e, c) -> c.filter(e).subscriberContext(Context.of(contextKey, true));
WebFilterChain chain = new DefaultWebFilterChain((e) -> Mono.empty(), List.of(mainContextWebFilter, this.filter));
Mono<Void> filter = chain.filter(MockServerWebExchange.from(this.exchange.build()));
StepVerifier.create(filter).expectAccessibleContext().hasKey(contextKey).then().verifyComplete();
}
use of org.springframework.web.server.WebFilter in project spring-security by spring-projects.
the class WebFilterChainProxyTests method filterWhenNoMatchThenContinuesChainAnd404.
// gh-4668
@Test
public void filterWhenNoMatchThenContinuesChainAnd404() {
List<WebFilter> filters = Arrays.asList(new Http200WebFilter());
ServerWebExchangeMatcher notMatch = (exchange) -> MatchResult.notMatch();
MatcherSecurityWebFilterChain chain = new MatcherSecurityWebFilterChain(notMatch, filters);
WebFilterChainProxy filter = new WebFilterChainProxy(chain);
WebTestClient.bindToController(new Object()).webFilter(filter).build().get().exchange().expectStatus().isNotFound();
}
Aggregations