──────────────────────── /consent ──────────────────────── TestHTTP_Consent_Allow_CreateNew is the happy path: user picks "create_new" + a slug, gets a code redirected to the client's redirect_uri. Verifies (a) status 303, (b) code has our prefix, (c) iss is present per RFC 9207, (d) state round-tri
(t *testing.T)
| 294 | // (c) iss is present per RFC 9207, (d) state round-trips, and |
| 295 | // (e) the agent row was actually created. |
| 296 | func TestHTTP_Consent_Allow_CreateNew(t *testing.T) { |
| 297 | f := newConsentFixture(t) |
| 298 | _, challenge := newPKCE(t) |
| 299 | |
| 300 | form := authorizeParams(challenge, f.clientID, "s1s1s1s1s1s1s1s1") |
| 301 | form.Set("action", "allow") |
| 302 | form.Set("agent_choice", "create_new") |
| 303 | form.Set("new_agent_slug", "myconsentbot") |
| 304 | |
| 305 | resp := f.consentPOST(t, form) |
| 306 | defer resp.Body.Close() |
| 307 | if resp.StatusCode != http.StatusSeeOther { |
| 308 | t.Fatalf("status = %d, want 303 See Other", resp.StatusCode) |
| 309 | } |
| 310 | loc, err := url.Parse(resp.Header.Get("Location")) |
| 311 | if err != nil { |
| 312 | t.Fatalf("Location parse: %v", err) |
| 313 | } |
| 314 | if !strings.HasPrefix(loc.String(), "http://localhost:8765/callback") { |
| 315 | t.Errorf("must redirect back to client redirect_uri: got %q", loc.String()) |
| 316 | } |
| 317 | code := loc.Query().Get("code") |
| 318 | if !strings.HasPrefix(code, oauth.AuthCodePrefix) { |
| 319 | t.Errorf("code missing %q prefix: %q", oauth.AuthCodePrefix, code) |
| 320 | } |
| 321 | if got := loc.Query().Get("state"); got != "s1s1s1s1s1s1s1s1" { |
| 322 | t.Errorf("state round-trip: got %q, want s1s1s1s1s1s1s1s1", got) |
| 323 | } |
| 324 | if got := loc.Query().Get("iss"); got != "https://test.e2a.dev" { |
| 325 | t.Errorf("RFC 9207 iss missing/wrong: got %q, want https://test.e2a.dev", got) |
| 326 | } |
| 327 | |
| 328 | // Verify the agent was actually created on the shared domain. |
| 329 | var count int |
| 330 | if err := f.pool.QueryRow(context.Background(), |
| 331 | `SELECT count(*) FROM agent_identities WHERE id = $1 AND user_id = $2`, |
| 332 | "myconsentbot@agents.e2a.dev", f.userID).Scan(&count); err != nil { |
| 333 | t.Fatal(err) |
| 334 | } |
| 335 | if count != 1 { |
| 336 | t.Errorf("expected exactly 1 agent row for new slug, got %d", count) |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | // TestHTTP_Consent_Allow_Existing — user picks an agent they already |
| 341 | // own. No new agent created; code issued bound to the chosen email. |
nothing calls this directly
no test coverage detected