MCPcopy
hub / github.com/labstack/echo / TestDecompress_MultipleReads

Function TestDecompress_MultipleReads

middleware/decompress_test.go:420–455  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

418}
419
420func 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
457func TestDecompress_LargePayloadDosPrevention(t *testing.T) {
458 e := echo.New()

Callers

nothing calls this directly

Calls 8

RequestMethod · 0.95
gzipStringFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
ToMiddlewareMethod · 0.65
StatusCodeMethod · 0.65
ReadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…