What changed, and why it matters
This commit only reformats an existing test file. It wraps long lines to 80 columns, splits nested code into separate variables, and adjusts whitespace. No production code was changed, and no security behavior is altered.
No action required. This is a non-functional style-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure formatting/style change in rpcclient/disableauth_test.go. It extracts inline http.HandlerFunc literals into a handler variable, wraps strings and function calls to 80 columns, and renames a temporary variable. The test logic, assertions, and the DisableAuth feature behavior remain identical.
Changed components
rpcclient/disableauth_test.goInspect captured patch +83 / −52
diff --git a/rpcclient/disableauth_test.go b/rpcclient/disableauth_test.go
index 4ef5c28..e35a888 100644
--- a/rpcclient/disableauth_test.go
+++ b/rpcclient/disableauth_test.go
@@ -19,20 +19,27 @@ func TestDisableAuth(t *testing.T) {
t.Parallel()
var gotAuth string
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- gotAuth = r.Header.Get("Authorization")
- // Return a valid JSON-RPC response so the client doesn't retry.
- w.Header().Set("Content-Type", "application/json")
- w.Write([]byte(`{"result":null,"error":null,"id":1}`))
- }))
+ handler := http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ gotAuth = r.Header.Get("Authorization")
+
+ // Return a valid JSON-RPC response so the client
+ // doesn't retry.
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(
+ `{"result":null,"error":null,"id":1}`,
+ ))
+ },
+ )
+ srv := httptest.NewServer(handler)
defer srv.Close()
addr := strings.TrimPrefix(srv.URL, "http://")
client, err := New(&ConnConfig{
- Host: addr,
+ Host: addr,
HTTPPostMode: true,
- DisableAuth: true,
- DisableTLS: true,
+ DisableAuth: true,
+ DisableTLS: true,
}, nil)
require.NoError(t, err)
defer client.Shutdown()
@@ -40,32 +47,40 @@ func TestDisableAuth(t *testing.T) {
// The client is now connected; issue a simple request to trigger
// handleSendPostMessage.
_, err = client.RawRequest("getblockchaininfo", nil)
- // We don't care if the RPC itself errors — we only care about
+ // We don't care if the RPC itself errors. We only care about
// the Authorization header.
_ = err
- require.Empty(t, gotAuth, "Authorization header should be empty when DisableAuth is true")
+ require.Empty(
+ t, gotAuth,
+ "Authorization header should be empty when DisableAuth is true",
+ )
})
t.Run("DisableAuth false includes Authorization header", func(t *testing.T) {
t.Parallel()
var gotAuth string
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- gotAuth = r.Header.Get("Authorization")
- w.Header().Set("Content-Type", "application/json")
- w.Write([]byte(`{"result":null,"error":null,"id":1}`))
- }))
+ handler := http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ gotAuth = r.Header.Get("Authorization")
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(
+ `{"result":null,"error":null,"id":1}`,
+ ))
+ },
+ )
+ srv := httptest.NewServer(handler)
defer srv.Close()
addr := strings.TrimPrefix(srv.URL, "http://")
client, err := New(&ConnConfig{
- Host: addr,
+ Host: addr,
HTTPPostMode: true,
- DisableAuth: false,
- DisableTLS: true,
- User: "testuser",
- Pass: "testpass",
+ DisableAuth: false,
+ DisableTLS: true,
+ User: "testuser",
+ Pass: "testpass",
}, nil)
require.NoError(t, err)
defer client.Shutdown()
@@ -73,37 +88,53 @@ func TestDisableAuth(t *testing.T) {
_, err = client.RawRequest("getblockchaininfo", nil)
_ = err
- expected := "Basic " + base64.StdEncoding.EncodeToString([]byte("testuser:testpass"))
- require.Equal(t, expected, gotAuth, "Authorization header should be set when DisableAuth is false")
+ login := []byte("testuser:testpass")
+ expected := "Basic " + base64.StdEncoding.EncodeToString(login)
+ require.Equal(
+ t, expected, gotAuth,
+ "Authorization header should be set when DisableAuth is false",
+ )
})
- t.Run("DisableAuth default (zero value) includes Authorization header", func(t *testing.T) {
- t.Parallel()
-
- var gotAuth string
- srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- gotAuth = r.Header.Get("Authorization")
- w.Header().Set("Content-Type", "application/json")
- w.Write([]byte(`{"result":null,"error":null,"id":1}`))
- }))
- defer srv.Close()
-
- addr := strings.TrimPrefix(srv.URL, "http://")
- client, err := New(&ConnConfig{
- Host: addr,
- HTTPPostMode: true,
- // DisableAuth left as default (false)
- DisableTLS: true,
- User: "myuser",
- Pass: "mypass",
- }, nil)
- require.NoError(t, err)
- defer client.Shutdown()
-
- _, err = client.RawRequest("getblockchaininfo", nil)
- _ = err
-
- expected := "Basic " + base64.StdEncoding.EncodeToString([]byte("myuser:mypass"))
- require.Equal(t, expected, gotAuth, "Authorization header should be set by default (DisableAuth is false)")
- })
+ t.Run(
+ "DisableAuth default (zero value) includes Authorization header",
+ func(t *testing.T) {
+ t.Parallel()
+
+ var gotAuth string
+ handler := http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ gotAuth = r.Header.Get("Authorization")
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(
+ `{"result":null,"error":null,"id":1}`,
+ ))
+ },
+ )
+ srv := httptest.NewServer(handler)
+ defer srv.Close()
+
+ addr := strings.TrimPrefix(srv.URL, "http://")
+ client, err := New(&ConnConfig{
+ Host: addr,
+ HTTPPostMode: true,
+ DisableTLS: true,
+ User: "myuser",
+ Pass: "mypass",
+ }, nil)
+ require.NoError(t, err)
+ defer client.Shutdown()
+
+ _, err = client.RawRequest("getblockchaininfo", nil)
+ _ = err
+
+ login := []byte("myuser:mypass")
+ expected := "Basic " +
+ base64.StdEncoding.EncodeToString(login)
+ require.Equal(
+ t, expected, gotAuth,
+ "Authorization header should be set by default",
+ )
+ },
+ )
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.