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