initializeProvider performs setup steps common to all tests (except the one which uses symlinks).
(t *testing.T, testName string, useSPIFFEBundle bool)
| 210 | // initializeProvider performs setup steps common to all tests (except the one |
| 211 | // which uses symlinks). |
| 212 | func initializeProvider(t *testing.T, testName string, useSPIFFEBundle bool) (string, certprovider.Provider, *testutils.Channel, func()) { |
| 213 | t.Helper() |
| 214 | |
| 215 | // Override the newDistributor to one which pushes on a channel that we |
| 216 | // can block on. |
| 217 | origDistributorFunc := newDistributor |
| 218 | distCh := testutils.NewChannel() |
| 219 | d := newWrappedDistributor(distCh) |
| 220 | newDistributor = func() distributor { return d } |
| 221 | |
| 222 | // Create a new provider to watch the files in tmpdir. |
| 223 | dir := createTmpDirWithFiles(t, testName+"*", "x509/client1_cert.pem", "x509/client1_key.pem", "x509/client_ca_cert.pem", "spiffe/spiffebundle.json") |
| 224 | opts := Options{ |
| 225 | CertFile: path.Join(dir, certFile), |
| 226 | KeyFile: path.Join(dir, keyFile), |
| 227 | RootFile: path.Join(dir, rootFile), |
| 228 | RefreshDuration: defaultTestRefreshDuration, |
| 229 | } |
| 230 | if useSPIFFEBundle { |
| 231 | opts.SPIFFEBundleMapFile = path.Join(dir, spiffeBundleFile) |
| 232 | } |
| 233 | prov, err := NewProvider(opts) |
| 234 | if err != nil { |
| 235 | t.Fatalf("NewProvider(%+v) failed: %v", opts, err) |
| 236 | } |
| 237 | |
| 238 | // Make sure the provider picks up the files and pushes the key material on |
| 239 | // to the distributors. |
| 240 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 241 | defer cancel() |
| 242 | for i := 0; i < 2; i++ { |
| 243 | // Since we have root and identity certs, we need to make sure the |
| 244 | // update is pushed on both of them. |
| 245 | if _, err := distCh.Receive(ctx); err != nil { |
| 246 | t.Fatalf("Timeout waiting for provider to read files and push key material to distributor: %v", err) |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return dir, prov, distCh, func() { |
| 251 | newDistributor = origDistributorFunc |
| 252 | prov.Close() |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // TestProvider_NoUpdate tests the case where a file watcher plugin is created |
| 257 | // successfully, and the underlying files do not change. Verifies that the |
no test coverage detected