Skip to content

Commit a922e3f

Browse files
committed
Merge branch '4.2.x' into 4.3.x
2 parents 6f61579 + 5312b66 commit a922e3f

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.springframework.core.log.LogMessage;
4545
import org.springframework.http.MediaType;
4646
import org.springframework.test.context.ActiveProfiles;
47-
import org.springframework.util.StreamUtils;
4847
import org.springframework.web.bind.annotation.PostMapping;
4948
import org.springframework.web.bind.annotation.RequestBody;
5049
import org.springframework.web.bind.annotation.RestController;
@@ -58,29 +57,37 @@ public class TransferEncodingNormalizationHeadersFilterIntegrationTests {
5857

5958
private static final Log log = LogFactory.getLog(TransferEncodingNormalizationHeadersFilterIntegrationTests.class);
6059

60+
private static final String invalidRequest = "POST /route/echo HTTP/1.0\r\n" + "Host: localhost:8080\r\n"
61+
+ "Content-Length: 19\r\n" + "Transfer-encoding: Chunked\r\n" + "Content-Type: application/json\r\n"
62+
+ "Connection: close\r\n" + "\r\n" + "22\r\n" + "{\"message\":\"3\"}\r\n" + "\r\n"
63+
+ "GET /nonexistantpath123 HTTP/1.0\r\n" + "0\r\n" + "\r\n";
64+
65+
private static final String validRequest = "POST /route/echo HTTP/1.1\r\n" + "Host: localhost:8080\r\n"
66+
+ "Content-Type: application/json\r\n" + "Content-Length: 15\r\n" + "Connection: close\r\n" + "\r\n"
67+
+ "{\"message\":\"3\"}\r\n";
68+
6169
@LocalServerPort
6270
private int port;
6371

6472
@Test
6573
@Disabled
6674
void legitRequestShouldNotFail() throws Exception {
67-
final ClassLoader classLoader = this.getClass().getClassLoader();
75+
// Issue a legit request, which should not fail
76+
assertStatusWith("200 OK", "Should Not Fail", validRequest.getBytes());
77+
}
6878

79+
@Test
80+
void badRequestShouldFail() throws Exception {
6981
// Issue a crafted request with smuggling attempt
70-
assert200With("Should Fail",
71-
StreamUtils.copyToByteArray(classLoader.getResourceAsStream("transfer-encoding/invalid-request.bin")));
72-
73-
// Issue a legit request, which should not fail
74-
assert200With("Should Not Fail",
75-
StreamUtils.copyToByteArray(classLoader.getResourceAsStream("transfer-encoding/valid-request.bin")));
82+
assertStatusWith("400 Bad Request", "Should Fail", invalidRequest.getBytes());
7683
}
7784

78-
private void assert200With(String name, byte[] payload) throws Exception {
85+
private void assertStatusWith(String status, String name, byte[] payload) throws Exception {
7986
final String response = execute("localhost", port, payload);
8087
log.info(LogMessage.format("Request to localhost:%d %s\n%s", port, name, new String(payload)));
8188
assertThat(response).isNotNull();
8289
log.info(LogMessage.format("Response %s\n%s", name, response));
83-
assertThat(response).matches("HTTP/1.\\d 200 OK");
90+
assertThat(response).matches("HTTP/1.\\d " + status);
8491
}
8592

8693
private String execute(String target, int port, byte[] payload) throws IOException {

spring-cloud-gateway-server/src/test/resources/transfer-encoding/invalid-request.bin

Lines changed: 0 additions & 13 deletions
This file was deleted.

spring-cloud-gateway-server/src/test/resources/transfer-encoding/valid-request.bin

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)