@@ -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"
@@ -425,7 +428,9 @@ func (patTest *PassAccessTokenTest) getCallbackEndpoint() (httpCode int,
425428 return rw.Code, rw.HeaderMap["Set-Cookie"][1]
426429}
427430
428−func (patTest *PassAccessTokenTest) getRootEndpoint(cookie string) (httpCode int, accessToken string) {
431+// getEndpointWithCookie makes a requests againt the oauthproxy with passed requestPath
432+// and cookie and returns body and status code.
433+func (patTest *PassAccessTokenTest) getEndpointWithCookie(cookie string, endpoint string) (httpCode int, accessToken string) {
429434 cookieName := patTest.proxy.CookieName
430435 var value string
431436 keyPrefix := cookieName + "="
@@ -442,7 +447,7 @@ func (patTest *PassAccessTokenTest) getRootEndpoint(cookie string) (httpCode int
442447 return 0, ""
443448 }
444449
445− req, err := http.NewRequest("GET", "/", strings.NewReader(""))
450+ req, err := http.NewRequest("GET", endpoint, strings.NewReader(""))
446451 if err != nil {
447452 return 0, ""
448453 }
@@ -475,13 +480,37 @@ func TestForwardAccessTokenUpstream(t *testing.T) {
475480 // Now we make a regular request; the access_token from the cookie is
476481 // forwarded as the "X-Forwarded-Access-Token" header. The token is
477482 // read by the test provider server and written in the response body.
478− code, payload := patTest.getRootEndpoint(cookie)
483+ code, payload := patTest.getEndpointWithCookie(cookie, "/")
479484 if code != 200 {
480485 t.Fatalf("expected 200; got %d", code)
481486 }
482487 assert.Equal(t, "my_auth_token", payload)
483488}
484489
490+func TestStaticProxyUpstream(t *testing.T) {
491+ patTest := NewPassAccessTokenTest(PassAccessTokenTestOptions{
492+ PassAccessToken: true,
493+ ProxyUpstream: "static://200/static-proxy",
494+ })
495+
496+ defer patTest.Close()
497+
498+ // A successful validation will redirect and set the auth cookie.
499+ code, cookie := patTest.getCallbackEndpoint()
500+ if code != 302 {
501+ t.Fatalf("expected 302; got %d", code)
502+ }
503+ assert.NotEqual(t, nil, cookie)
504+
505+ // Now we make a regular request againts the upstream proxy; And validate
506+ // the returned status code through the static proxy.
507+ code, payload := patTest.getEndpointWithCookie(cookie, "/static-proxy")
508+ if code != 200 {
509+ t.Fatalf("expected 200; got %d", code)
510+ }
511+ assert.Equal(t, "Authenticated", payload)
512+}
513+
485514func TestDoNotForwardAccessTokenUpstream(t *testing.T) {
486515 patTest := NewPassAccessTokenTest(PassAccessTokenTestOptions{
487516 PassAccessToken: false,
@@ -497,7 +526,7 @@ func TestDoNotForwardAccessTokenUpstream(t *testing.T) {
497526
498527 // Now we make a regular request, but the access token header should
499528 // not be present.
500− code, payload := patTest.getRootEndpoint(cookie)
529+ code, payload := patTest.getEndpointWithCookie(cookie, "/")
501530 if code != 200 {
502531 t.Fatalf("expected 200; got %d", code)
503532 }