(t *testing.T)
| 436 | } |
| 437 | |
| 438 | func TestBodyDump_DefaultConfig(t *testing.T) { |
| 439 | e := echo.New() |
| 440 | smallData := "test" |
| 441 | req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(smallData)) |
| 442 | rec := httptest.NewRecorder() |
| 443 | c := e.NewContext(req, rec) |
| 444 | |
| 445 | h := func(c *echo.Context) error { |
| 446 | body, _ := io.ReadAll(c.Request().Body) |
| 447 | return c.String(http.StatusOK, string(body)) |
| 448 | } |
| 449 | |
| 450 | requestBodyDumped := "" |
| 451 | // Use default config which should have 1MB limits |
| 452 | config := BodyDumpConfig{} |
| 453 | config.Handler = func(c *echo.Context, reqBody, resBody []byte, err error) { |
| 454 | requestBodyDumped = string(reqBody) |
| 455 | } |
| 456 | mw, err := config.ToMiddleware() |
| 457 | assert.NoError(t, err) |
| 458 | |
| 459 | err = mw(h)(c) |
| 460 | assert.NoError(t, err) |
| 461 | assert.Equal(t, smallData, requestBodyDumped) |
| 462 | } |
| 463 | |
| 464 | func TestBodyDump_LargeRequestDosPrevention(t *testing.T) { |
| 465 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…