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

Function TestHTTP_Consent_Account_Loopback

internal/agent/oauth_scope_picker_test.go:66–98  ·  view source on GitHub ↗

TestHTTP_Consent_Account_Loopback grants account scope when the user picks it on a loopback client, and the resulting token resolves to an account principal (no bound agent) — exactly like an e2a_acct_ key.

(t *testing.T)

Source from the content-addressed store, hash-verified

64// on a loopback client, and the resulting token resolves to an account
65// principal (no bound agent) — exactly like an e2a_acct_ key.
66func TestHTTP_Consent_Account_Loopback(t *testing.T) {
67 f := newConsentFixture(t)
68 verifier, challenge := newPKCE(t)
69 redirectURI := "http://localhost:8765/callback"
70
71 form := authorizeParams(challenge, f.clientID, "s1s1s1s1s1s1s1s1")
72 form.Set("action", "allow")
73 form.Set("scope_choice", "account")
74 // No agent_choice — account isn't inbox-bound.
75
76 resp := f.consentPOST(t, form)
77 defer resp.Body.Close()
78 if resp.StatusCode != http.StatusSeeOther {
79 t.Fatalf("status = %d, want 303 (account on loopback is allowed)", resp.StatusCode)
80 }
81 loc, _ := url.Parse(resp.Header.Get("Location"))
82 code := loc.Query().Get("code")
83 if code == "" {
84 t.Fatalf("expected code in redirect, got error=%q", loc.Query().Get("error"))
85 }
86
87 access, _, scope := f.exchangeCode(t, code, verifier, redirectURI)
88 if !strings.Contains(scope, "account") {
89 t.Errorf("token scope = %q, want it to contain account", scope)
90 }
91 gotScope, agentAddr := f.whoami(t, access)
92 if gotScope != "account" {
93 t.Errorf("whoami scope = %q, want account", gotScope)
94 }
95 if agentAddr != "" {
96 t.Errorf("account principal must have no bound agent; got agent_address=%q", agentAddr)
97 }
98}
99
100// TestHTTP_Consent_Account_NonLoopback_Rejected — the loopback gate fails closed
101// for a client whose redirect is https (a hosted/remote client that couldn't

Callers

nothing calls this directly

Calls 9

newConsentFixtureFunction · 0.85
newPKCEFunction · 0.85
authorizeParamsFunction · 0.85
consentPOSTMethod · 0.80
QueryMethod · 0.80
exchangeCodeMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.45
whoamiMethod · 0.45

Tested by

no test coverage detected