diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-07-19 09:13:39 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-07-19 09:13:39 +0300 |
commit | e3ae6279faffc6005de53ec1c2a0fa15da706d22 (patch) | |
tree | 034973d7894c43bf7eb44960e6ef41ead4639cb1 /test/acceptance | |
parent | 224b20ad8bcb8bd3b8d067588524677aee9b4894 (diff) |
Update status and serving tests
Diffstat (limited to 'test/acceptance')
-rw-r--r-- | test/acceptance/serving_test.go | 58 | ||||
-rw-r--r-- | test/acceptance/status_test.go | 42 | ||||
-rw-r--r-- | test/acceptance/stub_test.go | 6 | ||||
-rw-r--r-- | test/acceptance/testdata/api_responses.go | 7 |
4 files changed, 60 insertions, 53 deletions
diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go index 23df429d..91e1181b 100644 --- a/test/acceptance/serving_test.go +++ b/test/acceptance/serving_test.go @@ -314,62 +314,53 @@ func TestHTTPSRedirect(t *testing.T) { ) tests := map[string]struct { + domain string path string expectedStatus int }{ "domain_https_only_true": { + domain: "group.https-only.gitlab-example.com", path: "project1/", expectedStatus: http.StatusMovedPermanently, }, "domain_https_only_false": { + domain: "group.https-only.gitlab-example.com", path: "project2/", expectedStatus: http.StatusOK, }, + "custom_domain_https_enabled": { + domain: "test.my-domain.com", + path: "/index.html", + expectedStatus: http.StatusMovedPermanently, + }, + "custom_domain_https_disabled": { + domain: "test2.my-domain.com", + path: "/", + expectedStatus: http.StatusOK, + }, + "custom_domain_https_enabled_with_bad_certificate_is_still_redirected": { + domain: "no.cert.com", + path: "/", + expectedStatus: http.StatusMovedPermanently, + }, } for name, test := range tests { t.Run(name, func(t *testing.T) { // see testdata/api_responses.go for per prefix configuration response from the API - rsp, err := GetRedirectPage(t, httpListener, "group.https-only.gitlab-example.com", test.path) + rsp, err := GetRedirectPage(t, httpListener, test.domain, test.path) require.NoError(t, err) - defer rsp.Body.Close() + + t.Cleanup(func() { + rsp.Body.Close() + }) require.Equal(t, test.expectedStatus, rsp.StatusCode) }) } } -func TestHttpsOnlyProjectEnabled(t *testing.T) { - RunPagesProcessWithStubGitLabServer(t, - withListeners([]ListenSpec{httpListener}), - ) - - rsp, err := GetRedirectPage(t, httpListener, "test.my-domain.com", "/index.html") - require.NoError(t, err) - defer rsp.Body.Close() - require.Equal(t, http.StatusMovedPermanently, rsp.StatusCode) -} - -func TestHttpsOnlyProjectDisabled(t *testing.T) { - RunPagesProcessWithStubGitLabServer(t, - withListeners([]ListenSpec{httpListener}), - ) - rsp, err := GetPageFromListener(t, httpListener, "test2.my-domain.com", "/") - require.NoError(t, err) - defer rsp.Body.Close() - require.Equal(t, http.StatusOK, rsp.StatusCode) -} - -func TestHttpsOnlyDomainDisabled(t *testing.T) { - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "") - defer teardown() - - rsp, err := GetPageFromListener(t, httpListener, "no.cert.com", "/") - require.NoError(t, err) - defer rsp.Body.Close() - require.Equal(t, http.StatusOK, rsp.StatusCode) -} - +// TODO: remove with domain-source-config https://gitlab.com/gitlab-org/gitlab-pages/-/issues/382 func TestDomainsSource(t *testing.T) { type args struct { configSource string @@ -513,6 +504,7 @@ func TestDomainsSource(t *testing.T) { // TestGitLabSourceBecomesUnauthorized proves workaround for https://gitlab.com/gitlab-org/gitlab-pages/-/issues/535 // The first request will fail and display an error but subsequent requests will // serve from disk source when `domain-config-source=auto` +// TODO: remove with domain-source-config https://gitlab.com/gitlab-org/gitlab-pages/-/issues/382 func TestGitLabSourceBecomesUnauthorized(t *testing.T) { opts := &stubOpts{ // edge case https://gitlab.com/gitlab-org/gitlab-pages/-/issues/535 diff --git a/test/acceptance/status_test.go b/test/acceptance/status_test.go index 13aa9534..a241da1f 100644 --- a/test/acceptance/status_test.go +++ b/test/acceptance/status_test.go @@ -9,8 +9,10 @@ import ( ) func TestStatusPage(t *testing.T) { - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "", "-pages-status=/@statuscheck") - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpListener}), + withExtraArgument("pages-status", "/@statuscheck"), + ) rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "@statuscheck") require.NoError(t, err) @@ -19,23 +21,25 @@ func TestStatusPage(t *testing.T) { } func TestStatusNotYetReady(t *testing.T) { - teardown := RunPagesProcessWithoutWait(t, *pagesBinary, supportedListeners(), "", "-pages-status=/@statuscheck", "-pages-root=../../shared/invalid-pages") - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withoutWait, + withExtraArgument("pages-status", "/@statuscheck"), + withExtraArgument("pages-root", "../../shared/invalid-pages"), + withStubOptions(&stubOpts{ + statusReadyCount: 100, + }), + ) waitForRoundtrips(t, supportedListeners(), 5*time.Second) - rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "@statuscheck") - require.NoError(t, err) - defer rsp.Body.Close() - require.Equal(t, http.StatusServiceUnavailable, rsp.StatusCode) -} - -func TestPageNotAvailableIfNotLoaded(t *testing.T) { - teardown := RunPagesProcessWithoutWait(t, *pagesBinary, supportedListeners(), "", "-pages-root=../../shared/invalid-pages") - defer teardown() - waitForRoundtrips(t, supportedListeners(), 5*time.Second) - - rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "index.html") - require.NoError(t, err) - defer rsp.Body.Close() - require.Equal(t, http.StatusServiceUnavailable, rsp.StatusCode) + for _, spec := range supportedListeners() { + rsp, err := GetPageFromListener(t, spec, "group.gitlab-example.com", "@statuscheck") + require.NoError(t, err) + defer rsp.Body.Close() + require.Equal(t, http.StatusServiceUnavailable, rsp.StatusCode) + + rsp2, err2 := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "index.html") + require.NoError(t, err2) + defer rsp2.Body.Close() + require.Equal(t, http.StatusServiceUnavailable, rsp2.StatusCode, "page should not be served") + } } diff --git a/test/acceptance/stub_test.go b/test/acceptance/stub_test.go index 6346fe4e..a22f798a 100644 --- a/test/acceptance/stub_test.go +++ b/test/acceptance/stub_test.go @@ -59,6 +59,12 @@ func withArguments(args []string) processOption { } } +func withStubOptions(opts *stubOpts) processOption { + return func(config *processConfig) { + config.gitlabStubOpts = opts + } +} + // makeGitLabPagesAccessStub provides a stub *httptest.Server to check pages_access API call. // the result is based on the project id. // diff --git a/test/acceptance/testdata/api_responses.go b/test/acceptance/testdata/api_responses.go index 2d05b344..b36563bb 100644 --- a/test/acceptance/testdata/api_responses.go +++ b/test/acceptance/testdata/api_responses.go @@ -57,10 +57,15 @@ var DomainResponses = map[string]responseFn{ pathOnDisk: "group.https-only/project3", }), "test2.my-domain.com": customDomain(projectConfig{ - projectID: 1002, + projectID: 1003, https: false, pathOnDisk: "group.https-only/project4", }), + "no.cert.com": customDomain(projectConfig{ + projectID: 1004, + https: true, + pathOnDisk: "group.https-only/project5", + }), // NOTE: before adding more domains here, generate the zip archive by running (per project) // make zip PROJECT_SUBDIR=group/serving // make zip PROJECT_SUBDIR=group/project2 |