diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java index 4c5bf50e..cb92f046 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java @@ -22,7 +22,9 @@ 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; @@ -34,6 +36,8 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; 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; @@ -93,7 +97,7 @@ public class PathRoutePredicateFactoryTests extends BaseWebClientTests { } @Test - @Disabled + //@Disabled public void pathRouteWorksWithPercent() { testClient.get() .uri("/abc/123%/function") @@ -149,6 +153,22 @@ public class PathRoutePredicateFactoryTests extends BaseWebClientTests { @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()