Files
Agent-System/internal/server/body_limit_middleware_test.go
T
weichenandCursor d7a144de26 feat(taskrun): resume interrupted runs and harden P1 security gaps
Add confirm-gated resume API with resumable flag, Phase 5 finalize fault
and rolling-restart replay tests, Mermaid strict mode, request body limits,
and optional Runner Bearer auth between app and pi-agent.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 02:50:23 +00:00

30 lines
765 B
Go

package server
import (
"bytes"
"io"
"net/http"
"net/http/httptest"
"testing"
)
func TestBodyLimitMiddleware_RejectsOversizedBody(t *testing.T) {
srv := &Server{}
inner := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if _, err := io.ReadAll(r.Body); isRequestBodyTooLarge(err) {
w.WriteHeader(http.StatusRequestEntityTooLarge)
return
}
w.WriteHeader(http.StatusOK)
})
handler := srv.bodyLimitMiddleware(inner)
body := bytes.Repeat([]byte("x"), int(defaultJSONBodyLimit)+1024)
req := httptest.NewRequest(http.MethodPost, "/api/v1/chat", bytes.NewReader(body))
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusRequestEntityTooLarge {
t.Fatalf("expected 413, got %d", rec.Code)
}
}