Skip to content

Commit 06276c9

Browse files
committed
Merge branch '4.3.x'
2 parents 947950e + a922e3f commit 06276c9

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

spring-cloud-gateway-server-webflux/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilterIntegrationTests.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public class TransferEncodingNormalizationHeadersFilterIntegrationTests {
5858

5959
private static final Log log = LogFactory.getLog(TransferEncodingNormalizationHeadersFilterIntegrationTests.class);
6060

61-
private static final String validRequest = "POST /route/echo HTTP/1.1\r\n" + "Host: localhost:8080\r\n"
62-
+ "Content-Type: application/json\r\n" + "Content-Length: 15\r\n" + "Connection: close\r\n" + "\r\n"
63-
+ "{\"message\":\"3\"}";
64-
6561
private static final String invalidRequest = "POST /route/echo HTTP/1.0\r\n" + "Host: localhost:8080\r\n"
6662
+ "Content-Length: 19\r\n" + "Transfer-encoding: Chunked\r\n" + "Content-Type: application/json\r\n"
6763
+ "Connection: close\r\n" + "\r\n" + "22\r\n" + "{\"message\":\"3\"}\r\n" + "\r\n"
6864
+ "GET /nonexistantpath123 HTTP/1.0\r\n" + "0\r\n" + "\r\n";
6965

66+
private static final String validRequest = "POST /route/echo HTTP/1.1\r\n" + "Host: localhost:8080\r\n"
67+
+ "Content-Type: application/json\r\n" + "Content-Length: 15\r\n" + "Connection: close\r\n" + "\r\n"
68+
+ "{\"message\":\"3\"}\r\n";
69+
7070
@LocalServerPort
7171
private int port;
7272

@@ -79,15 +79,18 @@ void invalidRequestShouldFail() throws Exception {
7979
@Test
8080
void legitRequestShouldNotFail() throws Exception {
8181
// Issue a legit request, which should not fail
82-
assertStatus("Should Not Fail", validRequest, "200 OK");
82+
assertStatusWith("200 OK", "Should Not Fail", validRequest.getBytes());
8383
}
8484

85-
private void assertStatus(String name, String payloadString, String status) throws Exception {
86-
// String payloadString = new String(payload);
87-
payloadString = payloadString.replace("8080", "" + port);
85+
@Test
86+
void badRequestShouldFail() throws Exception {
87+
// Issue a crafted request with smuggling attempt
88+
assertStatusWith("400 Bad Request", "Should Fail", invalidRequest.getBytes());
89+
}
8890

89-
log.info(LogMessage.format("Request to localhost:%d %s\n%s", port, name, payloadString));
90-
final String response = execute("localhost", port, payloadString);
91+
private void assertStatusWith(String status, String name, byte[] payload) throws Exception {
92+
final String response = execute("localhost", port, payload);
93+
log.info(LogMessage.format("Request to localhost:%d %s\n%s", port, name, new String(payload)));
9194
assertThat(response).isNotNull();
9295
log.info(LogMessage.format("Response %s\n%s", name, response));
9396
assertThat(response).matches("HTTP/1.\\d " + status);

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ public void clientResponseBodyAttributeWorks() {
10291029
@EnableAutoConfiguration
10301030
@LoadBalancerClient(name = "httpbin", configuration = TestLoadBalancerConfig.Httpbin.class)
10311031
@Import(PermitAllSecurityConfiguration.class)
1032-
protected static class TestConfiguration extends WebMvcConfigurationSupport {
1032+
protected static class TestConfiguration {
10331033

10341034
@Bean
10351035
StaticPortController staticPortController() {

spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcLoadBalancerIntegrationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import org.springframework.boot.test.web.server.LocalServerPort;
2525
import org.springframework.cloud.gateway.server.mvc.filter.FilterAutoConfiguration;
2626
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
27+
import org.springframework.cloud.gateway.server.mvc.test.PermitAllSecurityConfiguration;
2728
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
2829
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
30+
import org.springframework.context.annotation.Import;
2931
import org.springframework.test.context.ActiveProfiles;
3032
import org.springframework.test.context.ContextConfiguration;
3133
import org.springframework.test.web.servlet.client.RestTestClient;
@@ -55,6 +57,7 @@ void shouldUseLbHandlerFunctionDefinitionToResolveHost() {
5557

5658
@SpringBootApplication
5759
@LoadBalancerClient(name = "httpbin", configuration = TestLoadBalancerConfig.Httpbin.class)
60+
@Import(PermitAllSecurityConfiguration.class)
5861
static class Config {
5962

6063
}

0 commit comments

Comments
 (0)