Add TestFailFastRPCErrorOnBadCertificates

This commit is contained in:
Menghan Li
2016-07-18 11:58:38 -07:00
parent 558ecfb3a6
commit b41c9e8e14

View File

@ -490,13 +490,16 @@ func (te *test) clientConn() *grpc.ClientConn {
grpc.WithDecompressor(grpc.NewGZIPDecompressor()), grpc.WithDecompressor(grpc.NewGZIPDecompressor()),
) )
} }
if te.e.security == "tls" { switch te.e.security {
case "tls":
creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com") creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com")
if err != nil { if err != nil {
te.t.Fatalf("Failed to load credentials: %v", err) te.t.Fatalf("Failed to load credentials: %v", err)
} }
opts = append(opts, grpc.WithTransportCredentials(creds)) opts = append(opts, grpc.WithTransportCredentials(creds))
} else { case "clientAlwaysFailCred":
opts = append(opts, grpc.WithTransportCredentials(clientAlwaysFailCred{}))
default:
opts = append(opts, grpc.WithInsecure()) opts = append(opts, grpc.WithInsecure())
} }
var err error var err error
@ -2286,7 +2289,7 @@ func (c clientAlwaysFailCred) Info() credentials.ProtocolInfo {
func TestDialWithBlockErrorOnBadCertificates(t *testing.T) { func TestDialWithBlockErrorOnBadCertificates(t *testing.T) {
te := newTest(t, env{name: "bad-cred", network: "tcp", security: "clientAlwaysFailCred"}) te := newTest(t, env{name: "bad-cred", network: "tcp", security: "clientAlwaysFailCred"})
te.startServer() te.startServer(&testServer{security: "clientAlwaysFailCred"})
defer te.tearDown() defer te.tearDown()
var ( var (
@ -2300,6 +2303,18 @@ func TestDialWithBlockErrorOnBadCertificates(t *testing.T) {
} }
} }
func TestFailFastRPCErrorOnBadCertificates(t *testing.T) {
te := newTest(t, env{name: "bad-cred", network: "tcp", security: "clientAlwaysFailCred"})
te.startServer(&testServer{security: "clientAlwaysFailCred"})
defer te.tearDown()
cc := te.clientConn()
tc := testpb.NewTestServiceClient(cc)
if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); !strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) {
te.t.Fatalf("Dial(%q) = %v, want err.Error() contains %q", te.srvAddr, err, clientAlwaysFailCredErrorMsg)
}
}
// interestingGoroutines returns all goroutines we care about for the purpose // interestingGoroutines returns all goroutines we care about for the purpose
// of leak checking. It excludes testing or runtime ones. // of leak checking. It excludes testing or runtime ones.
func interestingGoroutines() (gs []string) { func interestingGoroutines() (gs []string) {