From bed31cb23ac5efee557afea207cfd0f4da7ec83d Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 22 Oct 2024 11:00:05 +0300 Subject: [PATCH] TT-13185, implemented CR feedback 2 --- gateway/mw_oauth2_auth_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gateway/mw_oauth2_auth_test.go b/gateway/mw_oauth2_auth_test.go index 0176074cd4d..83e1f0dbd1c 100644 --- a/gateway/mw_oauth2_auth_test.go +++ b/gateway/mw_oauth2_auth_test.go @@ -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{ @@ -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")) })) - defer ts.Close() + defer t.Cleanup(func() { ts.Close() }) cfg := apidef.PasswordAuthentication{ Enabled: true,