-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crl provider: Static and FileWatcher provider implementations #6670
Changes from 1 commit
978cb44
7d032e0
cdbc298
95991d8
32e3158
00de36e
8033cab
338a7f4
d1f63fe
01afa97
401eb79
c88d12d
1feaae3
a9a84f1
5a0acad
f3c830b
4ea1b34
aeebd4e
735ac20
5c76a60
0bc7757
f844c8c
a4da85e
c3ba07e
ffe5c34
6d28181
7814373
1a46b65
d7f1555
2f1935d
0a7b086
8d05f28
ccbf7f6
99ecab0
9e5a70d
5643760
8898959
b16af8b
21f4301
51b42aa
f0c1ca4
08188d1
9b8d07e
ad15e23
8e02546
e6a690d
340757d
1e4c5ac
f654d18
53d6b05
1f398eb
f3dcca1
131e6e7
bc14ea8
96bf905
0ce6a2c
c57a08a
4c53c56
7fedab5
1025333
d9ba363
150e585
d7cf48f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ import ( | |
"google.golang.org/grpc/security/advancedtls/testdata" | ||
) | ||
|
||
const nonCRLFilesUnderCRLDirectory = 5 | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func TestStaticCRLProvider(t *testing.T) { | ||
p := MakeStaticCRLProvider() | ||
for i := 1; i <= 6; i++ { | ||
|
@@ -89,62 +91,35 @@ func TestFileWatcherCRLProviderConfig(t *testing.T) { | |
t.Fatal("Unexpected error:", err) | ||
} | ||
|
||
customCallback := func(err error) { | ||
fmt.Printf("Custom error message: %v", err) | ||
} | ||
regularProvider, err := MakeFileWatcherCRLProvider(Options{ | ||
CRLDirectory: testdata.Path("crl"), | ||
RefreshDuration: 5 * time.Second, | ||
CRLDirectory: testdata.Path("crl"), | ||
RefreshDuration: 5 * time.Second, | ||
cRLReloadingFailedCallback: customCallback, | ||
}) | ||
if err != nil { | ||
t.Fatal("Unexpected error while creating regular FileWatcherCRLProvider:", err) | ||
} | ||
|
||
regularProvider.scanCRLDirectory() | ||
tests := []struct { | ||
desc string | ||
certs []*x509.Certificate | ||
expectNoCRL bool | ||
}{ | ||
{ | ||
desc: "Unrevoked chain", | ||
certs: makeChain(t, testdata.Path("crl/unrevoked.pem")), | ||
}, | ||
{ | ||
desc: "Revoked Intermediate chain", | ||
certs: makeChain(t, testdata.Path("crl/revokedInt.pem")), | ||
}, | ||
{ | ||
desc: "Revoked leaf chain", | ||
certs: makeChain(t, testdata.Path("crl/revokedLeaf.pem")), | ||
}, | ||
{ | ||
desc: "Chain with no CRL for issuer", | ||
certs: makeChain(t, testdata.Path("client_cert_1.pem")), | ||
expectNoCRL: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.desc, func(t *testing.T) { | ||
for _, c := range tt.certs { | ||
crl, err := regularProvider.CRL(c) | ||
if err != nil { | ||
t.Fatalf("Expected error fetch from provider: %v", err) | ||
} | ||
if crl == nil && !tt.expectNoCRL { | ||
t.Fatalf("CRL is unexpectedly nil") | ||
} | ||
} | ||
}) | ||
} | ||
regularProvider.Close() | ||
} | ||
|
||
func TestFileWatcherCRLProvider(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a test verifying the async refreshing goroutine works? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet, it'll require playing with the timers so I'm planning to have a separate PR for that (like e2e test) |
||
p := MakeStaticCRLProvider() | ||
for i := 1; i <= 6; i++ { | ||
crl := loadCRL(t, testdata.Path(fmt.Sprintf("crl/%d.crl", i))) | ||
p.AddCRL(crl) | ||
// testdata.Path("crl") contains 5 non-crl files. | ||
failedCRlsCounter := 0 | ||
customCallback := func(err error) { | ||
failedCRlsCounter++ | ||
} | ||
|
||
p, err := MakeFileWatcherCRLProvider(Options{ | ||
CRLDirectory: testdata.Path("crl"), | ||
RefreshDuration: 5 * time.Second, | ||
cRLReloadingFailedCallback: customCallback, | ||
}) | ||
if err != nil { | ||
t.Fatal("Unexpected error while creating FileWatcherCRLProvider:", err) | ||
} | ||
p.scanCRLDirectory() | ||
tests := []struct { | ||
desc string | ||
certs []*x509.Certificate | ||
|
@@ -182,4 +157,8 @@ func TestFileWatcherCRLProvider(t *testing.T) { | |
} | ||
}) | ||
} | ||
if failedCRlsCounter < nonCRLFilesUnderCRLDirectory { | ||
t.Fatalf("Number of callback execution is smaller then number of non-CRL files: got %v, want at least %v", failedCRlsCounter, nonCRLFilesUnderCRLDirectory) | ||
} | ||
p.Close() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name this
FileWatcherOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively (and this is a go style thing so I'm not 100% sure) we could just eschew the
Options
struct and have theMakeFileWatcherCrlProvider
just take these arguments directlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use here
credentials/tls/certprovider/pemfile/watcher.go
as a pattern so bothOptions
as a wrapping args pattern and as a name come from thereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Options are good, but
advancedtls.Options
is not the right name for something only used for the file watcher crl provider.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done