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

Method TestClientCredsProviderFailure

credentials/xds/xds_client_test.go:314–349  ·  view source on GitHub ↗

TestClientCredsProviderFailure verifies the cases where an expected certificate provider is missing in the HandshakeInfo value in the context.

(t *testing.T)

Source from the content-addressed store, hash-verified

312// TestClientCredsProviderFailure verifies the cases where an expected
313// certificate provider is missing in the HandshakeInfo value in the context.
314func (s) TestClientCredsProviderFailure(t *testing.T) {
315 opts := ClientOptions{FallbackCreds: makeFallbackClientCreds(t)}
316 creds, err := NewClientCredentials(opts)
317 if err != nil {
318 t.Fatalf("NewClientCredentials(%v) failed: %v", opts, err)
319 }
320
321 tests := []struct {
322 desc string
323 rootProvider certprovider.Provider
324 identityProvider certprovider.Provider
325 wantErr string
326 }{
327 {
328 desc: "erroring root provider",
329 rootProvider: &fakeProvider{err: errors.New("root provider error")},
330 wantErr: "root provider error",
331 },
332 {
333 desc: "erroring identity provider",
334 rootProvider: &fakeProvider{km: &certprovider.KeyMaterial{}},
335 identityProvider: &fakeProvider{err: errors.New("identity provider error")},
336 wantErr: "identity provider error",
337 },
338 }
339 for _, test := range tests {
340 t.Run(test.desc, func(t *testing.T) {
341 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
342 defer cancel()
343 ctx = newTestContextWithHandshakeInfo(ctx, test.rootProvider, test.identityProvider, "", "", false)
344 if _, _, err := creds.ClientHandshake(ctx, authority, nil); err == nil || !strings.Contains(err.Error(), test.wantErr) {
345 t.Fatalf("ClientHandshake() returned error: %q, wantErr: %q", err, test.wantErr)
346 }
347 })
348 }
349}
350
351// TestClientCredsSuccess verifies successful client handshake cases.
352func (s) TestClientCredsSuccess(t *testing.T) {

Callers

nothing calls this directly

Calls 6

makeFallbackClientCredsFunction · 0.85
NewClientCredentialsFunction · 0.85
FatalfMethod · 0.65
ClientHandshakeMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected