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

Function NewValidateSessionTest

providers/internal_util_test.go:46–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44}
45
46func NewValidateSessionTest() *ValidateSessionStateTest {
47 var vtTest ValidateSessionStateTest
48
49 vtTest.backend = httptest.NewServer(
50 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
51 if r.URL.Path != "/oauth/tokeninfo" {
52 w.WriteHeader(500)
53 w.Write([]byte("unknown URL"))
54 }
55 tokenParam := r.FormValue("access_token")
56 if tokenParam == "" {
57 missing := false
58 receivedHeaders := r.Header
59 for k := range vtTest.header {
60 received := receivedHeaders.Get(k)
61 expected := vtTest.header.Get(k)
62 if received == "" || received != expected {
63 missing = true
64 }
65 }
66 if missing {
67 w.WriteHeader(500)
68 w.Write([]byte("no token param and missing or incorrect headers"))
69 }
70 }
71 w.WriteHeader(vtTest.responseCode)
72 w.Write([]byte("only code matters; contents disregarded"))
73
74 }))
75 backendURL, _ := url.Parse(vtTest.backend.URL)
76 vtTest.provider = &ValidateSessionTestProvider{
77 ProviderData: &ProviderData{
78 ValidateURL: &url.URL{
79 Scheme: "http",
80 Host: backendURL.Host,
81 Path: "/oauth/tokeninfo",
82 },
83 },
84 }
85 vtTest.responseCode = 200
86 return &vtTest
87}
88
89func (vtTest *ValidateSessionStateTest) Close() {
90 vtTest.backend.Close()

Calls 3

WriteHeaderMethod · 0.80
GetMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected