forked from Mirrors/oauth2
oauth2, jws, internal: more style fixes for bad test messages
Change-Id: Id2805fd77fb11d975414eb66689efab284a18805 Reviewed-on: https://go-review.googlesource.com/27911 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
68218bf41b
commit
e839600e66
|
@ -14,23 +14,22 @@ func TestRegisterBrokenAuthHeaderProvider(t *testing.T) {
|
||||||
RegisterBrokenAuthHeaderProvider("https://aaa.com/")
|
RegisterBrokenAuthHeaderProvider("https://aaa.com/")
|
||||||
tokenURL := "https://aaa.com/token"
|
tokenURL := "https://aaa.com/token"
|
||||||
if providerAuthHeaderWorks(tokenURL) {
|
if providerAuthHeaderWorks(tokenURL) {
|
||||||
t.Errorf("URL: %s is a broken provider", tokenURL)
|
t.Errorf("got %q as unbroken; want broken", tokenURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_providerAuthHeaderWorks(t *testing.T) {
|
func Test_providerAuthHeaderWorks(t *testing.T) {
|
||||||
for _, p := range brokenAuthHeaderProviders {
|
for _, p := range brokenAuthHeaderProviders {
|
||||||
if providerAuthHeaderWorks(p) {
|
if providerAuthHeaderWorks(p) {
|
||||||
t.Errorf("URL: %s not found in list", p)
|
t.Errorf("got %q as unbroken; want broken", p)
|
||||||
}
|
}
|
||||||
p := fmt.Sprintf("%ssomesuffix", p)
|
p := fmt.Sprintf("%ssomesuffix", p)
|
||||||
if providerAuthHeaderWorks(p) {
|
if providerAuthHeaderWorks(p) {
|
||||||
t.Errorf("URL: %s not found in list", p)
|
t.Errorf("got %q as unbroken; want broken", p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p := "https://api.not-in-the-list-example.com/"
|
p := "https://api.not-in-the-list-example.com/"
|
||||||
if !providerAuthHeaderWorks(p) {
|
if !providerAuthHeaderWorks(p) {
|
||||||
t.Errorf("URL: %s found in list", p)
|
t.Errorf("got %q as unbroken; want broken", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,6 @@ func TestSignAndVerify(t *testing.T) {
|
||||||
func TestVerifyFailsOnMalformedClaim(t *testing.T) {
|
func TestVerifyFailsOnMalformedClaim(t *testing.T) {
|
||||||
err := Verify("abc.def", nil)
|
err := Verify("abc.def", nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Improperly formed JWT should fail.")
|
t.Error("got no errors; want improperly formed JWT not to be verified")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@ func TestTransportNilTokenSource(t *testing.T) {
|
||||||
server := newMockServer(func(w http.ResponseWriter, r *http.Request) {})
|
server := newMockServer(func(w http.ResponseWriter, r *http.Request) {})
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
client := &http.Client{Transport: tr}
|
client := &http.Client{Transport: tr}
|
||||||
res, err := client.Get(server.URL)
|
resp, err := client.Get(server.URL)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("a nil Source was passed into the transport expected an error")
|
t.Errorf("got no errors, want an error with nil token source")
|
||||||
}
|
}
|
||||||
if res != nil {
|
if resp != nil {
|
||||||
t.Errorf("expected a nil response, got %v", res)
|
t.Errorf("Response = %v; want nil", resp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ func TestTransportTokenSource(t *testing.T) {
|
||||||
Source: ts,
|
Source: ts,
|
||||||
}
|
}
|
||||||
server := newMockServer(func(w http.ResponseWriter, r *http.Request) {
|
server := newMockServer(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Header.Get("Authorization") != "Bearer abc" {
|
if got, want := r.Header.Get("Authorization"), "Bearer abc"; got != want {
|
||||||
t.Errorf("Transport doesn't set the Authorization header from the fetched token")
|
t.Errorf("Authorization header = %q; want %q", got, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
@ -90,7 +90,7 @@ func TestTransportTokenSourceTypes(t *testing.T) {
|
||||||
func TestTokenValidNoAccessToken(t *testing.T) {
|
func TestTokenValidNoAccessToken(t *testing.T) {
|
||||||
token := &Token{}
|
token := &Token{}
|
||||||
if token.Valid() {
|
if token.Valid() {
|
||||||
t.Errorf("Token should not be valid with no access token")
|
t.Errorf("got valid with no access token; want invalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ func TestExpiredWithExpiry(t *testing.T) {
|
||||||
Expiry: time.Now().Add(-5 * time.Hour),
|
Expiry: time.Now().Add(-5 * time.Hour),
|
||||||
}
|
}
|
||||||
if token.Valid() {
|
if token.Valid() {
|
||||||
t.Errorf("Token should not be valid if it expired in the past")
|
t.Errorf("got valid with expired token; want invalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue