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

Function TestDecompress_AtExactLimit

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

Source from the content-addressed store, hash-verified

299}
300
301func TestDecompress_AtExactLimit(t *testing.T) {
302 e := echo.New()
303 exactBody := strings.Repeat("B", 1024) // Exactly 1KB
304 gz, _ := gzipString(exactBody)
305
306 req := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(gz))
307 req.Header.Set(echo.HeaderContentEncoding, GZIPEncoding)
308 rec := httptest.NewRecorder()
309 c := e.NewContext(req, rec)
310
311 h, err := DecompressConfig{MaxDecompressedSize: 1024}.ToMiddleware()
312 assert.NoError(t, err)
313
314 err = h(func(c *echo.Context) error {
315 b, _ := io.ReadAll(c.Request().Body)
316 return c.String(http.StatusOK, string(b))
317 })(c)
318
319 assert.NoError(t, err)
320 assert.Equal(t, exactBody, rec.Body.String())
321}
322
323func TestDecompress_ZipBomb(t *testing.T) {
324 e := echo.New()

Callers

nothing calls this directly

Calls 6

RequestMethod · 0.95
StringMethod · 0.95
gzipStringFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
ToMiddlewareMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…