(t *testing.T)
| 263 | } |
| 264 | |
| 265 | func TestPassGroupsHeadersWithGroups(t *testing.T) { |
| 266 | opts := baseTestOptions() |
| 267 | opts.InjectRequestHeaders = []options.Header{ |
| 268 | { |
| 269 | Name: "X-Forwarded-Groups", |
| 270 | Values: []options.HeaderValue{ |
| 271 | { |
| 272 | ClaimSource: &options.ClaimSource{ |
| 273 | Claim: "groups", |
| 274 | }, |
| 275 | }, |
| 276 | }, |
| 277 | }, |
| 278 | } |
| 279 | |
| 280 | err := validation.Validate(opts) |
| 281 | assert.NoError(t, err) |
| 282 | |
| 283 | const emailAddress = "john.doe@example.com" |
| 284 | const userName = "9fcab5c9b889a557" |
| 285 | |
| 286 | groups := []string{"a", "b"} |
| 287 | created := time.Now() |
| 288 | session := &sessions.SessionState{ |
| 289 | User: userName, |
| 290 | Groups: groups, |
| 291 | Email: emailAddress, |
| 292 | AccessToken: "oauth_token", |
| 293 | CreatedAt: &created, |
| 294 | } |
| 295 | |
| 296 | proxy, err := NewOAuthProxy(opts, func(email string) bool { |
| 297 | return email == emailAddress |
| 298 | }) |
| 299 | assert.NoError(t, err) |
| 300 | |
| 301 | // Save the required session |
| 302 | rw := httptest.NewRecorder() |
| 303 | req, _ := http.NewRequest(http.MethodGet, "/", nil) |
| 304 | err = proxy.sessionStore.Save(rw, req, session) |
| 305 | assert.NoError(t, err) |
| 306 | |
| 307 | // Extract the cookie value to inject into the test request |
| 308 | cookie := rw.Header().Values("Set-Cookie")[0] |
| 309 | |
| 310 | req, _ = http.NewRequest(http.MethodGet, "/", nil) |
| 311 | req.Header.Set("Cookie", cookie) |
| 312 | rw = httptest.NewRecorder() |
| 313 | proxy.ServeHTTP(rw, req) |
| 314 | |
| 315 | assert.Equal(t, []string{"a,b"}, req.Header["X-Forwarded-Groups"]) |
| 316 | } |
| 317 | |
| 318 | type PassAccessTokenTest struct { |
| 319 | providerServer *httptest.Server |
nothing calls this directly
no test coverage detected