TestDo_AcceptedError_LargeBodyTruncated verifies that when the API returns a 202 Accepted with a body larger than maxErrorBodySize, the client reads at most maxErrorBodySize bytes into AcceptedError.Raw and does not allocate unbounded memory.
(t *testing.T)
| 2279 | // most maxErrorBodySize bytes into AcceptedError.Raw and does not allocate |
| 2280 | // unbounded memory. |
| 2281 | func TestDo_AcceptedError_LargeBodyTruncated(t *testing.T) { |
| 2282 | t.Parallel() |
| 2283 | client, mux, _ := setup(t) |
| 2284 | |
| 2285 | // Serve a 202 response whose body exceeds the cap by one byte. |
| 2286 | mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { |
| 2287 | w.WriteHeader(http.StatusAccepted) |
| 2288 | fmt.Fprint(w, strings.Repeat("x", maxErrorBodySize+1)) |
| 2289 | }) |
| 2290 | |
| 2291 | req, _ := client.NewRequest(t.Context(), "GET", ".", nil) |
| 2292 | _, err := client.Do(req, nil) |
| 2293 | if err == nil { |
| 2294 | t.Fatal("Expected AcceptedError, got nil") |
| 2295 | } |
| 2296 | |
| 2297 | var aerr *AcceptedError |
| 2298 | if !errors.As(err, &aerr) { |
| 2299 | t.Fatalf("Expected *AcceptedError, got %T: %v", err, err) |
| 2300 | } |
| 2301 | |
| 2302 | if got, want := len(aerr.Raw), maxErrorBodySize; got != want { |
| 2303 | t.Errorf("AcceptedError.Raw length = %v, want %v (maxErrorBodySize)", got, want) |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | // Test that an error caused by the internal http client's Do() function |
| 2308 | // does not leak the client secret. |
nothing calls this directly
no test coverage detected
searching dependent graphs…