MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestRegRateLimited

Function TestRegRateLimited

internal/httpapi/ratelimit_test.go:145–166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

143}
144
145func TestRegRateLimited(t *testing.T) {
146 srv := httptest.NewServer(New(Deps{
147 Authenticator: func(r *http.Request) (*identity.User, error) {
148 return &identity.User{ID: "u_1"}, nil
149 },
150 CreateAgent: func(ctx context.Context, email, domain, name, webhookURL, agentMode, userID string) (*identity.AgentIdentity, error) {
151 t.Error("CreateAgent must NOT be reached when reg-limited")
152 return nil, nil
153 },
154 RegLimit: func(key string) (bool, time.Duration, int, int, int) {
155 return false, 30 * time.Second, 200, 0, 3600
156 },
157 }))
158 t.Cleanup(srv.Close)
159
160 code, body := postJSON(t, srv.URL+"/v1/agents", "good", map[string]any{
161 "slug": "bot",
162 })
163 if code != 429 || errCode(body) != "rate_limited" {
164 t.Fatalf("want 429 rate_limited, got %d %v", code, body)
165 }
166}
167
168// serverWithSendLimit builds a minimal server whose SendLimit always blocks,
169// to assert the 429 path on the outbound chokepoint.

Callers

nothing calls this directly

Calls 5

postJSONFunction · 0.85
errCodeFunction · 0.85
CleanupMethod · 0.80
NewFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected