MCPcopy Create free account
hub / github.com/algolia/cli / TestAuthorizationCodeGrant_Success

Function TestAuthorizationCodeGrant_Success

api/dashboard/client_test.go:38–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36}
37
38func TestAuthorizationCodeGrant_Success(t *testing.T) {
39 mux := http.NewServeMux()
40 mux.HandleFunc("/2/oauth/token", func(w http.ResponseWriter, r *http.Request) {
41 assert.Equal(t, http.MethodPost, r.Method)
42 assert.Equal(t, "application/x-www-form-urlencoded", r.Header.Get("Content-Type"))
43
44 require.NoError(t, r.ParseForm())
45 assert.Equal(t, "authorization_code", r.FormValue("grant_type"))
46 assert.Equal(t, "test-client-id", r.FormValue("client_id"))
47 assert.Equal(t, "auth-code-123", r.FormValue("code"))
48 assert.Equal(t, "verifier-xyz", r.FormValue("code_verifier"))
49
50 require.NoError(t, json.NewEncoder(w).Encode(OAuthTokenResponse{
51 AccessToken: "access-token-123",
52 RefreshToken: "refresh-token-456",
53 TokenType: "Bearer",
54 ExpiresIn: 7200,
55 Scope: "scope:test",
56 User: &User{
57 ID: 1,
58 Email: "user@test.com",
59 Name: "Test User",
60 },
61 }))
62 })
63
64 ts, client := newTestClient(mux)
65 defer ts.Close()
66
67 resp, err := client.AuthorizationCodeGrant(
68 "auth-code-123",
69 "verifier-xyz",
70 "http://localhost:12345",
71 )
72 require.NoError(t, err)
73 assert.Equal(t, "access-token-123", resp.AccessToken)
74 assert.Equal(t, "refresh-token-456", resp.RefreshToken)
75 assert.Equal(t, "user@test.com", resp.User.Email)
76}
77
78func TestAuthorizationCodeGrant_InvalidGrant(t *testing.T) {
79 mux := http.NewServeMux()

Callers

nothing calls this directly

Calls 4

newTestClientFunction · 0.85
GetMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected