MCPcopy Index your code
hub / github.com/coder/coder / RequestExternalAuthCallback

Function RequestExternalAuthCallback

coderd/coderdtest/coderdtest.go:1503–1529  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

1501// RequestExternalAuthCallback makes a request with the proper OAuth2 state cookie
1502// to the external auth callback endpoint.
1503func 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.

Callers 4

TestExternalAuthCallbackFunction · 0.92
TestCreateWithGitAuthFunction · 0.92

Calls 6

ParseMethod · 0.65
DoMethod · 0.65
CleanupMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
SessionTokenMethod · 0.45

Tested by 4

TestExternalAuthCallbackFunction · 0.74
TestCreateWithGitAuthFunction · 0.74