feat: refine operations UI and transport limits
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package inbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPostAcceptsAPIResponseLargerThanLegacy64KiB(t *testing.T) {
|
||||
payload := strings.Repeat("x", 128*1024)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"payload": payload})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
var result struct {
|
||||
Payload string `json:"payload"`
|
||||
}
|
||||
if err := (Server{APIBaseURL: server.URL}).post(context.Background(), "/large", map[string]string{"request": "ok"}, &result); err != nil {
|
||||
t.Fatalf("post response larger than 64KiB: %v", err)
|
||||
}
|
||||
if result.Payload != payload {
|
||||
t.Fatalf("payload length = %d, want %d", len(result.Payload), len(payload))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostRejectsAPIResponseBeyondFourMiBWithoutTruncatedJSONError(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"payload":"` + strings.Repeat("x", int(maxAPIResponseBodyBytes)) + `"}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
var result map[string]any
|
||||
err := (Server{APIBaseURL: server.URL}).post(context.Background(), "/too-large", map[string]string{"request": "ok"}, &result)
|
||||
if err == nil || !strings.Contains(err.Error(), "api response exceeds 4194304-byte limit") {
|
||||
t.Fatalf("error = %v, want explicit response-size error", err)
|
||||
}
|
||||
if strings.Contains(err.Error(), "unexpected end of JSON input") {
|
||||
t.Fatalf("oversized response must not surface as truncated JSON: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user