2020-09-16 14:19:51 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-08-01 00:37:59 +00:00
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
2020-11-12 22:24:25 +00:00
|
|
|
"strings"
|
2020-08-01 00:37:59 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-11-12 22:24:25 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-08-01 00:37:59 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
2020-09-18 19:56:24 +00:00
|
|
|
"go.pinniped.dev/test/library"
|
2020-08-01 00:37:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetAPIResourceList(t *testing.T) {
|
2020-08-07 01:44:14 +00:00
|
|
|
library.SkipUnlessIntegration(t)
|
|
|
|
|
2020-11-13 18:09:22 +00:00
|
|
|
client := library.NewClientset(t)
|
2020-08-01 00:37:59 +00:00
|
|
|
groups, resources, err := client.Discovery().ServerGroupsAndResources()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-09 15:36:38 +00:00
|
|
|
tests := []struct {
|
|
|
|
group metav1.APIGroup
|
|
|
|
resourceByVersion map[string][]metav1.APIResource
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2020-10-30 14:34:43 +00:00
|
|
|
Name: "login.concierge.pinniped.dev",
|
2020-09-09 15:36:38 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2020-10-30 14:34:43 +00:00
|
|
|
GroupVersion: "login.concierge.pinniped.dev/v1alpha1",
|
2020-09-09 15:36:38 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2020-10-30 14:34:43 +00:00
|
|
|
GroupVersion: "login.concierge.pinniped.dev/v1alpha1",
|
2020-09-09 15:23:28 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2020-10-30 14:34:43 +00:00
|
|
|
"login.concierge.pinniped.dev/v1alpha1": {
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
2020-09-18 22:15:04 +00:00
|
|
|
Name: "tokencredentialrequests",
|
|
|
|
Kind: "TokenCredentialRequest",
|
2020-09-09 15:36:38 +00:00
|
|
|
Verbs: []string{"create"},
|
2020-09-18 22:15:04 +00:00
|
|
|
Namespaced: true,
|
2020-11-13 18:09:22 +00:00
|
|
|
Categories: []string{"pinniped"},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:23:28 +00:00
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2020-10-30 20:09:14 +00:00
|
|
|
Name: "config.supervisor.pinniped.dev",
|
2020-09-09 15:36:38 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2020-10-30 20:09:14 +00:00
|
|
|
GroupVersion: "config.supervisor.pinniped.dev/v1alpha1",
|
2020-09-09 15:36:38 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2020-10-30 20:09:14 +00:00
|
|
|
GroupVersion: "config.supervisor.pinniped.dev/v1alpha1",
|
2020-09-09 15:36:38 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
2020-09-09 15:23:28 +00:00
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2020-10-30 20:09:14 +00:00
|
|
|
"config.supervisor.pinniped.dev/v1alpha1": {
|
2020-10-07 00:53:29 +00:00
|
|
|
{
|
2020-11-02 22:24:55 +00:00
|
|
|
Name: "oidcproviders",
|
|
|
|
SingularName: "oidcprovider",
|
2020-10-07 00:53:29 +00:00
|
|
|
Namespaced: true,
|
2020-11-02 22:24:55 +00:00
|
|
|
Kind: "OIDCProvider",
|
2020-10-07 00:53:29 +00:00
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
2020-11-12 22:24:25 +00:00
|
|
|
Categories: []string{"pinniped"},
|
2020-10-07 00:53:29 +00:00
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-11-12 00:28:42 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
|
|
|
Name: "idp.supervisor.pinniped.dev",
|
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
|
|
|
GroupVersion: "idp.supervisor.pinniped.dev/v1alpha1",
|
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
|
|
|
GroupVersion: "idp.supervisor.pinniped.dev/v1alpha1",
|
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
|
|
|
"idp.supervisor.pinniped.dev/v1alpha1": {
|
|
|
|
{
|
|
|
|
Name: "upstreamoidcproviders",
|
|
|
|
SingularName: "upstreamoidcprovider",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "UpstreamOIDCProvider",
|
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
Categories: []string{"pinniped", "pinniped-idp", "pinniped-idps"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "upstreamoidcproviders/status",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "UpstreamOIDCProvider",
|
|
|
|
Verbs: []string{"get", "patch", "update"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-10-30 20:09:14 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
|
|
|
Name: "config.concierge.pinniped.dev",
|
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
|
|
|
GroupVersion: "config.concierge.pinniped.dev/v1alpha1",
|
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
|
|
|
GroupVersion: "config.concierge.pinniped.dev/v1alpha1",
|
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
|
|
|
"config.concierge.pinniped.dev/v1alpha1": {
|
|
|
|
{
|
2020-11-02 21:39:43 +00:00
|
|
|
Name: "credentialissuers",
|
|
|
|
SingularName: "credentialissuer",
|
2020-10-30 20:09:14 +00:00
|
|
|
Namespaced: true,
|
2020-11-02 21:39:43 +00:00
|
|
|
Kind: "CredentialIssuer",
|
2020-10-30 20:09:14 +00:00
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
2020-11-12 22:24:25 +00:00
|
|
|
Categories: []string{"pinniped"},
|
2020-10-30 20:09:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2020-10-30 16:03:25 +00:00
|
|
|
Name: "authentication.concierge.pinniped.dev",
|
2020-09-09 15:36:38 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2020-10-30 16:03:25 +00:00
|
|
|
GroupVersion: "authentication.concierge.pinniped.dev/v1alpha1",
|
2020-09-09 15:36:38 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2020-10-30 16:03:25 +00:00
|
|
|
GroupVersion: "authentication.concierge.pinniped.dev/v1alpha1",
|
2020-09-09 15:36:38 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2020-10-30 16:03:25 +00:00
|
|
|
"authentication.concierge.pinniped.dev/v1alpha1": {
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
2020-10-30 16:39:26 +00:00
|
|
|
Name: "webhookauthenticators",
|
|
|
|
SingularName: "webhookauthenticator",
|
2020-09-09 15:36:38 +00:00
|
|
|
Namespaced: true,
|
2020-10-30 16:39:26 +00:00
|
|
|
Kind: "WebhookAuthenticator",
|
2020-09-09 15:36:38 +00:00
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
2020-11-12 22:24:25 +00:00
|
|
|
Categories: []string{"pinniped", "pinniped-authenticator", "pinniped-authenticators"},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
2020-12-08 01:37:43 +00:00
|
|
|
{
|
|
|
|
Name: "jwtauthenticators",
|
|
|
|
SingularName: "jwtauthenticator",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "JWTAuthenticator",
|
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
Categories: []string{"pinniped", "pinniped-authenticator", "pinniped-authenticators"},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-08-01 00:37:59 +00:00
|
|
|
}
|
2020-09-09 15:23:28 +00:00
|
|
|
|
2020-11-12 22:24:25 +00:00
|
|
|
t.Run("every Pinniped API has explicit test coverage", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
testedGroups := map[string]bool{}
|
|
|
|
for _, tt := range tests {
|
|
|
|
testedGroups[tt.group.Name] = true
|
|
|
|
}
|
|
|
|
for _, g := range groups {
|
|
|
|
if !strings.Contains(g.Name, "pinniped.dev") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
assert.Truef(t, testedGroups[g.Name], "expected group %q to have assertions defined", g.Name)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("every API categorized appropriately", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
for _, r := range resources {
|
|
|
|
if !strings.Contains(r.GroupVersion, "pinniped.dev") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, a := range r.APIResources {
|
2020-11-12 00:28:42 +00:00
|
|
|
if strings.HasSuffix(a.Name, "/status") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
assert.Containsf(t, a.Categories, "pinniped", "expected resource %q to be in the 'pinniped' category", a.Name)
|
2020-11-13 18:09:22 +00:00
|
|
|
assert.NotContainsf(t, a.Categories, "all", "expected resource %q not to be in the 'all' category", a.Name)
|
2020-11-12 22:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-11-12 22:49:21 +00:00
|
|
|
t.Run("Pinniped resources do not have short names", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
for _, r := range resources {
|
|
|
|
if !strings.Contains(r.GroupVersion, "pinniped.dev") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, a := range r.APIResources {
|
|
|
|
assert.Empty(t, a.ShortNames, "expected resource %q not to have any short names", a.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-09 15:36:38 +00:00
|
|
|
for _, tt := range tests {
|
|
|
|
tt := tt
|
|
|
|
t.Run(tt.group.Name, func(t *testing.T) {
|
2020-11-12 22:24:25 +00:00
|
|
|
t.Parallel()
|
2020-09-09 15:36:38 +00:00
|
|
|
require.Contains(t, groups, &tt.group)
|
|
|
|
|
|
|
|
for groupVersion, expectedResources := range tt.resourceByVersion {
|
|
|
|
// Find the actual resource list and make a copy.
|
|
|
|
var actualResourceList *metav1.APIResourceList
|
|
|
|
for _, resource := range resources {
|
|
|
|
if resource.GroupVersion == groupVersion {
|
|
|
|
actualResourceList = resource.DeepCopy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotNilf(t, actualResourceList, "could not find groupVersion %s", groupVersion)
|
|
|
|
|
|
|
|
// Because its hard to predict the storage version hash (e.g. "t/+v41y+3e4="), we just don't
|
|
|
|
// worry about comparing that field.
|
|
|
|
for i := range actualResourceList.APIResources {
|
|
|
|
actualResourceList.APIResources[i].StorageVersionHash = ""
|
|
|
|
}
|
2020-10-07 18:42:30 +00:00
|
|
|
require.ElementsMatch(t, expectedResources, actualResourceList.APIResources, "unexpected API resources")
|
2020-09-09 15:36:38 +00:00
|
|
|
}
|
|
|
|
})
|
2020-09-09 15:23:28 +00:00
|
|
|
}
|
2020-08-01 00:37:59 +00:00
|
|
|
}
|