Skip to content
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

Use boolean values instead of pointers #24

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions jwks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,14 @@ func TestRateLimit(t *testing.T) {
refreshInterval := time.Second
refreshRateLimit := time.Millisecond * 500
refreshTimeout := time.Second
refreshUnknownKID := true
options := keyfunc.Options{
RefreshErrorHandler: func(err error) {
t.Errorf("The package itself had an error.\nError: %s", err.Error())
},
RefreshInterval: refreshInterval,
RefreshRateLimit: refreshRateLimit,
RefreshTimeout: refreshTimeout,
RefreshUnknownKID: &refreshUnknownKID,
RefreshUnknownKID: true,
}

// Create the JWKs.
Expand Down Expand Up @@ -412,7 +411,7 @@ func TestUnknownKIDRefresh(t *testing.T) {
// Set the options to refresh KID when unknown.
options := keyfunc.Options{
RefreshErrorHandler: testingRefreshErrorHandler,
RefreshUnknownKID: &[]bool{true}[0],
RefreshUnknownKID: true,
}

// Create the JWKs.
Expand Down
12 changes: 6 additions & 6 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Options struct {

// GivenKIDOverride will make a GivenKey override any keys with the same ID (`kid`) in the remote JWKs. The is only
// effectual if GivenKeys is provided.
GivenKIDOverride *bool
GivenKIDOverride bool

// RefreshErrorHandler is a function that consumes errors that happen during a JWKs refresh. This is only effectual
// if a background refresh goroutine is active.
Expand All @@ -54,7 +54,7 @@ type Options struct {
// This is done through a background goroutine. Without specifying a RefreshInterval a malicious client could
// self-sign X JWTs, send them to this service, then cause potentially high network usage proportional to X. Make
// sure to call the JWKs.EndBackground method to end this goroutine when it's no longer needed.
RefreshUnknownKID *bool
RefreshUnknownKID bool
}

// applyOptions applies the given options to the given JWKs.
Expand All @@ -73,8 +73,8 @@ func applyOptions(jwks *JWKs, options Options) {
jwks.givenKeys[kid] = key
}
}
if options.GivenKIDOverride != nil {
jwks.givenKIDOverride = *options.GivenKIDOverride
if options.GivenKIDOverride {
jwks.givenKIDOverride = true
}
if options.RefreshErrorHandler != nil {
jwks.refreshErrorHandler = options.RefreshErrorHandler
Expand All @@ -88,7 +88,7 @@ func applyOptions(jwks *JWKs, options Options) {
if options.RefreshTimeout != 0 {
jwks.refreshTimeout = options.RefreshTimeout
}
if options.RefreshUnknownKID != nil {
jwks.refreshUnknownKID = *options.RefreshUnknownKID
if options.RefreshUnknownKID {
jwks.refreshUnknownKID = true
}
}
3 changes: 1 addition & 2 deletions override_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func TestNewGiven(t *testing.T) {
createSignParseValidate(t, remotePrivateKeys, jwks, remoteKID, true)

// Change the JWKs options to overwrite remote keys.
givenKidOverride := true
options.GivenKIDOverride = &givenKidOverride
options.GivenKIDOverride = true
if jwks, err = keyfunc.Get(jwksURL, options); err != nil {
t.Errorf("Failed to recreate JWKs.\nError: %s.", err.Error())
t.FailNow()
Expand Down