From 5cccf1a7e70463fc3dc09dbf626fed7d450f5a2e Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Mon, 9 Mar 2015 14:25:31 -0700 Subject: [PATCH] oauth2: add a test that checks token reuse Change-Id: I6bd9cadc489418708635ca55a21955b94203bede Reviewed-on: https://go-review.googlesource.com/7240 Reviewed-by: Andrew Gerrand --- oauth2_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/oauth2_test.go b/oauth2_test.go index edbe03a..2ec482b 100644 --- a/oauth2_test.go +++ b/oauth2_test.go @@ -6,6 +6,7 @@ package oauth2 import ( "errors" + "fmt" "io/ioutil" "net/http" "net/http/httptest" @@ -328,3 +329,27 @@ func TestRefreshToken_RefreshTokenReplacement(t *testing.T) { t.Errorf("tokenRefresher.refresh_token = %s; want %s", tkr.refreshToken, tk.RefreshToken) } } + +func TestConfigClientWithToken(t *testing.T) { + tok := &Token{ + AccessToken: "abc123", + } + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if got, want := r.Header.Get("Authorization"), fmt.Sprintf("Bearer %s", tok.AccessToken); got != want { + t.Errorf("Authorization header = %q; want %q", got, want) + } + return + })) + defer ts.Close() + conf := newConf(ts.URL) + + c := conf.Client(NoContext, tok) + req, err := http.NewRequest("GET", ts.URL, nil) + if err != nil { + t.Error(err) + } + _, err = c.Do(req) + if err != nil { + t.Error(err) + } +}