2020-09-16 14:19:51 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-07-31 16:08:07 +00:00
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/base64"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
2020-09-18 21:38:45 +00:00
|
|
|
configv1alpha1 "go.pinniped.dev/generated/1.19/apis/config/v1alpha1"
|
2020-09-18 19:56:24 +00:00
|
|
|
"go.pinniped.dev/test/library"
|
2020-07-31 16:08:07 +00:00
|
|
|
)
|
|
|
|
|
2020-08-25 01:07:34 +00:00
|
|
|
func TestCredentialIssuerConfig(t *testing.T) {
|
2020-09-24 22:51:43 +00:00
|
|
|
env := library.IntegrationEnv(t)
|
2020-08-25 01:07:34 +00:00
|
|
|
config := library.NewClientConfig(t)
|
2020-08-20 17:54:15 +00:00
|
|
|
client := library.NewPinnipedClientset(t)
|
2020-07-31 16:08:07 +00:00
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2020-08-25 01:07:34 +00:00
|
|
|
t.Run("test successful CredentialIssuerConfig", func(t *testing.T) {
|
|
|
|
actualConfigList, err := client.
|
2020-09-18 21:38:45 +00:00
|
|
|
ConfigV1alpha1().
|
2020-09-24 22:51:43 +00:00
|
|
|
CredentialIssuerConfigs(env.Namespace).
|
2020-08-25 01:07:34 +00:00
|
|
|
List(ctx, metav1.ListOptions{})
|
|
|
|
require.NoError(t, err)
|
2020-09-15 17:04:46 +00:00
|
|
|
|
2020-08-25 01:07:34 +00:00
|
|
|
require.Len(t, actualConfigList.Items, 1)
|
2020-07-31 16:08:07 +00:00
|
|
|
|
2020-08-25 01:07:34 +00:00
|
|
|
actualStatusKubeConfigInfo := actualConfigList.Items[0].Status.KubeConfigInfo
|
2020-07-31 16:08:07 +00:00
|
|
|
|
2020-08-25 01:07:34 +00:00
|
|
|
// Verify the cluster strategy status based on what's expected of the test cluster's ability to share signing keys.
|
|
|
|
actualStatusStrategies := actualConfigList.Items[0].Status.Strategies
|
|
|
|
require.Len(t, actualStatusStrategies, 1)
|
|
|
|
actualStatusStrategy := actualStatusStrategies[0]
|
2020-09-18 21:38:45 +00:00
|
|
|
require.Equal(t, configv1alpha1.KubeClusterSigningCertificateStrategyType, actualStatusStrategy.Type)
|
2020-07-31 16:08:07 +00:00
|
|
|
|
2020-09-24 22:51:43 +00:00
|
|
|
if env.HasCapability(library.ClusterSigningKeyIsAvailable) {
|
2020-09-18 21:38:45 +00:00
|
|
|
require.Equal(t, configv1alpha1.SuccessStrategyStatus, actualStatusStrategy.Status)
|
|
|
|
require.Equal(t, configv1alpha1.FetchedKeyStrategyReason, actualStatusStrategy.Reason)
|
2020-08-25 01:07:34 +00:00
|
|
|
require.Equal(t, "Key was fetched successfully", actualStatusStrategy.Message)
|
2020-08-28 00:18:48 +00:00
|
|
|
// Verify the published kube config info.
|
2020-09-24 16:19:57 +00:00
|
|
|
require.Equal(
|
|
|
|
t,
|
|
|
|
&configv1alpha1.CredentialIssuerConfigKubeConfigInfo{
|
|
|
|
Server: config.Host,
|
|
|
|
CertificateAuthorityData: base64.StdEncoding.EncodeToString(config.TLSClientConfig.CAData),
|
|
|
|
},
|
|
|
|
actualStatusKubeConfigInfo,
|
|
|
|
)
|
2020-08-25 01:07:34 +00:00
|
|
|
} else {
|
2020-09-18 21:38:45 +00:00
|
|
|
require.Equal(t, configv1alpha1.ErrorStrategyStatus, actualStatusStrategy.Status)
|
|
|
|
require.Equal(t, configv1alpha1.CouldNotFetchKeyStrategyReason, actualStatusStrategy.Reason)
|
2020-09-24 21:56:55 +00:00
|
|
|
require.Contains(t, actualStatusStrategy.Message, "did not find kube-controller-manager pod(s)")
|
2020-08-28 00:18:48 +00:00
|
|
|
// For now, don't verify the kube config info because its not available on GKE. We'll need to address
|
|
|
|
// this somehow once we starting supporting those cluster types.
|
|
|
|
// Require `nil` to remind us to address this later for other types of clusters where it is available.
|
|
|
|
require.Nil(t, actualStatusKubeConfigInfo)
|
2020-08-25 01:07:34 +00:00
|
|
|
}
|
2020-07-31 16:08:07 +00:00
|
|
|
|
2020-08-25 01:07:34 +00:00
|
|
|
require.WithinDuration(t, time.Now(), actualStatusStrategy.LastUpdateTime.Local(), 10*time.Minute)
|
|
|
|
})
|
2020-07-31 16:08:07 +00:00
|
|
|
}
|