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

Method TestStoreMultipleProviders

credentials/tls/certprovider/store_test.go:359–400  ·  view source on GitHub ↗

TestStoreMultipleProviders creates providers of different types and makes sure closing of one does not affect the other.

(t *testing.T)

Source from the content-addressed store, hash-verified

357// TestStoreMultipleProviders creates providers of different types and makes
358// sure closing of one does not affect the other.
359func (s) TestStoreMultipleProviders(t *testing.T) {
360 opts := BuildOptions{CertName: "foo"}
361 prov1 := createProvider(t, fakeProvider1Name, fakeConfig, opts)
362 defer prov1.Close()
363 // Our fakeProviderBuilder pushes newly created providers on a channel. Grab
364 // the fake provider from that channel.
365 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
366 defer cancel()
367 p1, err := fpb1.providerChan.Receive(ctx)
368 if err != nil {
369 t.Fatalf("Timeout when expecting certProvider %q to be created", fakeProvider1Name)
370 }
371 fakeProv1 := p1.(*fakeProvider)
372
373 prov2 := createProvider(t, fakeProvider2Name, fakeConfig, opts)
374 defer prov2.Close()
375 // Grab the second provider from the channel.
376 p2, err := fpb2.providerChan.Receive(ctx)
377 if err != nil {
378 t.Fatalf("Timeout when expecting certProvider %q to be created", fakeProvider2Name)
379 }
380 fakeProv2 := p2.(*fakeProvider)
381
382 // Push the key material into both providers and verify that the
383 // readers return the appropriate key material.
384 km1 := loadKeyMaterials(t, "x509/server1_cert.pem", "x509/server1_key.pem", "x509/client_ca_cert.pem")
385 fakeProv1.newKeyMaterial(km1, nil)
386 km2 := loadKeyMaterials(t, "x509/server2_cert.pem", "x509/server2_key.pem", "x509/client_ca_cert.pem")
387 fakeProv2.newKeyMaterial(km2, nil)
388 if err := readAndVerifyKeyMaterial(ctx, prov1, km1); err != nil {
389 t.Fatal(err)
390 }
391 if err := readAndVerifyKeyMaterial(ctx, prov2, km2); err != nil {
392 t.Fatal(err)
393 }
394
395 // Close one of the providers and verify that the other one is not affected.
396 prov1.Close()
397 if err := readAndVerifyKeyMaterial(ctx, prov2, km2); err != nil {
398 t.Fatal(err)
399 }
400}

Callers

nothing calls this directly

Calls 8

createProviderFunction · 0.85
loadKeyMaterialsFunction · 0.85
readAndVerifyKeyMaterialFunction · 0.85
newKeyMaterialMethod · 0.80
CloseMethod · 0.65
FatalfMethod · 0.65
FatalMethod · 0.65
ReceiveMethod · 0.45

Tested by

no test coverage detected