(t *testing.T)
| 418 | } |
| 419 | |
| 420 | func TestDecompress_MultipleReads(t *testing.T) { |
| 421 | e := echo.New() |
| 422 | // Test that limit is enforced across multiple Read() calls |
| 423 | largeBody := strings.Repeat("M", 2*1024) // 2KB |
| 424 | gz, _ := gzipString(largeBody) |
| 425 | |
| 426 | req := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(gz)) |
| 427 | req.Header.Set(echo.HeaderContentEncoding, GZIPEncoding) |
| 428 | rec := httptest.NewRecorder() |
| 429 | c := e.NewContext(req, rec) |
| 430 | |
| 431 | h, err := DecompressConfig{MaxDecompressedSize: 1024}.ToMiddleware() // 1KB limit |
| 432 | assert.NoError(t, err) |
| 433 | |
| 434 | err = h(func(c *echo.Context) error { |
| 435 | // Read in small chunks |
| 436 | buf := make([]byte, 256) |
| 437 | total := 0 |
| 438 | for { |
| 439 | n, readErr := c.Request().Body.Read(buf) |
| 440 | total += n |
| 441 | if readErr != nil { |
| 442 | if readErr == io.EOF { |
| 443 | return nil |
| 444 | } |
| 445 | return readErr |
| 446 | } |
| 447 | } |
| 448 | })(c) |
| 449 | |
| 450 | // Should return 413 error from cumulative reads |
| 451 | assert.Error(t, err) |
| 452 | he, ok := err.(echo.HTTPStatusCoder) |
| 453 | assert.True(t, ok) |
| 454 | assert.Equal(t, http.StatusRequestEntityTooLarge, he.StatusCode()) |
| 455 | } |
| 456 | |
| 457 | func TestDecompress_LargePayloadDosPrevention(t *testing.T) { |
| 458 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…