Skip to content

Commit

Permalink
TT-13185, implemented CR feedback 2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-tyk committed Oct 22, 2024
1 parent cad722f commit bed31cb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions gateway/mw_oauth2_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ func TestUpstreamOauth2(t *testing.T) {

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.String() != "/token" {
t.Errorf("authenticate client request URL = %q; want %q", r.URL, "/token")
assert.Fail(t, "authenticate client request URL = %q; want %q", r.URL, "/token")
}
headerAuth := r.Header.Get("Authorization")
if headerAuth != "Basic Q0xJRU5UX0lEOkNMSUVOVF9TRUNSRVQ=" {
t.Errorf("Unexpected authorization header, %v is found.", headerAuth)
assert.Fail(t, "Unexpected authorization header, %v is found.", headerAuth)
}
if got, want := r.Header.Get("Content-Type"), "application/x-www-form-urlencoded"; got != want {
t.Errorf("Content-Type header = %q; want %q", got, want)
assert.Fail(t, "Content-Type header = %q; want %q", got, want)
}
body, err := io.ReadAll(r.Body)
if err != nil {
r.Body.Close()
}
if err != nil {
t.Errorf("failed reading request body: %s.", err)
assert.Fail(t, "failed reading request body: %s.", err)
}
if string(body) != "grant_type=client_credentials&scope=scope1+scope2" {
t.Errorf("payload = %q; want %q", string(body), "grant_type=client_credentials&scope=scope1+scope2")
assert.Fail(t, "payload = %q; want %q", string(body), "grant_type=client_credentials&scope=scope1+scope2")
}
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
w.Write([]byte("access_token=90d64460d14870c08c81352a05dedd3465940a7c&token_type=bearer"))
}))
defer ts.Close()
defer t.Cleanup(func() { ts.Close() })

cfg := apidef.ClientCredentials{
ClientAuthData: apidef.ClientAuthData{
Expand Down Expand Up @@ -100,30 +100,30 @@ func TestPasswordCredentialsTokenRequest(t *testing.T) {
defer r.Body.Close()
expected := "/token"
if r.URL.String() != expected {
t.Errorf("URL = %q; want %q", r.URL, expected)
assert.Fail(t, "URL = %q; want %q", r.URL, expected)
}
headerAuth := r.Header.Get("Authorization")
expected = "Basic Q0xJRU5UX0lEOkNMSUVOVF9TRUNSRVQ="
if headerAuth != expected {
t.Errorf("Authorization header = %q; want %q", headerAuth, expected)
assert.Fail(t, "Authorization header = %q; want %q", headerAuth, expected)
}
headerContentType := r.Header.Get("Content-Type")
expected = "application/x-www-form-urlencoded"
if headerContentType != expected {
t.Errorf("Content-Type header = %q; want %q", headerContentType, expected)
assert.Fail(t, "Content-Type header = %q; want %q", headerContentType, expected)
}
body, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("Failed reading request body: %s.", err)
assert.Fail(t, "Failed reading request body: %s.", err)
}
expected = "grant_type=password&password=password1&scope=scope1+scope2&username=user1"
if string(body) != expected {
t.Errorf("res.Body = %q; want %q", string(body), expected)
assert.Fail(t, "payload = %q; want %q", string(body), expected)
}
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
w.Write([]byte("access_token=90d64460d14870c08c81352a05dedd3465940a7c&scope=user&token_type=bearer"))

Check failure on line 124 in gateway/mw_oauth2_auth_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `w.Write` is not checked (errcheck)
}))
defer ts.Close()
defer t.Cleanup(func() { ts.Close() })

cfg := apidef.PasswordAuthentication{
Enabled: true,
Expand Down

0 comments on commit bed31cb

Please sign in to comment.