(t *testing.T)
| 190 | } |
| 191 | |
| 192 | func TestSendRateLimited(t *testing.T) { |
| 193 | srv := serverWithSendLimit(t) |
| 194 | code, body := postJSON(t, srv.URL+"/v1/agents/support%40acme.com/messages", "good", map[string]any{ |
| 195 | "to": []string{"a@x.com"}, "subject": "Hi", "body": "hello", |
| 196 | }) |
| 197 | if code != 429 || errCode(body) != "rate_limited" { |
| 198 | t.Fatalf("want 429 rate_limited, got %d %v", code, body) |
| 199 | } |
| 200 | e, _ := body["error"].(map[string]any) |
| 201 | d, _ := e["details"].(map[string]any) |
| 202 | if d == nil || d["retry_after_seconds"].(float64) != 7 { |
| 203 | t.Fatalf("expected retry_after_seconds=7 in details, got %v", body) |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // TestClientIPIgnoresXForwardedFor locks in the per-IP-limiter security |
| 208 | // contract: the caller key comes from CF-Connecting-IP (edge-set, not |
nothing calls this directly
no test coverage detected