From d4611b829dc8d8ef02661b25ac2175b51a73be7a Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Tue, 22 Aug 2023 17:29:44 -0700 Subject: [PATCH] use slices.Contains() instead of custom func in token_handler_test.go --- .../endpoints/token/token_handler_test.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/internal/federationdomain/endpoints/token/token_handler_test.go b/internal/federationdomain/endpoints/token/token_handler_test.go index 764f2c28..1ce81311 100644 --- a/internal/federationdomain/endpoints/token/token_handler_test.go +++ b/internal/federationdomain/endpoints/token/token_handler_test.go @@ -38,6 +38,7 @@ import ( "k8s.io/apiserver/pkg/warning" "k8s.io/client-go/kubernetes/fake" v1 "k8s.io/client-go/kubernetes/typed/core/v1" + "k8s.io/utils/strings/slices" configv1alpha1 "go.pinniped.dev/generated/latest/apis/supervisor/config/v1alpha1" supervisorfake "go.pinniped.dev/generated/latest/client/supervisor/clientset/versioned/fake" @@ -4118,7 +4119,7 @@ func TestRefreshGrant(t *testing.T) { ) if test.refreshRequest.want.wantStatus == http.StatusOK { - wantIDToken := contains(test.refreshRequest.want.wantSuccessBodyFields, "id_token") + wantIDToken := slices.Contains(test.refreshRequest.want.wantSuccessBodyFields, "id_token") var parsedRefreshResponseBody map[string]interface{} require.NoError(t, json.Unmarshal(refreshResponse.Body.Bytes(), &parsedRefreshResponseBody)) @@ -4283,8 +4284,8 @@ func requireTokenEndpointBehavior( require.NoError(t, json.Unmarshal(tokenEndpointResponse.Body.Bytes(), &parsedResponseBody)) require.ElementsMatch(t, test.wantSuccessBodyFields, getMapKeys(parsedResponseBody)) - wantIDToken := contains(test.wantSuccessBodyFields, "id_token") - wantRefreshToken := contains(test.wantSuccessBodyFields, "refresh_token") + wantIDToken := slices.Contains(test.wantSuccessBodyFields, "id_token") + wantRefreshToken := slices.Contains(test.wantSuccessBodyFields, "refresh_token") requireInvalidAuthCodeStorage(t, authCode, oauthStore, secrets, requestTime) requireValidAccessTokenStorage(t, parsedResponseBody, oauthStore, test.wantClientID, test.wantRequestedScopes, test.wantGrantedScopes, test.wantUsername, test.wantGroups, test.wantCustomSessionDataStored, test.wantAdditionalClaims, secrets, requestTime) @@ -4685,7 +4686,7 @@ func requireValidOIDCStorage( ) { t.Helper() - if contains(wantGrantedScopes, "openid") { + if slices.Contains(wantGrantedScopes, "openid") { // Make sure the OIDC session is still there. Note that Fosite stores OIDC sessions using the full auth code as a key. storedRequest, err := storage.GetOpenIDConnectSession(context.Background(), code, nil) require.NoError(t, err) @@ -4951,15 +4952,6 @@ func getMapKeys(m map[string]interface{}) []string { return keys } -func contains(haystack []string, needle string) bool { - for _, hay := range haystack { - if hay == needle { - return true - } - } - return false -} - func toSliceOfInterface(s []string) []interface{} { r := make([]interface{}, len(s)) for i := range s {