mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-12 02:56:14 +00:00
More unit tests for dynamic clients
- Add dynamic client unit tests for the upstream OIDC callback and POST login endpoints. - Enhance a few log statements to print the full fosite error messages into the logs where they were previously only printing the name of the error type.
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
kubetesting "k8s.io/client-go/testing"
|
||||
"k8s.io/utils/strings/slices"
|
||||
|
||||
"go.pinniped.dev/internal/authenticators"
|
||||
@@ -954,7 +955,7 @@ func RequireAuthCodeRegexpMatch(
|
||||
if includesOpenIDScope(wantDownstreamGrantedScopes) {
|
||||
expectedNumberOfCreatedSecrets++
|
||||
}
|
||||
require.Len(t, kubeClient.Actions(), expectedNumberOfCreatedSecrets)
|
||||
require.Len(t, FilterClientSecretCreateActions(kubeClient.Actions()), expectedNumberOfCreatedSecrets)
|
||||
|
||||
// One authcode should have been stored.
|
||||
testutil.RequireNumberOfSecretsMatchingLabelSelector(t, secretsClient, labels.Set{crud.SecretLabelKey: authorizationcode.TypeLabelValue}, 1)
|
||||
@@ -1164,3 +1165,20 @@ func castStoredAuthorizeRequest(t *testing.T, storedAuthorizeRequest fosite.Requ
|
||||
|
||||
return storedRequest, storedSession
|
||||
}
|
||||
|
||||
// FilterClientSecretCreateActions ignores any reads made to get a storage secret corresponding to an OIDCClient, since these
|
||||
// are normal actions when the request is using a dynamic client's client_id, and we don't need to make assertions
|
||||
// about these Secrets since they are not related to session storage.
|
||||
func FilterClientSecretCreateActions(actions []kubetesting.Action) []kubetesting.Action {
|
||||
filtered := make([]kubetesting.Action, 0, len(actions))
|
||||
for _, action := range actions {
|
||||
if action.Matches("get", "secrets") {
|
||||
getAction := action.(kubetesting.GetAction)
|
||||
if strings.HasPrefix(getAction.GetName(), "pinniped-storage-oidc-client-secret-") {
|
||||
continue // filter out OIDCClient's storage secret reads
|
||||
}
|
||||
}
|
||||
filtered = append(filtered, action) // otherwise include the action
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user