-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc/client: Add unit test for TLS handshake failure
Inspired by nspcc-dev/neofs-node#2561. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
- Loading branch information
1 parent
fb2ed14
commit a4b7d73
Showing
2 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"net" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/test/bufconn" | ||
) | ||
|
||
func TestClient_Init(t *testing.T) { | ||
t.Run("TLS handshake failure", func(t *testing.T) { | ||
lis := bufconn.Listen(1024) // size does not matter in this test | ||
|
||
srv := grpc.NewServer() | ||
t.Cleanup(srv.Stop) | ||
go func() { _ = srv.Serve(lis) }() | ||
|
||
c := New(WithNetworkURIAddress("grpcs://any:54321", new(tls.Config))...) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) | ||
t.Cleanup(cancel) | ||
|
||
err := c.openGRPCConn(ctx, grpc.WithContextDialer(func(ctx context.Context, s string) (net.Conn, error) { | ||
return lis.DialContext(ctx) | ||
})) | ||
// error is not wrapped properly, so we can do nothing more to check it. | ||
// Text from stdlib tls.Conn.HandshakeContext. | ||
require.ErrorContains(t, err, "first record does not look like a TLS handshake") | ||
}) | ||
} |