@@ -24,6 +24,7 @@ import (
2424 "github.com/stretchr/testify/assert"
2525 "github.com/stretchr/testify/require"
2626 "google.golang.org/grpc"
27+ "google.golang.org/protobuf/types/known/emptypb"
2728)
2829
2930func TestClientReconnectsAfterServerRestart (t * testing.T ) {
@@ -313,6 +314,23 @@ func TestClient_tlsConfig_NonexistentCACertPath(t *testing.T) {
313314 assert .Contains (t , err .Error (), "failed to access CA certificate" )
314315}
315316
317+ func TestClient_Connect_SanitizesTLSConfigError (t * testing.T ) {
318+ client := & Client {
319+ config : & config.CentralConfig {
320+ URL : "central.stackrox.io:8443" ,
321+ AuthType : config .AuthTypeStatic ,
322+ APIToken : "dummy" ,
323+ CACertPath : "/nonexistent/secret/path/ca.crt" ,
324+ },
325+ }
326+
327+ err := client .Connect (context .Background ())
328+ require .Error (t , err )
329+ assert .NotContains (t , err .Error (), "/nonexistent/secret/path/ca.crt" )
330+ assert .Contains (t , err .Error (), "invalid TLS configuration" )
331+ assert .Contains (t , err .Error (), "check server logs for details" )
332+ }
333+
316334// generateTestCert creates a certificate PEM with the given options, signed by the given CA.
317335// If ca/caKey are nil, the cert is self-signed.
318336func generateTestCert (
@@ -472,7 +490,7 @@ func TestClient_ConnectWithCACert_Positive(t *testing.T) {
472490
473491 // Invoke a dummy RPC to trigger the TLS handshake. The method doesn't exist,
474492 // so the server returns Unimplemented — any non-TLS error proves the handshake succeeded.
475- err = conn .Invoke (ctx , "/test.Service/Method" , nil , nil )
493+ err = conn .Invoke (ctx , "/test.Service/Method" , & emptypb. Empty {}, & emptypb. Empty {} )
476494 require .Error (t , err )
477495
478496 // Verify the error is NOT a TLS certificate verification failure.
@@ -514,7 +532,7 @@ func TestClient_ConnectWithoutCACert_Negative(t *testing.T) {
514532
515533 // Invoke triggers the actual TLS handshake. Because no CA cert is provided and
516534 // InsecureSkipTLSVerify is false, the self-signed server cert cannot be verified.
517- err = conn .Invoke (ctx , "/test.Service/Method" , nil , nil )
535+ err = conn .Invoke (ctx , "/test.Service/Method" , & emptypb. Empty {}, & emptypb. Empty {} )
518536 require .Error (t , err )
519537
520538 // Verify the error IS a TLS certificate verification failure.
0 commit comments