MCPcopy Create free account
hub / github.com/cli/cli / TestAddAuthTokenHeaderLegacyConfig

Function TestAddAuthTokenHeaderLegacyConfig

api/http_client_test.go:282–307  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

280}
281
282func TestAddAuthTokenHeaderLegacyConfig(t *testing.T) {
283 // Regression: the primitive config seam that external callers implement must keep attaching tokens, including the
284 // api_host fallback, exactly as it did before refresh support was added.
285 var gotAuthorization string
286 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
287 gotAuthorization = r.Header.Get(authorization)
288 w.WriteHeader(http.StatusNoContent)
289 }))
290 defer ts.Close()
291
292 host := serverHostname(t, ts.URL)
293 cfg := legacyConfig{
294 "canonical.example:oauth_token": "CANONICAL-TOKEN",
295 "api_host:" + host: "canonical.example",
296 }
297 client := &http.Client{Transport: AddAuthTokenHeader(http.DefaultTransport, cfg)}
298
299 req, err := http.NewRequest("GET", ts.URL, nil)
300 require.NoError(t, err)
301
302 res, err := client.Do(req)
303 require.NoError(t, err)
304 assert.Equal(t, 204, res.StatusCode)
305 // The request host has no token of its own, so the token of the canonical host it stands in for is attached.
306 assert.Equal(t, "token CANONICAL-TOKEN", gotAuthorization)
307}
308
309func TestNewHTTPClientLegacyConfigAttachesToken(t *testing.T) {
310 // Regression: HTTPClientOptions.Config (the primitive seam) must keep authenticating requests for external callers.

Callers

nothing calls this directly

Calls 6

serverHostnameFunction · 0.85
AddAuthTokenHeaderFunction · 0.85
EqualMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected