MCPcopy
hub / github.com/grpc/grpc-go / TestCredentialsMisuse

Method TestCredentialsMisuse

clientconn_test.go:363–392  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

361}
362
363func (s) TestCredentialsMisuse(t *testing.T) {
364 // Use of no transport creds and no creds bundle must fail.
365 if _, err := NewClient("passthrough:///Non-Existent.Server:80"); err != errNoTransportSecurity {
366 t.Fatalf("grpc.NewClient() failed with error: %v, want: %v", err, errNoTransportSecurity)
367 }
368
369 // Use of both transport creds and creds bundle must fail.
370 creds, err := credentials.NewClientTLSFromFile(testdata.Path("x509/server_ca_cert.pem"), "x.test.example.com")
371 if err != nil {
372 t.Fatalf("Failed to create authenticator %v", err)
373 }
374 dopts := []DialOption{
375 WithTransportCredentials(creds),
376 WithCredentialsBundle(&fakeBundleCreds{transportCreds: creds}),
377 }
378 if _, err := NewClient("passthrough:///Non-Existent.Server:80", dopts...); err != errTransportCredsAndBundle {
379 t.Fatalf("grpc.NewClient() failed with error: %v, want: %v", err, errTransportCredsAndBundle)
380 }
381
382 // Use of perRPC creds requiring transport security over an insecure
383 // transport must fail.
384 if _, err := NewClient("passthrough:///Non-Existent.Server:80", WithPerRPCCredentials(securePerRPCCredentials{}), WithTransportCredentials(insecure.NewCredentials())); err != errTransportCredentialsMissing {
385 t.Fatalf("grpc.NewClient() failed with error: %v, want: %v", err, errTransportCredentialsMissing)
386 }
387
388 // Use of a creds bundle with nil transport credentials must fail.
389 if _, err := NewClient("passthrough:///Non-Existent.Server:80", WithCredentialsBundle(&fakeBundleCreds{})); err != errNoTransportCredsInBundle {
390 t.Fatalf("grpc.NewClient() failed with error: %v, want: %v", err, errTransportCredsAndBundle)
391 }
392}
393
394func (s) TestWithBackoffConfigDefault(t *testing.T) {
395 testBackoffConfigSet(t, internalbackoff.DefaultExponential)

Callers

nothing calls this directly

Calls 8

NewClientTLSFromFileFunction · 0.92
PathFunction · 0.92
NewCredentialsFunction · 0.92
WithTransportCredentialsFunction · 0.85
WithCredentialsBundleFunction · 0.85
WithPerRPCCredentialsFunction · 0.85
NewClientFunction · 0.70
FatalfMethod · 0.65

Tested by

no test coverage detected