@@ -365,6 +365,7 @@ type PassAccessTokenTest struct {
365365
366366type PassAccessTokenTestOptions struct {
367367 PassAccessToken bool
368+ ProxyUpstream string
368369}
369370
370371func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTest {
@@ -372,7 +373,6 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTes
372373
373374 t.providerServer = httptest.NewServer(
374375 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
375− logger.Printf("%#v", r)
376376 var payload string
377377 switch r.URL.Path {
378378 case "/oauth/token":
@@ -389,6 +389,9 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTes
389389
390390 t.opts = NewOptions()
391391 t.opts.Upstreams = append(t.opts.Upstreams, t.providerServer.URL)
392+ if opts.ProxyUpstream != "" {
393+ t.opts.Upstreams = append(t.opts.Upstreams, opts.ProxyUpstream)
394+ }
392395 // The CookieSecret must be 32 bytes in order to create the AES
393396 // cipher.
394397 t.opts.CookieSecret = "xyzzyplughxyzzyplughxyzzyplughxp"
@@ -459,6 +462,39 @@ func (patTest *PassAccessTokenTest) getRootEndpoint(cookie string) (httpCode int
459462 return rw.Code, rw.Body.String()
460463}
461464
465+func (patTest *PassAccessTokenTest) getProxyEndpoint(cookie string) (httpCode int, accessToken string) {
466+ cookieName := patTest.proxy.CookieName
467+ var value string
468+ keyPrefix := cookieName + "="
469+
470+ for _, field := range strings.Split(cookie, "; ") {
471+ value = strings.TrimPrefix(field, keyPrefix)
472+ if value != field {
473+ break
474+ } else {
475+ value = ""
476+ }
477+ }
478+ if value == "" {
479+ return 0, ""
480+ }
481+
482+ req, err := http.NewRequest("GET", "/static-proxy", strings.NewReader(""))
483+ if err != nil {
484+ return 0, ""
485+ }
486+ req.AddCookie(&http.Cookie{
487+ Name: cookieName,
488+ Value: value,
489+ Path: "/",
490+ Expires: time.Now().Add(time.Duration(24)),
491+ HttpOnly: true,
492+ })
493+ rw := httptest.NewRecorder()
494+ patTest.proxy.ServeHTTP(rw, req)
495+ return rw.Code, rw.Body.String()
496+}
497+
462498func TestForwardAccessTokenUpstream(t *testing.T) {
463499 patTest := NewPassAccessTokenTest(PassAccessTokenTestOptions{
464500 PassAccessToken: true,
@@ -482,6 +518,28 @@ func TestForwardAccessTokenUpstream(t *testing.T) {
482518 assert.Equal(t, "my_auth_token", payload)
483519}
484520
521+func TestStaticProxyUpstream(t *testing.T) {
522+ patTest := NewPassAccessTokenTest(PassAccessTokenTestOptions{
523+ PassAccessToken: true,
524+ ProxyUpstream: "static://200/static-proxy",
525+ })
526+
527+ defer patTest.Close()
528+
529+ // A successful validation will redirect and set the auth cookie.
530+ code, cookie := patTest.getCallbackEndpoint()
531+ if code != 302 {
532+ t.Fatalf("expected 302; got %d", code)
533+ }
534+ assert.NotEqual(t, nil, cookie)
535+
536+ code, payload := patTest.getProxyEndpoint(cookie)
537+ if code != 200 {
538+ t.Fatalf("expected 200; got %d", code)
539+ }
540+ assert.Equal(t, "Authenticated", payload)
541+}
542+
485543func TestDoNotForwardAccessTokenUpstream(t *testing.T) {
486544 patTest := NewPassAccessTokenTest(PassAccessTokenTestOptions{
487545 PassAccessToken: false,