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

Function Test_enrichSession

oauthproxy_test.go:123–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func Test_enrichSession(t *testing.T) {
124 const (
125 sessionUser = "Mr Session"
126 sessionEmail = "session@example.com"
127 providerEmail = "provider@example.com"
128 )
129
130 testCases := map[string]struct {
131 session *sessions.SessionState
132 expectedUser string
133 expectedEmail string
134 }{
135 "Session already has enrichable fields": {
136 session: &sessions.SessionState{
137 User: sessionUser,
138 Email: sessionEmail,
139 },
140 expectedUser: sessionUser,
141 expectedEmail: sessionEmail,
142 },
143 "Session is missing Email and GetEmailAddress is implemented": {
144 session: &sessions.SessionState{
145 User: sessionUser,
146 },
147 expectedUser: sessionUser,
148 expectedEmail: providerEmail,
149 },
150 "Session is missing User and GetUserName is not implemented": {
151 session: &sessions.SessionState{
152 Email: sessionEmail,
153 },
154 expectedUser: "",
155 expectedEmail: sessionEmail,
156 },
157 }
158
159 for name, tc := range testCases {
160 t.Run(name, func(t *testing.T) {
161 opts := baseTestOptions()
162 err := validation.Validate(opts)
163 assert.NoError(t, err)
164
165 proxy, err := NewOAuthProxy(opts, func(string) bool { return true })
166 if err != nil {
167 t.Fatal(err)
168 }
169 proxy.provider = NewTestProvider(&url.URL{Host: "www.example.com"}, providerEmail)
170
171 err = proxy.enrichSessionState(context.Background(), tc.session)
172 assert.NoError(t, err)
173 assert.Equal(t, tc.expectedUser, tc.session.User)
174 assert.Equal(t, tc.expectedEmail, tc.session.Email)
175 })
176 }
177}
178
179func TestBasicAuthPassword(t *testing.T) {
180 providerServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 5

enrichSessionStateMethod · 0.95
ValidateFunction · 0.92
baseTestOptionsFunction · 0.85
NewOAuthProxyFunction · 0.85
NewTestProviderFunction · 0.85

Tested by

no test coverage detected