| 3051 | } |
| 3052 | |
| 3053 | func 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 | |
| 3082 | func authCookieValue(cookies []*http.Cookie) string { |
| 3083 | for _, cookie := range cookies { |