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

Function TestAddAuthTokenHeaderLegacyConfig

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

Source from the content-addressed store, hash-verified

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