From 150de90c38886be616ae45c59760c9b5534928e7 Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Sat, 13 Nov 2021 17:52:45 +0100 Subject: [PATCH] Use boolean values instead of pointers Signed-off-by: Alexander Yastrebov --- jwks_test.go | 5 ++--- options.go | 12 ++++++------ override_test.go | 3 +-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/jwks_test.go b/jwks_test.go index 640ed02..5b8e9a7 100644 --- a/jwks_test.go +++ b/jwks_test.go @@ -275,7 +275,6 @@ 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()) @@ -283,7 +282,7 @@ func TestRateLimit(t *testing.T) { RefreshInterval: refreshInterval, RefreshRateLimit: refreshRateLimit, RefreshTimeout: refreshTimeout, - RefreshUnknownKID: &refreshUnknownKID, + RefreshUnknownKID: true, } // Create the JWKs. @@ -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. diff --git a/options.go b/options.go index 66fc86b..cefa67e 100644 --- a/options.go +++ b/options.go @@ -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. @@ -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. @@ -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 @@ -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 } } diff --git a/override_test.go b/override_test.go index 7640f52..c2bae23 100644 --- a/override_test.go +++ b/override_test.go @@ -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()