|
26 | 26 | import org.apache.http.impl.client.HttpClients; |
27 | 27 | import org.apache.http.util.EntityUtils; |
28 | 28 | import org.bouncycastle.util.encoders.Hex; |
| 29 | +import org.eclipse.jetty.http.HttpStatus; |
29 | 30 | import org.junit.Assert; |
30 | 31 | import org.junit.Before; |
31 | 32 | import org.junit.Test; |
@@ -1572,8 +1573,7 @@ public void testWeb3ClientVersion() { |
1572 | 1573 | * Verifies SizeLimitHandler integration with the real JsonRpcServlet + jsonrpc4j stack. |
1573 | 1574 | * |
1574 | 1575 | * Covers: normal request no regression, Content-Length oversized 413, |
1575 | | - * and chunked oversized handled gracefully (body truncated, 200 + empty body |
1576 | | - * because jsonrpc4j absorbs the BadMessageException). |
| 1576 | + * and chunked oversized 413 during streaming body reads. |
1577 | 1577 | */ |
1578 | 1578 | @Test |
1579 | 1579 | public void testJsonRpcSizeLimitIntegration() { |
@@ -1609,22 +1609,20 @@ public void testJsonRpcSizeLimitIntegration() { |
1609 | 1609 | overPost.setEntity(new StringEntity( |
1610 | 1610 | new String(new char[(int) testLimit + 1]).replace('\0', 'x'))); |
1611 | 1611 | resp = httpClient.execute(overPost); |
1612 | | - Assert.assertEquals(413, resp.getStatusLine().getStatusCode()); |
| 1612 | + Assert.assertEquals(HttpStatus.PAYLOAD_TOO_LARGE_413, |
| 1613 | + resp.getStatusLine().getStatusCode()); |
1613 | 1614 | resp.close(); |
1614 | 1615 |
|
1615 | | - // Chunked oversized -> BadMessageException thrown during body read, |
1616 | | - // absorbed by jsonrpc4j catch(Exception) -> 200 with empty body. |
| 1616 | + // Chunked oversized -> BadMessageException thrown during body read. |
1617 | 1617 | // Body read IS truncated at the limit - OOM protection effective. |
1618 | 1618 | byte[] chunkedData = new String(new char[(int) testLimit * 2]) |
1619 | 1619 | .replace('\0', 'x').getBytes("UTF-8"); |
1620 | 1620 | HttpPost chunkedPost = new HttpPost(url); |
1621 | 1621 | chunkedPost.setEntity(new InputStreamEntity( |
1622 | 1622 | new ByteArrayInputStream(chunkedData), -1)); |
1623 | 1623 | resp = httpClient.execute(chunkedPost); |
1624 | | - Assert.assertEquals(200, resp.getStatusLine().getStatusCode()); |
1625 | | - body = EntityUtils.toString(resp.getEntity()); |
1626 | | - Assert.assertTrue("Chunked oversized should return empty body" |
1627 | | - + " (jsonrpc4j absorbs BadMessageException)", body.isEmpty()); |
| 1624 | + Assert.assertEquals(HttpStatus.PAYLOAD_TOO_LARGE_413, |
| 1625 | + resp.getStatusLine().getStatusCode()); |
1628 | 1626 | resp.close(); |
1629 | 1627 | } |
1630 | 1628 | } catch (Exception e) { |
|
0 commit comments