diff options
author | Vishal Tak <vtak@gitlab.com> | 2022-06-01 15:59:58 +0300 |
---|---|---|
committer | Vishal Tak <vtak@gitlab.com> | 2022-06-02 09:28:49 +0300 |
commit | 2624810f74b8ea239a02d09f5a21def3e1076fda (patch) | |
tree | 9bf58d9b73e17efdcc420eb4284ce7c12fa63fe4 /test/acceptance | |
parent | 8488ef56611256c1761f93de5f8df23e07b86af4 (diff) |
Use TLSConfig and remove IsHTTPS in Metrics config
Add unit tests and move acceptance tests
Diffstat (limited to 'test/acceptance')
-rw-r--r-- | test/acceptance/config_test.go | 27 | ||||
-rw-r--r-- | test/acceptance/metrics_test.go | 25 |
2 files changed, 25 insertions, 27 deletions
diff --git a/test/acceptance/config_test.go b/test/acceptance/config_test.go index 011b4c73..95be6e17 100644 --- a/test/acceptance/config_test.go +++ b/test/acceptance/config_test.go @@ -1,7 +1,6 @@ package acceptance_test import ( - "crypto/tls" "fmt" "net" "net/http" @@ -9,7 +8,6 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers" ) func TestEnvironmentVariablesConfig(t *testing.T) { @@ -88,28 +86,3 @@ func TestUnixSocketListener(t *testing.T) { rsp.Body.Close() require.Equal(t, http.StatusOK, rsp.StatusCode) } - -func TestMetricsHTTPSConfig(t *testing.T) { - keyFile, certFile := CreateHTTPSFixtureFiles(t) - - RunPagesProcess(t, - withExtraArgument("metrics-address", ":42345"), - withExtraArgument("metrics-certificate", certFile), - withExtraArgument("metrics-key", keyFile), - ) - require.NoError(t, httpsListener.WaitUntilRequestSucceeds(nil)) - - tlsConfig := &tls.Config{InsecureSkipVerify: true} - transport := &http.Transport{TLSClientConfig: tlsConfig} - client := &http.Client{Transport: transport} - - res, err := client.Get("https://127.0.0.1:42345/metrics") - require.NoError(t, err) - testhelpers.Close(t, res.Body) - require.Equal(t, http.StatusOK, res.StatusCode) - - res, err = client.Get("http://127.0.0.1:42345/metrics") - require.NoError(t, err) - testhelpers.Close(t, res.Body) - require.Equal(t, http.StatusBadRequest, res.StatusCode) -} diff --git a/test/acceptance/metrics_test.go b/test/acceptance/metrics_test.go index d1e8a1b6..193d21e7 100644 --- a/test/acceptance/metrics_test.go +++ b/test/acceptance/metrics_test.go @@ -1,6 +1,7 @@ package acceptance_test import ( + "crypto/tls" "io" "net/http" "testing" @@ -58,3 +59,27 @@ func TestPrometheusMetricsCanBeScraped(t *testing.T) { require.Contains(t, string(body), "gitlab_pages_limit_listener_concurrent_conns") require.Contains(t, string(body), "gitlab_pages_limit_listener_waiting_conns") } + +func TestMetricsHTTPSConnection(t *testing.T) { + keyFile, certFile := CreateHTTPSFixtureFiles(t) + + RunPagesProcess(t, + withExtraArgument("metrics-address", ":42345"), + withExtraArgument("metrics-certificate", certFile), + withExtraArgument("metrics-key", keyFile), + ) + + tlsConfig := &tls.Config{InsecureSkipVerify: true} + transport := &http.Transport{TLSClientConfig: tlsConfig} + client := &http.Client{Transport: transport} + + res, err := client.Get("https://127.0.0.1:42345/metrics") + require.NoError(t, err) + testhelpers.Close(t, res.Body) + require.Equal(t, http.StatusOK, res.StatusCode) + + res, err = client.Get("http://127.0.0.1:42345/metrics") + require.NoError(t, err) + testhelpers.Close(t, res.Body) + require.Equal(t, http.StatusBadRequest, res.StatusCode) +} |