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

Function TestKnownSPIFFEBundle

internal/credentials/spiffe/spiffe_test.go:43–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41}
42
43func TestKnownSPIFFEBundle(t *testing.T) {
44 spiffeBundleFile := testdata.Path("spiffe/spiffebundle.json")
45 spiffeBundleBytes := loadFileBytes(t, spiffeBundleFile)
46 bundles, err := BundleMapFromBytes(spiffeBundleBytes)
47 if err != nil {
48 t.Fatalf("BundleMapFromBytes(%v) error during parsing: %v", spiffeBundleFile, err)
49 }
50 const wantBundleSize = 2
51 if len(bundles) != wantBundleSize {
52 t.Fatalf("BundleMapFromBytes(%v) did not parse correct bundle length. got %v want %v", spiffeBundleFile, len(bundles), wantBundleSize)
53 }
54 if bundles["example.com"] == nil {
55 t.Fatalf("BundleMapFromBytes(%v) got no bundle for example.com", spiffeBundleFile)
56 }
57 if bundles["test.example.com"] == nil {
58 t.Fatalf("BundleMapFromBytes(%v) got no bundle for test.example.com", spiffeBundleFile)
59 }
60
61 wantExampleComCert := loadX509Cert(t, testdata.Path("spiffe/spiffe_cert.pem"))
62 wantTestExampleComCert := loadX509Cert(t, testdata.Path("spiffe/server1_spiffe.pem"))
63 if !bundles["example.com"].X509Authorities()[0].Equal(wantExampleComCert) {
64 t.Errorf("BundleMapFromBytes(%v) parsed wrong cert for example.com.", spiffeBundleFile)
65 }
66 if !bundles["test.example.com"].X509Authorities()[0].Equal(wantTestExampleComCert) {
67 t.Errorf("BundleMapFromBytes(%v) parsed wrong cert for test.example.com", spiffeBundleFile)
68 }
69
70}
71
72func loadX509Cert(t *testing.T, filePath string) *x509.Certificate {
73 t.Helper()

Callers

nothing calls this directly

Calls 7

PathFunction · 0.92
loadFileBytesFunction · 0.85
BundleMapFromBytesFunction · 0.85
loadX509CertFunction · 0.85
FatalfMethod · 0.65
EqualMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected