@@ -111,7 +111,11 @@ func (tss *testServiceServer) EmptyCall(context.Context, *testpb.Empty) (*testpb
111
111
func invokeEmptyCall (address string , dialOptions []grpc.DialOption ) (* testpb.Empty , error ) {
112
112
113
113
//add DialOptions
114
- dialOptions = append (dialOptions , grpc .WithBlock ())
114
+ dialOptions = append (
115
+ dialOptions ,
116
+ grpc .WithDefaultCallOptions (grpc .FailFast (true )),
117
+ grpc .FailOnNonTempDialError (true ),
118
+ grpc .WithBlock ())
115
119
ctx := context .Background ()
116
120
ctx , _ = context .WithTimeout (ctx , timeout )
117
121
//create GRPC client conn
@@ -194,6 +198,7 @@ func (org *testOrg) testServers(port int, clientRootCAs [][]byte) []testServer {
194
198
testServer := testServer {
195
199
fmt .Sprintf ("localhost:%d" , port + i ),
196
200
comm.ServerConfig {
201
+ ConnectionTimeout : 250 * time .Millisecond ,
197
202
SecOpts : & comm.SecureOptions {
198
203
UseTLS : true ,
199
204
Certificate : serverCert .certPEM ,
@@ -575,6 +580,7 @@ func TestNewSecureGRPCServer(t *testing.T) {
575
580
t .Parallel ()
576
581
testAddress := "localhost:9055"
577
582
srv , err := comm .NewGRPCServer (testAddress , comm.ServerConfig {
583
+ ConnectionTimeout : 250 * time .Millisecond ,
578
584
SecOpts : & comm.SecureOptions {
579
585
UseTLS : true ,
580
586
Certificate : []byte (selfSignedCertPEM ),
@@ -633,18 +639,22 @@ func TestNewSecureGRPCServer(t *testing.T) {
633
639
t .Log ("GRPC client successfully invoked the EmptyCall service: " + testAddress )
634
640
}
635
641
636
- // ensure that TLS 1.2 in required / enforced
637
- for _ , tlsVersion := range []uint16 {tls .VersionSSL30 , tls .VersionTLS10 , tls .VersionTLS11 } {
638
- _ , err = invokeEmptyCall (testAddress ,
639
- []grpc.DialOption {grpc .WithTransportCredentials (
640
- credentials .NewTLS (& tls.Config {
641
- RootCAs : certPool ,
642
- MinVersion : tlsVersion ,
643
- MaxVersion : tlsVersion ,
644
- }))})
645
- t .Logf ("TLSVersion [%d] failed with [%s]" , tlsVersion , err )
646
- assert .Error (t , err , "Should not have been able to connect with TLS version < 1.2" )
647
- assert .Contains (t , err .Error (), "protocol version not supported" )
642
+ tlsVersions := []string {"SSL30" , "TLS10" , "TLS11" }
643
+ for counter , tlsVersion := range []uint16 {tls .VersionSSL30 , tls .VersionTLS10 , tls .VersionTLS11 } {
644
+ tlsVersion := tlsVersion
645
+ t .Run (tlsVersions [counter ], func (t * testing.T ) {
646
+ t .Parallel ()
647
+ _ , err = invokeEmptyCall (testAddress ,
648
+ []grpc.DialOption {grpc .WithTransportCredentials (
649
+ credentials .NewTLS (& tls.Config {
650
+ RootCAs : certPool ,
651
+ MinVersion : tlsVersion ,
652
+ MaxVersion : tlsVersion ,
653
+ }))})
654
+ t .Logf ("TLSVersion [%d] failed with [%s]" , tlsVersion , err )
655
+ assert .Error (t , err , "Should not have been able to connect with TLS version < 1.2" )
656
+ assert .Contains (t , err .Error (), "context deadline exceeded" )
657
+ })
648
658
}
649
659
}
650
660
@@ -923,7 +933,11 @@ func runMutualAuth(t *testing.T, servers []testServer, trustedClients, unTrusted
923
933
//loop through all the untrusted clients
924
934
for k := 0 ; k < len (unTrustedClients ); k ++ {
925
935
//invoke the EmptyCall service
926
- _ , err = invokeEmptyCall (servers [i ].address , []grpc.DialOption {grpc .WithTransportCredentials (credentials .NewTLS (unTrustedClients [k ]))})
936
+ _ , err = invokeEmptyCall (
937
+ servers [i ].address ,
938
+ []grpc.DialOption {
939
+ grpc .WithTransportCredentials (
940
+ credentials .NewTLS (unTrustedClients [k ]))})
927
941
//we expect failure from untrusted clients
928
942
if err != nil {
929
943
t .Logf ("Untrusted client%d was correctly rejected by %s" , k , servers [i ].address )
@@ -1413,8 +1427,12 @@ func TestKeepaliveClientResponse(t *testing.T) {
1413
1427
defer srv .Stop ()
1414
1428
1415
1429
// test that connection does not close with response to ping
1416
- clientTransport , err := transport .NewClientTransport (context .Background (),
1417
- transport.TargetInfo {Addr : testAddress }, transport.ConnectOptions {})
1430
+ clientTransport , err := transport .NewClientTransport (
1431
+ context .Background (),
1432
+ context .Background (),
1433
+ transport.TargetInfo {Addr : testAddress },
1434
+ transport.ConnectOptions {},
1435
+ func () {})
1418
1436
assert .NoError (t , err , "Unexpected error creating client transport" )
1419
1437
defer clientTransport .Close ()
1420
1438
// sleep past keepalive timeout
@@ -1469,7 +1487,7 @@ func TestUpdateTLSCert(t *testing.T) {
1469
1487
// bootstrap TLS certificate has a SAN of "notlocalhost" so it should fail
1470
1488
err = probeServer ()
1471
1489
assert .Error (t , err )
1472
- assert .Contains (t , err .Error (), "certificate is valid for notlocalhost.org1.example.com, notlocalhost, not localhost " )
1490
+ assert .Contains (t , err .Error (), "context deadline exceeded " )
1473
1491
1474
1492
// new TLS certificate has a SAN of "localhost" so it should succeed
1475
1493
certPath := filepath .Join ("testdata" , "dynamic_cert_update" , "localhost" , "server.crt" )
@@ -1488,7 +1506,7 @@ func TestUpdateTLSCert(t *testing.T) {
1488
1506
srv .SetServerCertificate (tlsCert )
1489
1507
err = probeServer ()
1490
1508
assert .Error (t , err )
1491
- assert .Contains (t , err .Error (), "certificate is valid for notlocalhost.org1.example.com, notlocalhost, not localhost " )
1509
+ assert .Contains (t , err .Error (), "context deadline exceeded " )
1492
1510
}
1493
1511
1494
1512
func TestCipherSuites (t * testing.T ) {
0 commit comments