grpc connection management no longer yields same errors from dial; also fix fmt issue in error message
This commit is contained in:
parent
9dfaded6cf
commit
45e17ae10b
|
|
@ -685,7 +685,7 @@ func fetchAllExtensions(source DescriptorSource, ext *dynamic.ExtensionRegistry,
|
|||
fds, err := source.AllExtensionsForType(msgTypeName)
|
||||
for _, fd := range fds {
|
||||
if err = ext.AddExtension(fd); err != nil {
|
||||
return fmt.Errorf("could not register extension %d of type %s: %v", fd.GetFullyQualifiedName(), msgTypeName, err)
|
||||
return fmt.Errorf("could not register extension %s of type %s: %v", fd.GetFullyQualifiedName(), msgTypeName, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,9 +142,6 @@ func TestBrokenTLS_ServerPlainText(t *testing.T) {
|
|||
t.Fatal("expecting TLS failure setting up server and client")
|
||||
e.Close()
|
||||
}
|
||||
if !strings.Contains(err.Error(), "first record does not look like a TLS handshake") {
|
||||
t.Fatalf("expecting TLS handshake failure, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrokenTLS_ServerUsesWrongCert(t *testing.T) {
|
||||
|
|
@ -162,9 +159,6 @@ func TestBrokenTLS_ServerUsesWrongCert(t *testing.T) {
|
|||
t.Fatal("expecting TLS failure setting up server and client")
|
||||
e.Close()
|
||||
}
|
||||
if !strings.Contains(err.Error(), "certificate is valid for") {
|
||||
t.Fatalf("expecting TLS certificate error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrokenTLS_ClientHasExpiredCert(t *testing.T) {
|
||||
|
|
@ -182,9 +176,6 @@ func TestBrokenTLS_ClientHasExpiredCert(t *testing.T) {
|
|||
t.Fatal("expecting TLS failure setting up server and client")
|
||||
e.Close()
|
||||
}
|
||||
if !strings.Contains(err.Error(), "bad certificate") {
|
||||
t.Fatalf("expecting TLS certificate error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrokenTLS_ServerHasExpiredCert(t *testing.T) {
|
||||
|
|
@ -202,9 +193,6 @@ func TestBrokenTLS_ServerHasExpiredCert(t *testing.T) {
|
|||
t.Fatal("expecting TLS failure setting up server and client")
|
||||
e.Close()
|
||||
}
|
||||
if !strings.Contains(err.Error(), "certificate has expired or is not yet valid") {
|
||||
t.Fatalf("expecting TLS certificate expired, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrokenTLS_ClientNotTrusted(t *testing.T) {
|
||||
|
|
@ -222,9 +210,6 @@ func TestBrokenTLS_ClientNotTrusted(t *testing.T) {
|
|||
t.Fatal("expecting TLS failure setting up server and client")
|
||||
e.Close()
|
||||
}
|
||||
if !strings.Contains(err.Error(), "bad certificate") {
|
||||
t.Fatalf("expecting TLS certificate error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrokenTLS_ServerNotTrusted(t *testing.T) {
|
||||
|
|
@ -242,9 +227,6 @@ func TestBrokenTLS_ServerNotTrusted(t *testing.T) {
|
|||
t.Fatal("expecting TLS failure setting up server and client")
|
||||
e.Close()
|
||||
}
|
||||
if !strings.Contains(err.Error(), "certificate signed by unknown authority") {
|
||||
t.Fatalf("expecting TLS certificate error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrokenTLS_RequireClientCertButNonePresented(t *testing.T) {
|
||||
|
|
@ -262,9 +244,6 @@ func TestBrokenTLS_RequireClientCertButNonePresented(t *testing.T) {
|
|||
t.Fatal("expecting TLS failure setting up server and client")
|
||||
e.Close()
|
||||
}
|
||||
if !strings.Contains(err.Error(), "bad certificate") {
|
||||
t.Fatalf("expecting TLS certificate error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func simpleTest(t *testing.T, cc *grpc.ClientConn) {
|
||||
|
|
@ -297,13 +276,16 @@ func createTestServerAndClient(serverCreds, clientCreds credentials.TransportCre
|
|||
port := l.Addr().(*net.TCPAddr).Port
|
||||
go svr.Serve(l)
|
||||
|
||||
cliOpts := []grpc.DialOption{grpc.WithTimeout(2 * time.Second), grpc.WithBlock()}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
|
||||
var tlsOpt grpc.DialOption
|
||||
if clientCreds != nil {
|
||||
cliOpts = append(cliOpts, grpc.WithTransportCredentials(clientCreds))
|
||||
tlsOpt = grpc.WithTransportCredentials(clientCreds)
|
||||
} else {
|
||||
cliOpts = append(cliOpts, grpc.WithInsecure())
|
||||
tlsOpt = grpc.WithInsecure()
|
||||
}
|
||||
cc, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", port), cliOpts...)
|
||||
cc, err := grpc.DialContext(ctx, fmt.Sprintf("127.0.0.1:%d", port), grpc.WithBlock(), tlsOpt)
|
||||
if err != nil {
|
||||
return e, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue