Skip to content

Commit

Permalink
Enables pathRouteWorksWithPercent.
Browse files Browse the repository at this point in the history
Webflux now has a firewall that prevents uris with % percent in them. No enable it, one must customize the StrictServerWebExchangeFirewall
  • Loading branch information
spencergibb committed Oct 23, 2024
1 parent 605ff55 commit 8187ce3
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import java.util.Arrays;
import java.util.function.Predicate;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -34,13 +35,15 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpHeaders;
import org.springframework.security.web.server.WebFilterChainProxy;
import org.springframework.security.web.server.firewall.StrictServerWebExchangeFirewall;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.web.server.ServerWebExchange;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

@SpringBootTest(webEnvironment = RANDOM_PORT)
@SpringBootTest(webEnvironment = RANDOM_PORT, properties = "debug=true")
@DirtiesContext
public class PathRoutePredicateFactoryTests extends BaseWebClientTests {

Expand Down Expand Up @@ -93,7 +96,6 @@ public void mulitPathDslRouteWorks() {
}

@Test
@Disabled("until StrictServerWebExchangeFirewall is customizable")
public void pathRouteWorksWithPercent() {
testClient.get()
.uri("/abc/123%/function")
Expand Down Expand Up @@ -149,6 +151,22 @@ public static class TestConfig {
@Value("${test.uri}")
String uri;

// TODO: move to bean of StrictServerWebExchangeFirewall
@Bean
public BeanPostProcessor firewallPostProcessor() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof WebFilterChainProxy webFilterChainProxy) {
StrictServerWebExchangeFirewall firewall = new StrictServerWebExchangeFirewall();
firewall.setAllowUrlEncodedPercent(true);
webFilterChainProxy.setFirewall(firewall);
}
return bean;
}
};
}

@Bean
public RouteLocator testRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
Expand Down

0 comments on commit 8187ce3

Please sign in to comment.