forked from mtusi2026/mtusi2026lab7
на оценку 4
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDecodeJSONRejectsBodyAboveOneMiB(t *testing.T) {
|
||||
request := httptest.NewRequest(
|
||||
"POST",
|
||||
"/api/v1/users",
|
||||
strings.NewReader(strings.Repeat(" ", maxJSONBodyBytes+1)),
|
||||
)
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
|
||||
var destination map[string]any
|
||||
err := decodeJSON(request, &destination)
|
||||
if !errors.Is(err, errJSONBodyTooLarge) {
|
||||
t.Fatalf("expected errJSONBodyTooLarge, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user