HTTPClient does nothing if IsServing is used. If IsServing is not used, then it will return a client that will make requests to the IDP all in memory. If a request is not to the IDP, then the passed in client will be used. If no client is passed in, then any regular network requests will fail.
(rest *http.Client)
| 1449 | // client will be used. If no client is passed in, then any regular network |
| 1450 | // requests will fail. |
| 1451 | func (f *FakeIDP) HTTPClient(rest *http.Client) *http.Client { |
| 1452 | if f.serve { |
| 1453 | if rest == nil { |
| 1454 | return &http.Client{} |
| 1455 | } |
| 1456 | return rest |
| 1457 | } |
| 1458 | |
| 1459 | var jar http.CookieJar |
| 1460 | if rest != nil { |
| 1461 | jar = rest.Jar |
| 1462 | } |
| 1463 | return &http.Client{ |
| 1464 | Jar: jar, |
| 1465 | Transport: fakeRoundTripper{ |
| 1466 | roundTrip: func(req *http.Request) (*http.Response, error) { |
| 1467 | u, _ := url.Parse(f.locked.Issuer()) |
| 1468 | if req.URL.Host != u.Host { |
| 1469 | if fakeCoderd := f.locked.FakeCoderd(); fakeCoderd != nil { |
| 1470 | return fakeCoderd(req) |
| 1471 | } |
| 1472 | if rest == nil || rest.Transport == nil { |
| 1473 | return nil, xerrors.Errorf("unexpected network request to %q", req.URL.Host) |
| 1474 | } |
| 1475 | return rest.Transport.RoundTrip(req) |
| 1476 | } |
| 1477 | resp := httptest.NewRecorder() |
| 1478 | f.locked.Handler().ServeHTTP(resp, req) |
| 1479 | return resp.Result(), nil |
| 1480 | }, |
| 1481 | }, |
| 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | // RefreshUsed returns if the refresh token has been used. All refresh tokens |
| 1486 | // can only be used once, then they are deleted. |