2022-06-10 20:56:15 +00:00
|
|
|
// Copyright 2022 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-26 17:57:45 +00:00
|
|
|
"encoding/hex"
|
2022-06-10 20:56:15 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
2022-06-13 21:28:05 +00:00
|
|
|
"go.pinniped.dev/generated/latest/apis/supervisor/clientsecret/v1alpha1"
|
2022-08-26 17:57:45 +00:00
|
|
|
supervisorconfigv1alpha1 "go.pinniped.dev/generated/latest/apis/supervisor/config/v1alpha1"
|
2022-06-10 20:56:15 +00:00
|
|
|
"go.pinniped.dev/test/testlib"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestOIDCClientSecretRequest_HappyPath_Parallel(t *testing.T) {
|
|
|
|
env := testlib.IntegrationEnv(t)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
2022-08-26 17:57:45 +00:00
|
|
|
t.Cleanup(cancel)
|
2022-06-10 20:56:15 +00:00
|
|
|
|
2022-06-13 21:28:05 +00:00
|
|
|
client := testlib.NewSupervisorClientset(t)
|
2022-06-10 20:56:15 +00:00
|
|
|
|
2022-08-26 17:57:45 +00:00
|
|
|
oidcClient, err := client.ConfigV1alpha1().OIDCClients(env.SupervisorNamespace).Create(ctx,
|
|
|
|
&supervisorconfigv1alpha1.OIDCClient{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
GenerateName: "client.oauth.pinniped.dev-",
|
|
|
|
},
|
|
|
|
Spec: supervisorconfigv1alpha1.OIDCClientSpec{
|
|
|
|
AllowedRedirectURIs: []supervisorconfigv1alpha1.RedirectURI{
|
|
|
|
"https://example.com",
|
|
|
|
"http://127.0.0.1/yoyo",
|
|
|
|
},
|
|
|
|
AllowedGrantTypes: []supervisorconfigv1alpha1.GrantType{
|
|
|
|
"authorization_code",
|
|
|
|
"refresh_token",
|
|
|
|
"urn:ietf:params:oauth:grant-type:token-exchange",
|
|
|
|
},
|
|
|
|
AllowedScopes: []supervisorconfigv1alpha1.Scope{
|
|
|
|
"openid",
|
|
|
|
"offline_access",
|
|
|
|
"username",
|
|
|
|
"groups",
|
|
|
|
"pinniped:request-audience",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
metav1.CreateOptions{},
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Cleanup(func() {
|
|
|
|
deleteErr := client.ConfigV1alpha1().OIDCClients(env.SupervisorNamespace).Delete(ctx, oidcClient.Name, metav1.DeleteOptions{})
|
|
|
|
require.NoError(t, deleteErr)
|
|
|
|
})
|
|
|
|
|
2022-06-13 21:28:05 +00:00
|
|
|
response, err := client.ClientsecretV1alpha1().OIDCClientSecretRequests(env.SupervisorNamespace).Create(ctx,
|
2022-06-10 20:56:15 +00:00
|
|
|
&v1alpha1.OIDCClientSecretRequest{
|
2022-08-26 17:57:45 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: oidcClient.Name,
|
|
|
|
},
|
2022-06-10 20:56:15 +00:00
|
|
|
Spec: v1alpha1.OIDCClientSecretRequestSpec{
|
|
|
|
GenerateNewSecret: true,
|
|
|
|
},
|
|
|
|
}, metav1.CreateOptions{})
|
|
|
|
require.NoError(t, err)
|
2022-08-26 17:57:45 +00:00
|
|
|
require.Equal(t, response.Status.TotalClientSecrets, 1)
|
|
|
|
require.Len(t, response.Status.GeneratedSecret, hex.EncodedLen(32))
|
2022-06-10 20:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOIDCClientSecretRequest_Unauthenticated_Parallel(t *testing.T) {
|
|
|
|
env := testlib.IntegrationEnv(t)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
2022-08-26 17:57:45 +00:00
|
|
|
t.Cleanup(cancel)
|
2022-06-10 20:56:15 +00:00
|
|
|
|
2022-06-13 21:28:05 +00:00
|
|
|
client := testlib.NewAnonymousSupervisorClientset(t)
|
2022-06-10 20:56:15 +00:00
|
|
|
|
2022-06-13 21:28:05 +00:00
|
|
|
_, err := client.ClientsecretV1alpha1().OIDCClientSecretRequests(env.SupervisorNamespace).Create(ctx,
|
2022-06-10 20:56:15 +00:00
|
|
|
&v1alpha1.OIDCClientSecretRequest{
|
|
|
|
Spec: v1alpha1.OIDCClientSecretRequestSpec{
|
|
|
|
GenerateNewSecret: true,
|
|
|
|
},
|
|
|
|
}, metav1.CreateOptions{})
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "User \"system:anonymous\" cannot create resource \"oidcclientsecretrequests\"")
|
|
|
|
}
|