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

Function oauth2Callback

coderd/userauth_test.go:3053–3080  ·  view source on GitHub ↗
(t *testing.T, client *codersdk.Client, opts ...func(*http.Request))

Source from the content-addressed store, hash-verified

3051}
3052
3053func oauth2Callback(t *testing.T, client *codersdk.Client, opts ...func(*http.Request)) *http.Response {
3054 client.HTTPClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
3055 return http.ErrUseLastResponse
3056 }
3057
3058 state := "somestate"
3059 oauthURL, err := client.URL.Parse("/api/v2/users/oauth2/github/callback?code=asd&state=" + state)
3060 require.NoError(t, err)
3061 req, err := http.NewRequestWithContext(context.Background(), "GET", oauthURL.String(), nil)
3062 require.NoError(t, err)
3063 for _, opt := range opts {
3064 opt(req)
3065 }
3066 req.AddCookie(&http.Cookie{
3067 Name: codersdk.OAuth2StateCookie,
3068 Value: state,
3069 })
3070 req.AddCookie(&http.Cookie{
3071 Name: codersdk.OAuth2PKCEVerifier,
3072 Value: oauth2.GenerateVerifier(),
3073 })
3074 res, err := client.HTTPClient.Do(req)
3075 require.NoError(t, err)
3076 t.Cleanup(func() {
3077 _ = res.Body.Close()
3078 })
3079 return res
3080}
3081
3082func authCookieValue(cookies []*http.Cookie) string {
3083 for _, cookie := range cookies {

Callers 1

TestUserOAuth2GithubFunction · 0.85

Calls 5

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

Tested by

no test coverage detected