(t *testing.T)
| 253 | } |
| 254 | |
| 255 | func TestBodyDump_RequestExceedsLimit(t *testing.T) { |
| 256 | e := echo.New() |
| 257 | // Create 2KB of data but limit to 1KB |
| 258 | largeData := strings.Repeat("A", 2*1024) |
| 259 | req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(largeData)) |
| 260 | rec := httptest.NewRecorder() |
| 261 | c := e.NewContext(req, rec) |
| 262 | |
| 263 | h := func(c *echo.Context) error { |
| 264 | body, _ := io.ReadAll(c.Request().Body) |
| 265 | return c.String(http.StatusOK, string(body)) |
| 266 | } |
| 267 | |
| 268 | requestBodyDumped := "" |
| 269 | limit := int64(1024) // 1KB limit |
| 270 | mw, err := BodyDumpConfig{ |
| 271 | Handler: func(c *echo.Context, reqBody, resBody []byte, err error) { |
| 272 | requestBodyDumped = string(reqBody) |
| 273 | }, |
| 274 | MaxRequestBytes: limit, |
| 275 | MaxResponseBytes: 1 * MB, |
| 276 | }.ToMiddleware() |
| 277 | assert.NoError(t, err) |
| 278 | |
| 279 | err = mw(h)(c) |
| 280 | assert.NoError(t, err) |
| 281 | assert.Equal(t, int(limit), len(requestBodyDumped), "Dumped request should be truncated to limit") |
| 282 | assert.Equal(t, strings.Repeat("A", 1024), requestBodyDumped, "Dumped data should match first N bytes") |
| 283 | // Handler should receive truncated data (what was dumped) |
| 284 | assert.Equal(t, strings.Repeat("A", 1024), rec.Body.String()) |
| 285 | } |
| 286 | |
| 287 | func TestBodyDump_RequestAtExactLimit(t *testing.T) { |
| 288 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…