mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-27 10:24:39 +00:00
Merge branch 'main' into impersonation-proxy
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// Copyright 2021 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.pinniped.dev/test/library"
|
||||
)
|
||||
|
||||
func TestGetPinnipedCategory(t *testing.T) {
|
||||
env := library.IntegrationEnv(t)
|
||||
dotSuffix := "." + env.APIGroupSuffix
|
||||
|
||||
t.Run("category, no special params", func(t *testing.T) {
|
||||
var stdOut, stdErr bytes.Buffer
|
||||
|
||||
cmd := exec.Command("kubectl", "get", "pinniped", "-A")
|
||||
cmd.Stdout = &stdOut
|
||||
cmd.Stderr = &stdErr
|
||||
err := cmd.Run()
|
||||
require.NoError(t, err, stdErr.String(), stdOut.String())
|
||||
require.Empty(t, stdErr.String())
|
||||
|
||||
require.NotContains(t, stdOut.String(), "MethodNotAllowed")
|
||||
require.Contains(t, stdOut.String(), dotSuffix)
|
||||
})
|
||||
|
||||
t.Run("category, table params", func(t *testing.T) {
|
||||
var stdOut, stdErr bytes.Buffer
|
||||
|
||||
cmd := exec.Command("kubectl", "get", "pinniped", "-A", "-o", "wide", "-v", "10")
|
||||
cmd.Stdout = &stdOut
|
||||
cmd.Stderr = &stdErr
|
||||
err := cmd.Run()
|
||||
require.NoError(t, err, stdErr.String(), stdOut.String())
|
||||
|
||||
require.NotContains(t, stdOut.String(), "MethodNotAllowed")
|
||||
require.Contains(t, stdOut.String(), dotSuffix)
|
||||
|
||||
require.Contains(t, stdErr.String(), `"kind":"Table"`)
|
||||
require.Contains(t, stdErr.String(), `"resourceVersion":"0"`)
|
||||
})
|
||||
|
||||
t.Run("list, no special params", func(t *testing.T) {
|
||||
var stdOut, stdErr bytes.Buffer
|
||||
|
||||
//nolint: gosec // input is part of test env
|
||||
cmd := exec.Command("kubectl", "get", "tokencredentialrequests.login.concierge"+dotSuffix, "-A")
|
||||
cmd.Stdout = &stdOut
|
||||
cmd.Stderr = &stdErr
|
||||
err := cmd.Run()
|
||||
require.NoError(t, err, stdErr.String(), stdOut.String())
|
||||
require.Empty(t, stdOut.String())
|
||||
|
||||
require.NotContains(t, stdErr.String(), "MethodNotAllowed")
|
||||
require.Contains(t, stdErr.String(), `No resources found`)
|
||||
})
|
||||
|
||||
t.Run("list, table params", func(t *testing.T) {
|
||||
var stdOut, stdErr bytes.Buffer
|
||||
|
||||
//nolint: gosec // input is part of test env
|
||||
cmd := exec.Command("kubectl", "get", "tokencredentialrequests.login.concierge"+dotSuffix, "-A", "-o", "wide", "-v", "10")
|
||||
cmd.Stdout = &stdOut
|
||||
cmd.Stderr = &stdErr
|
||||
err := cmd.Run()
|
||||
require.NoError(t, err, stdErr.String(), stdOut.String())
|
||||
require.Empty(t, stdOut.String())
|
||||
|
||||
require.NotContains(t, stdErr.String(), "MethodNotAllowed")
|
||||
require.Contains(t, stdErr.String(), `"kind":"Table"`)
|
||||
require.Contains(t, stdErr.String(), `"resourceVersion":"0"`)
|
||||
})
|
||||
|
||||
t.Run("raw request to see body", func(t *testing.T) {
|
||||
var stdOut, stdErr bytes.Buffer
|
||||
|
||||
//nolint: gosec // input is part of test env
|
||||
cmd := exec.Command("kubectl", "get", "--raw", "/apis/login.concierge"+dotSuffix+"/v1alpha1/tokencredentialrequests")
|
||||
cmd.Stdout = &stdOut
|
||||
cmd.Stderr = &stdErr
|
||||
err := cmd.Run()
|
||||
require.NoError(t, err, stdErr.String(), stdOut.String())
|
||||
require.Empty(t, stdErr.String())
|
||||
|
||||
require.NotContains(t, stdOut.String(), "MethodNotAllowed")
|
||||
require.Contains(t, stdOut.String(), `{"kind":"TokenCredentialRequestList","apiVersion":"login.concierge`+
|
||||
dotSuffix+`/v1alpha1","metadata":{"resourceVersion":"0"},"items":[]}`)
|
||||
})
|
||||
}
|
||||
@@ -35,6 +35,8 @@ import (
|
||||
func TestCLIGetKubeconfigStaticToken(t *testing.T) {
|
||||
env := library.IntegrationEnv(t).WithCapability(library.ClusterSigningKeyIsAvailable)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
// Create a test webhook configuration to use with the CLI.
|
||||
ctx, cancelFunc := context.WithTimeout(context.Background(), 4*time.Minute)
|
||||
defer cancelFunc()
|
||||
|
||||
@@ -22,6 +22,8 @@ func TestAPIServingCertificateAutoCreationAndRotation(t *testing.T) {
|
||||
env := library.IntegrationEnv(t)
|
||||
defaultServingCertResourceName := env.ConciergeAppName + "-api-tls-serving-certificate"
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
forceRotation func(context.Context, kubernetes.Interface, string) error
|
||||
|
||||
@@ -57,6 +57,8 @@ var maskKey = func(s string) string { return strings.ReplaceAll(s, "TESTING KEY"
|
||||
func TestClient(t *testing.T) {
|
||||
env := library.IntegrationEnv(t).WithCapability(library.ClusterSigningKeyIsAvailable)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -21,6 +21,8 @@ func TestCredentialIssuer(t *testing.T) {
|
||||
config := library.NewClientConfig(t)
|
||||
client := library.NewConciergeClientset(t)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ import (
|
||||
)
|
||||
|
||||
func TestUnsuccessfulCredentialRequest(t *testing.T) {
|
||||
library.SkipUnlessIntegration(t)
|
||||
env := library.IntegrationEnv(t)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
@@ -42,6 +44,8 @@ func TestUnsuccessfulCredentialRequest(t *testing.T) {
|
||||
func TestSuccessfulCredentialRequest(t *testing.T) {
|
||||
env := library.IntegrationEnv(t).WithCapability(library.ClusterSigningKeyIsAvailable)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
@@ -127,7 +131,9 @@ func TestSuccessfulCredentialRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFailedCredentialRequestWhenTheRequestIsValidButTheTokenDoesNotAuthenticateTheUser(t *testing.T) {
|
||||
library.IntegrationEnv(t).WithCapability(library.ClusterSigningKeyIsAvailable)
|
||||
env := library.IntegrationEnv(t).WithCapability(library.ClusterSigningKeyIsAvailable)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
response, err := makeRequest(context.Background(), t, loginv1alpha1.TokenCredentialRequestSpec{Token: "not a good token"})
|
||||
|
||||
@@ -139,7 +145,9 @@ func TestFailedCredentialRequestWhenTheRequestIsValidButTheTokenDoesNotAuthentic
|
||||
}
|
||||
|
||||
func TestCredentialRequest_ShouldFailWhenRequestDoesNotIncludeToken(t *testing.T) {
|
||||
library.IntegrationEnv(t).WithCapability(library.ClusterSigningKeyIsAvailable)
|
||||
env := library.IntegrationEnv(t).WithCapability(library.ClusterSigningKeyIsAvailable)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
response, err := makeRequest(context.Background(), t, loginv1alpha1.TokenCredentialRequestSpec{Token: ""})
|
||||
|
||||
@@ -158,7 +166,9 @@ func TestCredentialRequest_ShouldFailWhenRequestDoesNotIncludeToken(t *testing.T
|
||||
}
|
||||
|
||||
func TestCredentialRequest_OtherwiseValidRequestWithRealTokenShouldFailWhenTheClusterIsNotCapable(t *testing.T) {
|
||||
library.IntegrationEnv(t).WithoutCapability(library.ClusterSigningKeyIsAvailable)
|
||||
env := library.IntegrationEnv(t).WithoutCapability(library.ClusterSigningKeyIsAvailable)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -27,6 +27,8 @@ const (
|
||||
func TestKubeCertAgent(t *testing.T) {
|
||||
env := library.IntegrationEnv(t).WithCapability(library.ClusterSigningKeyIsAvailable)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -46,6 +46,9 @@ func TestE2EFullIntegration(t *testing.T) {
|
||||
defer library.DumpLogs(t, env.SupervisorNamespace, "")
|
||||
defer library.DumpLogs(t, "dex", "app=proxy")
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.ConciergeNamespace, "")
|
||||
library.AssertNoRestartsDuringTest(t, env.SupervisorNamespace, "")
|
||||
|
||||
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||
defer cancelFunc()
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestGetAPIResourceList(t *testing.T) {
|
||||
{
|
||||
Name: "tokencredentialrequests",
|
||||
Kind: "TokenCredentialRequest",
|
||||
Verbs: []string{"create"},
|
||||
Verbs: []string{"create", "list"},
|
||||
Namespaced: true,
|
||||
Categories: []string{"pinniped"},
|
||||
},
|
||||
|
||||
@@ -44,7 +44,10 @@ func TestSupervisorOIDCDiscovery(t *testing.T) {
|
||||
env := library.IntegrationEnv(t)
|
||||
client := library.NewSupervisorClientset(t)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.SupervisorNamespace, "")
|
||||
|
||||
ns := env.SupervisorNamespace
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
@@ -148,6 +151,8 @@ func TestSupervisorTLSTerminationWithSNI(t *testing.T) {
|
||||
pinnipedClient := library.NewSupervisorClientset(t)
|
||||
kubeClient := library.NewKubernetesClientset(t)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.SupervisorNamespace, "")
|
||||
|
||||
ns := env.SupervisorNamespace
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer cancel()
|
||||
@@ -215,6 +220,8 @@ func TestSupervisorTLSTerminationWithDefaultCerts(t *testing.T) {
|
||||
pinnipedClient := library.NewSupervisorClientset(t)
|
||||
kubeClient := library.NewKubernetesClientset(t)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.SupervisorNamespace, "")
|
||||
|
||||
ns := env.SupervisorNamespace
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
||||
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package integration
|
||||
@@ -29,6 +29,8 @@ func TestSupervisorHealthz(t *testing.T) {
|
||||
t.Skip("PINNIPED_TEST_SUPERVISOR_HTTP_ADDRESS not defined")
|
||||
}
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.SupervisorNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ func TestSupervisorLogin(t *testing.T) {
|
||||
defer library.DumpLogs(t, env.SupervisorNamespace, "")
|
||||
defer library.DumpLogs(t, "dex", "app=proxy")
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.SupervisorNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ func TestSupervisorSecrets(t *testing.T) {
|
||||
kubeClient := library.NewKubernetesClientset(t)
|
||||
supervisorClient := library.NewSupervisorClientset(t)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.SupervisorNamespace, "")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
func TestSupervisorUpstreamOIDCDiscovery(t *testing.T) {
|
||||
env := library.IntegrationEnv(t)
|
||||
|
||||
library.AssertNoRestartsDuringTest(t, env.SupervisorNamespace, "")
|
||||
|
||||
t.Run("invalid missing secret and bad issuer", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
spec := v1alpha1.OIDCIdentityProviderSpec{
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
)
|
||||
|
||||
@@ -24,3 +28,56 @@ func RequireEventuallyWithoutError(
|
||||
t.Helper()
|
||||
require.NoError(t, wait.PollImmediate(tick, waitFor, f), msgAndArgs...)
|
||||
}
|
||||
|
||||
// NewRestartAssertion allows a caller to assert that there were no restarts for a Pod in the
|
||||
// provided namespace with the provided labelSelector during the lifetime of a test.
|
||||
func AssertNoRestartsDuringTest(t *testing.T, namespace, labelSelector string) {
|
||||
t.Helper()
|
||||
|
||||
previousRestartCounts := getRestartCounts(t, namespace, labelSelector)
|
||||
|
||||
t.Cleanup(func() {
|
||||
currentRestartCounts := getRestartCounts(t, namespace, labelSelector)
|
||||
|
||||
for key, previousRestartCount := range previousRestartCounts {
|
||||
currentRestartCount, ok := currentRestartCounts[key]
|
||||
if assert.Truef(
|
||||
t,
|
||||
ok,
|
||||
"pod namespace/name/container %s existed at beginning of the test, but not the end",
|
||||
key,
|
||||
) {
|
||||
assert.Equal(
|
||||
t,
|
||||
previousRestartCount,
|
||||
currentRestartCount,
|
||||
"pod namespace/name/container %s has restarted %d times (original count was %d)",
|
||||
key,
|
||||
currentRestartCount,
|
||||
previousRestartCount,
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func getRestartCounts(t *testing.T, namespace, labelSelector string) map[string]int32 {
|
||||
t.Helper()
|
||||
|
||||
kubeClient := NewKubernetesClientset(t)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
|
||||
pods, err := kubeClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector})
|
||||
require.NoError(t, err)
|
||||
|
||||
restartCounts := make(map[string]int32)
|
||||
for _, pod := range pods.Items {
|
||||
for _, container := range pod.Status.ContainerStatuses {
|
||||
key := fmt.Sprintf("%s/%s/%s", pod.Namespace, pod.Name, container.Name)
|
||||
restartCounts[key] = container.RestartCount
|
||||
}
|
||||
}
|
||||
|
||||
return restartCounts
|
||||
}
|
||||
|
||||
@@ -180,8 +180,11 @@ func CreateTestWebhookAuthenticator(ctx context.Context, t *testing.T) corev1.Ty
|
||||
require.NoErrorf(t, err, "could not cleanup test WebhookAuthenticator %s/%s", webhook.Namespace, webhook.Name)
|
||||
})
|
||||
|
||||
apiGroup, replacedSuffix := groupsuffix.Replace(auth1alpha1.SchemeGroupVersion.Group, testEnv.APIGroupSuffix)
|
||||
require.True(t, replacedSuffix)
|
||||
|
||||
return corev1.TypedLocalObjectReference{
|
||||
APIGroup: &auth1alpha1.SchemeGroupVersion.Group,
|
||||
APIGroup: &apiGroup,
|
||||
Kind: "WebhookAuthenticator",
|
||||
Name: webhook.Name,
|
||||
}
|
||||
@@ -250,8 +253,11 @@ func CreateTestJWTAuthenticator(ctx context.Context, t *testing.T, spec auth1alp
|
||||
require.NoErrorf(t, err, "could not cleanup test JWTAuthenticator %s/%s", jwtAuthenticator.Namespace, jwtAuthenticator.Name)
|
||||
})
|
||||
|
||||
apiGroup, replacedSuffix := groupsuffix.Replace(auth1alpha1.SchemeGroupVersion.Group, testEnv.APIGroupSuffix)
|
||||
require.True(t, replacedSuffix)
|
||||
|
||||
return corev1.TypedLocalObjectReference{
|
||||
APIGroup: &auth1alpha1.SchemeGroupVersion.Group,
|
||||
APIGroup: &apiGroup,
|
||||
Kind: "JWTAuthenticator",
|
||||
Name: jwtAuthenticator.Name,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user