(t *testing.T)
| 280 | } |
| 281 | |
| 282 | func 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 | |
| 309 | func TestNewHTTPClientLegacyConfigAttachesToken(t *testing.T) { |
| 310 | // Regression: HTTPClientOptions.Config (the primitive seam) must keep authenticating requests for external callers. |
nothing calls this directly
no test coverage detected