RequestExternalAuthCallback makes a request with the proper OAuth2 state cookie to the external auth callback endpoint.
(t testing.TB, providerID string, client *codersdk.Client, opts ...func(*http.Request))
| 1501 | // RequestExternalAuthCallback makes a request with the proper OAuth2 state cookie |
| 1502 | // to the external auth callback endpoint. |
| 1503 | func RequestExternalAuthCallback(t testing.TB, providerID string, client *codersdk.Client, opts ...func(*http.Request)) *http.Response { |
| 1504 | client.HTTPClient.CheckRedirect = func(_ *http.Request, _ []*http.Request) error { |
| 1505 | return http.ErrUseLastResponse |
| 1506 | } |
| 1507 | state := "somestate" |
| 1508 | oauthURL, err := client.URL.Parse(fmt.Sprintf("/external-auth/%s/callback?code=asd&state=%s", providerID, state)) |
| 1509 | require.NoError(t, err) |
| 1510 | req, err := http.NewRequestWithContext(context.Background(), "GET", oauthURL.String(), nil) |
| 1511 | require.NoError(t, err) |
| 1512 | req.AddCookie(&http.Cookie{ |
| 1513 | Name: codersdk.OAuth2StateCookie, |
| 1514 | Value: state, |
| 1515 | }) |
| 1516 | req.AddCookie(&http.Cookie{ |
| 1517 | Name: codersdk.SessionTokenCookie, |
| 1518 | Value: client.SessionToken(), |
| 1519 | }) |
| 1520 | for _, opt := range opts { |
| 1521 | opt(req) |
| 1522 | } |
| 1523 | res, err := client.HTTPClient.Do(req) |
| 1524 | require.NoError(t, err) |
| 1525 | t.Cleanup(func() { |
| 1526 | _ = res.Body.Close() |
| 1527 | }) |
| 1528 | return res |
| 1529 | } |
| 1530 | |
| 1531 | // NewGoogleInstanceIdentity returns a metadata client and ID token validator for faking |
| 1532 | // instance authentication for Google Cloud. |