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

Function TestRequestExplicitAuthorizationHeaderIsPreserved

api/request_test.go:104–121  ·  view source on GitHub ↗

Pre-auth call sites supply their own token because it is not yet in config, so an explicit Authorization header must survive rather than be replaced by the transport.

(t *testing.T)

Source from the content-addressed store, hash-verified

102// Pre-auth call sites supply their own token because it is not yet in config, so an explicit
103// Authorization header must survive rather than be replaced by the transport.
104func TestRequestExplicitAuthorizationHeaderIsPreserved(t *testing.T) {
105 reg := &httpmock.Registry{}
106 defer reg.Verify(t)
107
108 httpClient := &http.Client{}
109 httpmock.ReplaceTripper(httpClient, reg)
110 httpClient.Transport = AddAuthTokenHeader(httpClient.Transport, tinyConfig{"github.com:oauth_token": "config-token"})
111 client := NewClientFromHTTP(httpClient)
112
113 reg.Register(httpmock.MatchAny, httpmock.StatusStringResponse(200, "{}"))
114
115 resp, err := client.Request("github.com", http.MethodGet, "user", nil,
116 WithHeader("Authorization", "token explicit-token"))
117 require.NoError(t, err)
118 defer resp.Body.Close()
119
120 assert.Equal(t, "token explicit-token", reg.Requests[0].Header.Get("Authorization"))
121}
122
123func TestRequestReturnsBodyUnread(t *testing.T) {
124 reg := &httpmock.Registry{}

Callers

nothing calls this directly

Calls 11

VerifyMethod · 0.95
RegisterMethod · 0.95
ReplaceTripperFunction · 0.92
StatusStringResponseFunction · 0.92
AddAuthTokenHeaderFunction · 0.85
NewClientFromHTTPFunction · 0.85
RequestMethod · 0.80
EqualMethod · 0.80
WithHeaderFunction · 0.70
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected