Skip to content

Commit 13106db

Browse files
committed
oauth2: add grant_type override test
1 parent 51f4c98 commit 13106db

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

clientcredentials/clientcredentials_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ import (
1515

1616
func newConf(serverURL string) *Config {
1717
return &Config{
18-
ClientID: "CLIENT_ID",
19-
ClientSecret: "CLIENT_SECRET",
20-
Scopes: []string{"scope1", "scope2"},
21-
TokenURL: serverURL + "/token",
22-
EndpointParams: url.Values{"audience": {"audience1"}},
18+
ClientID: "CLIENT_ID",
19+
ClientSecret: "CLIENT_SECRET",
20+
Scopes: []string{"scope1", "scope2"},
21+
TokenURL: serverURL + "/token",
22+
EndpointParams: url.Values{
23+
"audience": {"audience1"},
24+
"grant_type": {"password"},
25+
},
2326
}
2427
}
2528

@@ -50,8 +53,8 @@ func TestTokenRequest(t *testing.T) {
5053
if err != nil {
5154
t.Errorf("failed reading request body: %s.", err)
5255
}
53-
if string(body) != "audience=audience1&grant_type=client_credentials&scope=scope1+scope2" {
54-
t.Errorf("payload = %q; want %q", string(body), "grant_type=client_credentials&scope=scope1+scope2")
56+
if wantBody := "audience=audience1&grant_type=password&scope=scope1+scope2"; string(body) != wantBody {
57+
t.Errorf("payload = %q; want %q", string(body), wantBody)
5558
}
5659
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
5760
w.Write([]byte("access_token=90d64460d14870c08c81352a05dedd3465940a7c&token_type=bearer"))
@@ -86,7 +89,7 @@ func TestTokenRefreshRequest(t *testing.T) {
8689
t.Errorf("Unexpected Content-Type header, %v is found.", headerContentType)
8790
}
8891
body, _ := ioutil.ReadAll(r.Body)
89-
if string(body) != "audience=audience1&grant_type=client_credentials&scope=scope1+scope2" {
92+
if string(body) != "audience=audience1&grant_type=password&scope=scope1+scope2" {
9093
t.Errorf("Unexpected refresh token payload, %v is found.", string(body))
9194
}
9295
}))

0 commit comments

Comments
 (0)