mirror of
https://github.com/golang/oauth2.git
synced 2025-07-21 00:00:09 +08:00
some pr review fixes
This commit is contained in:
parent
e68820a209
commit
8551f9eee2
@ -64,27 +64,30 @@ func TestExchangeRequest(t *testing.T) {
|
||||
if headerContentType != "application/x-www-form-urlencoded" {
|
||||
t.Errorf("Unexpected Content-Type header, %v is found.", headerContentType)
|
||||
}
|
||||
body, _ := ioutil.ReadAll(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Errorf("Failed reading request body: %s.", err)
|
||||
}
|
||||
if string(body) != "client_id=CLIENT_ID&code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL&scope=scope1+scope2" {
|
||||
t.Errorf("Unexpected exchange payload, %v is found.", string(body))
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
w.Write([]byte("access_token=90d64460d14870c08c81352a05dedd3465940a7c&scope=user&token_type=bearer"))
|
||||
}))
|
||||
defer ts.Close()
|
||||
conf := newTestConf(ts.URL)
|
||||
tok, err := conf.Exchange("exchange-code")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Errorf("Failed retrieving token: %s.", err)
|
||||
}
|
||||
if tok.Expired() {
|
||||
t.Fatal("token shouldn't be expired")
|
||||
t.Errorf("Token shouldn't be expired.")
|
||||
}
|
||||
if tok.AccessToken != "90d64460d14870c08c81352a05dedd3465940a7c" {
|
||||
t.Fatalf("wrong access token, %#v", tok.AccessToken)
|
||||
t.Errorf("Wrong access token, %#v.", tok.AccessToken)
|
||||
}
|
||||
if tok.TokenType != "bearer" {
|
||||
t.Fatal("wrong token type, %#v", tok.TokenType)
|
||||
t.Errorf("Wrong token type, %#v.", tok.TokenType)
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +104,10 @@ func TestExchangeRequest_JsonResponse(t *testing.T) {
|
||||
if headerContentType != "application/x-www-form-urlencoded" {
|
||||
t.Errorf("Unexpected Content-Type header, %v is found.", headerContentType)
|
||||
}
|
||||
body, _ := ioutil.ReadAll(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Errorf("Failed reading request body: %s.", err)
|
||||
}
|
||||
if string(body) != "client_id=CLIENT_ID&code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL&scope=scope1+scope2" {
|
||||
t.Errorf("Unexpected exchange payload, %v is found.", string(body))
|
||||
}
|
||||
@ -112,16 +118,16 @@ func TestExchangeRequest_JsonResponse(t *testing.T) {
|
||||
conf := newTestConf(ts.URL)
|
||||
tok, err := conf.Exchange("exchange-code")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Errorf("Failed retrieving token: %s.", err)
|
||||
}
|
||||
if tok.Expired() {
|
||||
t.Fatal("token shouldn't be expired")
|
||||
t.Errorf("Token shouldn't be expired.")
|
||||
}
|
||||
if tok.AccessToken != "90d64460d14870c08c81352a05dedd3465940a7c" {
|
||||
t.Fatalf("wrong access token, %#v", tok.AccessToken)
|
||||
t.Errorf("Wrong access token, %#v.", tok.AccessToken)
|
||||
}
|
||||
if tok.TokenType != "bearer" {
|
||||
t.Fatal("wrong token type, %#v", tok.TokenType)
|
||||
t.Errorf("Wrong token type, %#v.", tok.TokenType)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user