Repository navigation
Conversation
wim07101993
left a comment
There was a problem hiding this comment.
Hi, thank you for the contribution. Looks good but I have a few small comments on the tests. Can you have a quick look?
|
|
||
| func TestExchangeToken_OmitsUnsetParameters(t *testing.T) { | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| require.NoError(t, r.ParseForm()) |
There was a problem hiding this comment.
require.NoError calls t.FailNow on the handler goroutine, which testing doesn't allow (testifylint's go-require flags this line). If ParseForm ever failed, the test would also report a second, misleading Post …: EOF from the client. Could you capture r.PostForm in the handler and assert after ExchangeToken returns, like pkg/client/client_test.go does?
| func TestExchangeToken_OmitsUnsetParameters(t *testing.T) { | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| require.NoError(t, r.ParseForm()) | ||
| for _, p := range []string{"actor_token", "actor_token_type", "resource", "audience", "scope", "requested_token_type"} { |
There was a problem hiding this comment.
This only checks that values are absent, so it would also pass if nothing were sent. I tagged every TokenExchangeRequest field schema:"-" and the test still passed. The resource and audience checks passed before this change too, because nil slices were never encoded.
Could you assert that grant_type, subject_token and subject_token_type are still sent, and add a case with every optional value set, so the test shows omitempty doesn't drop them?
| assert.NotContains(t, r.PostForm, p) | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| w.Write([]byte(`{"access_token":"a","issued_token_type":"urn:ietf:params:oauth:token-type:access_token","token_type":"Bearer"}`)) |
There was a problem hiding this comment.
errcheck flags this; the other test handlers ignore the result explicitly.
| w.Write([]byte(`{"access_token":"a","issued_token_type":"urn:ietf:params:oauth:token-type:access_token","token_type":"Bearer"}`)) | |
| _, _ = w.Write([]byte(`{"access_token":"a","issued_token_type":"urn:ietf:params:oauth:token-type:access_token","token_type":"Bearer"}`)) |
Which Problems Are Solved
actor_token=&actor_token_type=&requested_token_type=&scope=). RFC 8693 §2.1 saysactor_token_type"MUST NOT be included" whenactor_tokenis absent, and servers that check for presencemay reject or misroute the request.
How the Problems Are Solved
omitemptyto the optional parameters ofTokenExchangeRequest.Additional Changes
Additional Context