From 69f75e56876f3424d2f707eb611dd1e4129ad15e Mon Sep 17 00:00:00 2001 From: spencergibb Date: Tue, 31 Jan 2023 15:58:23 -0500 Subject: [PATCH 1/3] Disable test on github actions --- .../ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java index 14c7aa70..85a13786 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java @@ -26,6 +26,7 @@ import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.util.internal.PlatformDependent; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; import org.junitpioneer.jupiter.RetryingTest; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; @@ -63,6 +64,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen "spring.main.allow-bean-definition-overriding=true" }) @DirtiesContext @ActiveProfiles("single-cert-ssl") +@DisabledIfEnvironmentVariable(named = "GITHUB_ACTION", matches = ".*") class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWebClientTests { @Autowired From 180a052c7622a99b9fb37cc34f17f4cc1628e73d Mon Sep 17 00:00:00 2001 From: spencergibb Date: Tue, 7 Feb 2023 12:11:35 -0500 Subject: [PATCH 2/3] Moves disabled if github actions to methods --- ...ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java index 85a13786..2cb27a89 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java @@ -64,7 +64,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen "spring.main.allow-bean-definition-overriding=true" }) @DirtiesContext @ActiveProfiles("single-cert-ssl") -@DisabledIfEnvironmentVariable(named = "GITHUB_ACTION", matches = ".*") class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWebClientTests { @Autowired @@ -73,6 +72,7 @@ class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWebClient @BeforeEach public void setup() { try { + System.err.println("in github = " + System.getenv("GITHUB_ACTIONS")); SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE) .build(); HttpClient httpClient = HttpClient.create().secure(ssl -> ssl.sslContext(sslContext)); @@ -84,6 +84,7 @@ class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWebClient } @Test + @DisabledIfEnvironmentVariable(named = "GITHUB_ACTIONS", matches = "true") void modifyRequestBodySSLTimeout() { testClient.post().uri("/post").header("Host", "www.modifyrequestbodyssltimeout.org") .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) @@ -92,6 +93,7 @@ class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWebClient .isEqualTo("handshake timed out after 1ms"); } + @DisabledIfEnvironmentVariable(named = "GITHUB_ACTIONS", matches = "true") @RetryingTest(3) void modifyRequestBodyRelease() { releaseCount.set(0); @@ -109,6 +111,7 @@ class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWebClient } @Test + @DisabledIfEnvironmentVariable(named = "GITHUB_ACTIONS", matches = "true") void modifyRequestBodyHappenedError() { testClient.post().uri("/post").header("Host", "www.modifyrequestbodyexception.org") .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) From a2ef4895a4eef32b180b7c1808b079486497d467 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Tue, 21 Feb 2023 11:18:31 -0500 Subject: [PATCH 3/3] Fixes for gateway routes on management port. Uses the LocalAddress to check against management port because request.getURI().getPort() can be set by the host header "myhost:8888", for example. Fixes gh-2870 --- .../gateway/handler/RoutePredicateHandlerMapping.java | 2 +- .../RoutePredicateHandlerMappingIntegrationTests.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java index 39b89197..54e8735c 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java @@ -77,7 +77,7 @@ public class RoutePredicateHandlerMapping extends AbstractHandlerMapping { protected Mono getHandlerInternal(ServerWebExchange exchange) { // don't handle requests on management port if set and different than server port if (this.managementPortType == DIFFERENT && this.managementPort != null - && exchange.getRequest().getURI().getPort() == this.managementPort) { + && exchange.getRequest().getLocalAddress().getPort() == this.managementPort) { return Mono.empty(); } exchange.getAttributes().put(GATEWAY_HANDLER_MAPPER_ATTR, getSimpleName()); diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java index ea3e3338..4e65cbc6 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java @@ -60,6 +60,13 @@ public class RoutePredicateHandlerMappingIntegrationTests extends BaseWebClientT .expectStatus().isNotFound(); } + @Test + public void requestsToManagementPortAndHostHeaderReturn404() { + String host = "example.com:8888"; + testClient.mutate().baseUrl("http://localhost:" + managementPort).build().get().uri("/get").header("host", host) + .exchange().expectStatus().isNotFound(); + } + @Test public void andNotWorksWithMissingParameter() { testClient.get().uri("/andnotquery").exchange().expectBody(String.class).isEqualTo("notsupplied");