MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / getCallbackEndpoint

Method getCallbackEndpoint

oauthproxy_test.go:406–440  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

404}
405
406func (patTest *PassAccessTokenTest) getCallbackEndpoint() (httpCode int, cookie string) {
407 rw := httptest.NewRecorder()
408
409 csrf, err := cookies.NewCSRF(patTest.proxy.CookieOptions, "")
410 if err != nil {
411 panic(err)
412 }
413
414 req, err := http.NewRequest(
415 http.MethodGet,
416 fmt.Sprintf(
417 "/oauth2/callback?code=callback_code&state=%s",
418 encodeState(csrf.HashOAuthState(), "%2F", false),
419 ),
420 strings.NewReader(""),
421 )
422 if err != nil {
423 return 0, ""
424 }
425
426 // rw is a dummy here, we just want the csrfCookie to add to our req
427 csrfCookie, err := csrf.SetCookie(httptest.NewRecorder(), req)
428 if err != nil {
429 panic(err)
430 }
431 req.AddCookie(csrfCookie)
432
433 patTest.proxy.ServeHTTP(rw, req)
434
435 if len(rw.Header().Values("Set-Cookie")) >= 2 {
436 cookie = rw.Header().Values("Set-Cookie")[1]
437 }
438
439 return rw.Code, cookie
440}
441
442// getEndpointWithCookie makes a requests againt the oauthproxy with passed requestPath
443// and cookie and returns body and status code.

Calls 5

HashOAuthStateMethod · 0.95
SetCookieMethod · 0.95
NewCSRFFunction · 0.92
encodeStateFunction · 0.85
ServeHTTPMethod · 0.45

Tested by

no test coverage detected