2022-03-08 20:28:09 +00:00
|
|
|
// Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
|
2020-10-21 22:24:48 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-12-15 20:48:55 +00:00
|
|
|
"crypto/tls"
|
2020-10-21 22:24:48 +00:00
|
|
|
"fmt"
|
2022-08-24 21:45:55 +00:00
|
|
|
"io"
|
2020-10-21 22:24:48 +00:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-06-22 15:23:19 +00:00
|
|
|
"go.pinniped.dev/test/testlib"
|
2020-10-21 22:24:48 +00:00
|
|
|
)
|
|
|
|
|
2021-12-15 20:48:55 +00:00
|
|
|
// Never run this test in parallel since deleting all federation domains and the default TLS secret is disruptive, see main_test.go.
|
|
|
|
func TestSupervisorHealthzBootstrap_Disruptive(t *testing.T) {
|
|
|
|
env := testlib.IntegrationEnv(t)
|
|
|
|
pinnipedClient := testlib.NewSupervisorClientset(t)
|
|
|
|
kubeClient := testlib.NewKubernetesClientset(t)
|
|
|
|
|
|
|
|
ns := env.SupervisorNamespace
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
temporarilyRemoveAllFederationDomainsAndDefaultTLSCertSecret(ctx, t, ns, defaultTLSCertSecretName(env), pinnipedClient, kubeClient)
|
|
|
|
|
|
|
|
httpClient := &http.Client{
|
|
|
|
Transport: &http.Transport{
|
|
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec // there is no way for us to know the bootstrap CA
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const badTLSConfigBody = "pinniped supervisor has invalid TLS serving certificate configuration\n"
|
|
|
|
|
|
|
|
httpGet(ctx, t, httpClient, fmt.Sprintf("https://%s/healthz", env.SupervisorHTTPSAddress), http.StatusOK, "ok")
|
|
|
|
httpGet(ctx, t, httpClient, fmt.Sprintf("https://%s", env.SupervisorHTTPSAddress), http.StatusInternalServerError, badTLSConfigBody)
|
|
|
|
httpGet(ctx, t, httpClient, fmt.Sprintf("https://%s/nothealthz", env.SupervisorHTTPSAddress), http.StatusInternalServerError, badTLSConfigBody)
|
|
|
|
httpGet(ctx, t, httpClient, fmt.Sprintf("https://%s/healthz/something", env.SupervisorHTTPSAddress), http.StatusInternalServerError, badTLSConfigBody)
|
|
|
|
}
|
|
|
|
|
|
|
|
func httpGet(ctx context.Context, t *testing.T, client *http.Client, url string, expectedStatus int, expectedBody string) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(
|
2020-10-21 22:24:48 +00:00
|
|
|
ctx,
|
|
|
|
http.MethodGet,
|
2021-12-15 20:48:55 +00:00
|
|
|
url,
|
2020-10-21 22:24:48 +00:00
|
|
|
nil,
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-08 20:28:09 +00:00
|
|
|
response, err := client.Do(req)
|
2020-10-21 22:24:48 +00:00
|
|
|
require.NoError(t, err)
|
2021-12-15 20:48:55 +00:00
|
|
|
require.Equal(t, expectedStatus, response.StatusCode)
|
2020-10-21 22:24:48 +00:00
|
|
|
|
2022-08-24 21:45:55 +00:00
|
|
|
responseBody, err := io.ReadAll(response.Body)
|
2020-10-21 22:24:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
err = response.Body.Close()
|
|
|
|
require.NoError(t, err)
|
2021-12-15 20:48:55 +00:00
|
|
|
require.Equal(t, expectedBody, string(responseBody))
|
2020-10-21 22:24:48 +00:00
|
|
|
}
|