TestFileWatcherCRLProviderConfig checks creation of FileWatcherCRLProvider, and the validation of FileWatcherOptions configuration. The configurations include empty one, non existing CRLDirectory, invalid RefreshDuration, and the correct one.
(t *testing.T)
| 92 | // and the validation of FileWatcherOptions configuration. The configurations include empty |
| 93 | // one, non existing CRLDirectory, invalid RefreshDuration, and the correct one. |
| 94 | func (s) TestFileWatcherCRLProviderConfig(t *testing.T) { |
| 95 | if _, err := NewFileWatcherCRLProvider(FileWatcherOptions{}); err == nil { |
| 96 | t.Fatalf("Empty FileWatcherOptions should not be allowed") |
| 97 | } |
| 98 | if _, err := NewFileWatcherCRLProvider(FileWatcherOptions{CRLDirectory: "I_do_not_exist"}); err == nil { |
| 99 | t.Fatalf("CRLDirectory must exist") |
| 100 | } |
| 101 | defaultProvider, err := NewFileWatcherCRLProvider(FileWatcherOptions{CRLDirectory: testdata.Path("crl")}) |
| 102 | if err != nil { |
| 103 | t.Fatal("Unexpected error:", err) |
| 104 | } |
| 105 | if defaultProvider.opts.RefreshDuration != defaultCRLRefreshDuration { |
| 106 | t.Fatalf("RefreshDuration for defaultCRLRefreshDuration case is not properly updated by validate() func") |
| 107 | } |
| 108 | defaultProvider.Close() |
| 109 | tooFastRefreshProvider, err := NewFileWatcherCRLProvider(FileWatcherOptions{ |
| 110 | CRLDirectory: testdata.Path("crl"), |
| 111 | RefreshDuration: 5 * time.Second, |
| 112 | }) |
| 113 | if err != nil { |
| 114 | t.Fatal("Unexpected error:", err) |
| 115 | } |
| 116 | if tooFastRefreshProvider.opts.RefreshDuration != minCRLRefreshDuration { |
| 117 | t.Fatalf("RefreshDuration for minCRLRefreshDuration case is not properly updated by validate() func") |
| 118 | } |
| 119 | tooFastRefreshProvider.Close() |
| 120 | |
| 121 | customCallback := func(err error) { |
| 122 | t.Logf("Custom error message: %v", err) |
| 123 | } |
| 124 | regularProvider, err := NewFileWatcherCRLProvider(FileWatcherOptions{ |
| 125 | CRLDirectory: testdata.Path("crl"), |
| 126 | RefreshDuration: 2 * time.Hour, |
| 127 | CRLReloadingFailedCallback: customCallback, |
| 128 | }) |
| 129 | if err != nil { |
| 130 | t.Fatal("Unexpected error while creating regular FileWatcherCRLProvider:", err) |
| 131 | } |
| 132 | if regularProvider.opts.RefreshDuration != 2*time.Hour { |
| 133 | t.Fatalf("Valid refreshDuration was incorrectly updated by validate() func") |
| 134 | } |
| 135 | regularProvider.Close() |
| 136 | } |
| 137 | |
| 138 | // TestFileWatcherCRLProvider tests how FileWatcherCRLProvider handles the major |
| 139 | // four cases for CRL checks. It scans the CRLs under crl directory to populate |