(t *testing.T)
| 41 | } |
| 42 | |
| 43 | func 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 | |
| 72 | func loadX509Cert(t *testing.T, filePath string) *x509.Certificate { |
| 73 | t.Helper() |
nothing calls this directly
no test coverage detected