2022-06-08 17:22:15 +00:00
|
|
|
// Copyright 2021-2022 the Pinniped contributors. All Rights Reserved.
|
2021-02-05 15:55:19 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os/exec"
|
2021-03-16 22:22:28 +00:00
|
|
|
"strings"
|
2021-02-05 15:55:19 +00:00
|
|
|
"testing"
|
2021-03-02 20:17:27 +00:00
|
|
|
"time"
|
2021-02-05 15:55:19 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-06-22 15:23:19 +00:00
|
|
|
"go.pinniped.dev/test/testlib"
|
2021-02-05 15:55:19 +00:00
|
|
|
)
|
|
|
|
|
2021-03-16 22:22:28 +00:00
|
|
|
func runTestKubectlCommand(t *testing.T, args ...string) (string, string) {
|
|
|
|
t.Helper()
|
|
|
|
var stdOut, stdErr bytes.Buffer
|
2021-06-22 15:23:19 +00:00
|
|
|
testlib.RequireEventually(t, func(requireEventually *require.Assertions) {
|
2021-03-16 22:22:28 +00:00
|
|
|
stdOut.Reset()
|
|
|
|
stdErr.Reset()
|
|
|
|
cmd := exec.Command("kubectl", args...)
|
|
|
|
cmd.Stdout = &stdOut
|
|
|
|
cmd.Stderr = &stdErr
|
2021-06-16 22:51:23 +00:00
|
|
|
requireEventually.NoError(cmd.Run())
|
|
|
|
}, 120*time.Second, 200*time.Millisecond)
|
2021-03-16 22:22:28 +00:00
|
|
|
return stdOut.String(), stdErr.String()
|
|
|
|
}
|
2021-03-30 17:29:29 +00:00
|
|
|
|
|
|
|
func requireCleanKubectlStderr(t *testing.T, stderr string) {
|
|
|
|
// Every line must be empty or contain a known, innocuous warning.
|
|
|
|
for _, line := range strings.Split(stderr, "\n") {
|
2022-06-08 17:22:15 +00:00
|
|
|
switch {
|
|
|
|
case strings.TrimSpace(line) == "",
|
|
|
|
strings.Contains(line, "Throttling request took"),
|
|
|
|
strings.Contains(line, "due to client-side throttling, not priority and fairness"),
|
2022-08-25 15:11:37 +00:00
|
|
|
strings.Contains(line, "the gcp auth plugin is deprecated in v1.22+, unavailable in "),
|
2022-06-08 17:22:15 +00:00
|
|
|
strings.Contains(line, "To learn more, consult https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke"):
|
|
|
|
// ignore these allowed stderr lines
|
|
|
|
default:
|
|
|
|
// anything else is a failure
|
|
|
|
require.Failf(t, "unexpected kubectl stderr", "kubectl produced unexpected stderr:\n%s\n\n", stderr)
|
|
|
|
return
|
2021-03-30 17:29:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:55:19 +00:00
|
|
|
func TestGetPinnipedCategory(t *testing.T) {
|
2021-06-22 15:23:19 +00:00
|
|
|
env := testlib.IntegrationEnv(t)
|
2021-02-05 15:55:19 +00:00
|
|
|
dotSuffix := "." + env.APIGroupSuffix
|
|
|
|
|
|
|
|
t.Run("category, no special params", func(t *testing.T) {
|
2021-03-16 22:22:28 +00:00
|
|
|
t.Parallel()
|
|
|
|
stdout, stderr := runTestKubectlCommand(t, "get", "pinniped", "-A")
|
2021-03-30 17:29:29 +00:00
|
|
|
requireCleanKubectlStderr(t, stderr)
|
2021-03-16 22:22:28 +00:00
|
|
|
require.NotContains(t, stdout, "MethodNotAllowed")
|
|
|
|
require.Contains(t, stdout, dotSuffix)
|
2021-02-05 15:55:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("category, table params", func(t *testing.T) {
|
2021-03-16 22:22:28 +00:00
|
|
|
t.Parallel()
|
|
|
|
stdout, stderr := runTestKubectlCommand(t, "get", "pinniped", "-A", "-o", "wide", "-v", "10")
|
|
|
|
require.NotContains(t, stdout, "MethodNotAllowed")
|
|
|
|
require.Contains(t, stdout, dotSuffix)
|
|
|
|
require.Contains(t, stderr, `"kind":"Table"`)
|
|
|
|
require.Contains(t, stderr, `"resourceVersion":"0"`)
|
|
|
|
require.Contains(t, stderr, `/v1alpha1/tokencredentialrequests`)
|
|
|
|
require.Contains(t, stderr, `/v1alpha1/whoamirequests`)
|
2021-02-05 15:55:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("list, no special params", func(t *testing.T) {
|
2021-03-16 22:22:28 +00:00
|
|
|
t.Parallel()
|
|
|
|
stdout, stderr := runTestKubectlCommand(t, "get", "tokencredentialrequests.login.concierge"+dotSuffix, "-A")
|
|
|
|
require.Empty(t, stdout)
|
|
|
|
require.NotContains(t, stderr, "MethodNotAllowed")
|
|
|
|
require.Contains(t, stderr, `No resources found`)
|
2021-02-05 15:55:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("list, table params", func(t *testing.T) {
|
2021-03-16 22:22:28 +00:00
|
|
|
t.Parallel()
|
|
|
|
stdout, stderr := runTestKubectlCommand(t, "get", "tokencredentialrequests.login.concierge"+dotSuffix, "-A", "-o", "wide", "-v", "10")
|
|
|
|
require.Empty(t, stdout)
|
|
|
|
require.NotContains(t, stderr, "MethodNotAllowed")
|
|
|
|
require.Contains(t, stderr, `"kind":"Table"`)
|
|
|
|
require.Contains(t, stderr, `"resourceVersion":"0"`)
|
2021-02-05 15:55:19 +00:00
|
|
|
})
|
|
|
|
|
2021-02-19 18:21:10 +00:00
|
|
|
t.Run("raw request to see body, token cred", func(t *testing.T) {
|
2021-03-16 22:22:28 +00:00
|
|
|
t.Parallel()
|
|
|
|
stdout, stderr := runTestKubectlCommand(t, "get", "--raw", "/apis/login.concierge"+dotSuffix+"/v1alpha1/tokencredentialrequests")
|
|
|
|
require.NotContains(t, stdout, "MethodNotAllowed")
|
|
|
|
require.Contains(t, stdout, `{"kind":"TokenCredentialRequestList","apiVersion":"login.concierge`+
|
2021-02-05 15:55:19 +00:00
|
|
|
dotSuffix+`/v1alpha1","metadata":{"resourceVersion":"0"},"items":[]}`)
|
2021-03-30 17:29:29 +00:00
|
|
|
requireCleanKubectlStderr(t, stderr)
|
2021-02-05 15:55:19 +00:00
|
|
|
})
|
2021-02-19 18:21:10 +00:00
|
|
|
|
|
|
|
t.Run("raw request to see body, whoami", func(t *testing.T) {
|
2021-03-16 22:22:28 +00:00
|
|
|
t.Parallel()
|
|
|
|
stdout, stderr := runTestKubectlCommand(t, "get", "--raw", "/apis/identity.concierge"+dotSuffix+"/v1alpha1/whoamirequests")
|
|
|
|
require.NotContains(t, stdout, "MethodNotAllowed")
|
|
|
|
require.Contains(t, stdout, `{"kind":"WhoAmIRequestList","apiVersion":"identity.concierge`+
|
2021-02-19 18:21:10 +00:00
|
|
|
dotSuffix+`/v1alpha1","metadata":{"resourceVersion":"0"},"items":[]}`)
|
2021-03-30 17:29:29 +00:00
|
|
|
requireCleanKubectlStderr(t, stderr)
|
2021-02-19 18:21:10 +00:00
|
|
|
})
|
2021-02-05 15:55:19 +00:00
|
|
|
}
|