This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
-
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.
Merge pull request #445 from nspcc-dev/client-ret-conn-error
- Loading branch information
Showing
2 changed files
with
40 additions
and
4 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") | ||
}) | ||
} |