2020-11-12 00:28:42 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
2020-11-17 00:16:16 +00:00
|
|
|
"encoding/base64"
|
2020-11-12 00:28:42 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
|
|
|
"go.pinniped.dev/generated/1.19/apis/supervisor/idp/v1alpha1"
|
|
|
|
"go.pinniped.dev/test/library"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSupervisorUpstreamOIDCDiscovery(t *testing.T) {
|
2020-11-17 00:16:16 +00:00
|
|
|
env := library.IntegrationEnv(t)
|
2020-11-12 00:28:42 +00:00
|
|
|
|
|
|
|
t.Run("invalid missing secret and bad issuer", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
spec := v1alpha1.UpstreamOIDCProviderSpec{
|
|
|
|
Issuer: "https://127.0.0.1:444444/issuer",
|
|
|
|
Client: v1alpha1.OIDCClient{
|
|
|
|
SecretName: "does-not-exist",
|
|
|
|
},
|
|
|
|
}
|
2020-12-02 21:32:54 +00:00
|
|
|
upstream := library.CreateTestUpstreamOIDCProvider(t, spec, v1alpha1.PhaseError)
|
2020-11-12 00:28:42 +00:00
|
|
|
expectUpstreamConditions(t, upstream, []v1alpha1.Condition{
|
|
|
|
{
|
|
|
|
Type: "ClientCredentialsValid",
|
|
|
|
Status: v1alpha1.ConditionFalse,
|
|
|
|
Reason: "SecretNotFound",
|
|
|
|
Message: `secret "does-not-exist" not found`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "OIDCDiscoverySucceeded",
|
|
|
|
Status: v1alpha1.ConditionFalse,
|
|
|
|
Reason: "Unreachable",
|
2020-11-13 21:29:32 +00:00
|
|
|
Message: `failed to perform OIDC discovery against "https://127.0.0.1:444444/issuer"`,
|
2020-11-12 00:28:42 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("valid", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
spec := v1alpha1.UpstreamOIDCProviderSpec{
|
2020-11-19 21:05:31 +00:00
|
|
|
Issuer: env.SupervisorTestUpstream.Issuer,
|
2020-11-17 00:16:16 +00:00
|
|
|
TLS: &v1alpha1.TLSSpec{
|
2020-11-19 21:05:31 +00:00
|
|
|
CertificateAuthorityData: base64.StdEncoding.EncodeToString([]byte(env.SupervisorTestUpstream.CABundle)),
|
2020-11-17 00:16:16 +00:00
|
|
|
},
|
2020-11-12 00:28:42 +00:00
|
|
|
AuthorizationConfig: v1alpha1.OIDCAuthorizationConfig{
|
|
|
|
AdditionalScopes: []string{"email", "profile"},
|
|
|
|
},
|
|
|
|
Client: v1alpha1.OIDCClient{
|
2020-12-02 21:32:54 +00:00
|
|
|
SecretName: library.CreateClientCredsSecret(t, "test-client-id", "test-client-secret").Name,
|
2020-11-12 00:28:42 +00:00
|
|
|
},
|
|
|
|
}
|
2020-12-02 21:32:54 +00:00
|
|
|
upstream := library.CreateTestUpstreamOIDCProvider(t, spec, v1alpha1.PhaseReady)
|
2020-11-12 00:28:42 +00:00
|
|
|
expectUpstreamConditions(t, upstream, []v1alpha1.Condition{
|
|
|
|
{
|
|
|
|
Type: "ClientCredentialsValid",
|
|
|
|
Status: v1alpha1.ConditionTrue,
|
|
|
|
Reason: "Success",
|
|
|
|
Message: "loaded client credentials",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "OIDCDiscoverySucceeded",
|
|
|
|
Status: v1alpha1.ConditionTrue,
|
|
|
|
Reason: "Success",
|
|
|
|
Message: "discovered issuer configuration",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func expectUpstreamConditions(t *testing.T, upstream *v1alpha1.UpstreamOIDCProvider, expected []v1alpha1.Condition) {
|
|
|
|
t.Helper()
|
|
|
|
normalized := make([]v1alpha1.Condition, 0, len(upstream.Status.Conditions))
|
|
|
|
for _, c := range upstream.Status.Conditions {
|
|
|
|
c.ObservedGeneration = 0
|
|
|
|
c.LastTransitionTime = metav1.Time{}
|
|
|
|
normalized = append(normalized, c)
|
|
|
|
}
|
|
|
|
require.ElementsMatch(t, expected, normalized)
|
|
|
|
}
|