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 6d535f31..0592c7d1 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 @@ -19,10 +19,11 @@ package org.springframework.cloud.gateway.handler.predicate; 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; @@ -34,13 +35,15 @@ 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; 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 { @@ -93,7 +96,6 @@ public class PathRoutePredicateFactoryTests extends BaseWebClientTests { } @Test - @Disabled("until StrictServerWebExchangeFirewall is customizable") public void pathRouteWorksWithPercent() { testClient.get() .uri("/abc/123%/function") @@ -149,6 +151,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()