diff options
Diffstat (limited to 'test/acceptance/serving_test.go')
-rw-r--r-- | test/acceptance/serving_test.go | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go index 92727d28..32291e52 100644 --- a/test/acceptance/serving_test.go +++ b/test/acceptance/serving_test.go @@ -163,8 +163,8 @@ func TestNestedSubgroups(t *testing.T) { func TestCustom404(t *testing.T) { skipUnlessEnabled(t) - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "") - defer teardown() + + RunPagesProcessWithStubGitLabServer(t) tests := []struct { host string @@ -334,30 +334,35 @@ func TestHttpToHttpsRedirectEnabled(t *testing.T) { require.Equal(t, http.StatusOK, rsp.StatusCode) } -func TestHttpsOnlyGroupEnabled(t *testing.T) { - skipUnlessEnabled(t) - - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "") - defer teardown() - - // TODO: allow configuring HTTPS responses from stub https://gitlab.com/gitlab-org/gitlab-pages/-/issues/571 - // Related MR in progress https://gitlab.com/gitlab-org/gitlab-pages/-/merge_requests/498 - rsp, err := GetRedirectPage(t, httpListener, "group.https-only.gitlab-example.com", "project1/") - require.NoError(t, err) - defer rsp.Body.Close() - require.Equal(t, http.StatusMovedPermanently, rsp.StatusCode) -} +func TestHTTPSRedirect(t *testing.T) { + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpListener}), + ) -func TestHttpsOnlyGroupDisabled(t *testing.T) { - skipUnlessEnabled(t) + tests := map[string]struct { + path string + expectedStatus int + }{ + "domain_https_only_true": { + path: "project1/", + expectedStatus: http.StatusMovedPermanently, + }, + "domain_https_only_false": { + path: "project2/", + expectedStatus: http.StatusOK, + }, + } - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "") - defer teardown() + 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) + require.NoError(t, err) + defer rsp.Body.Close() - rsp, err := GetPageFromListener(t, httpListener, "group.https-only.gitlab-example.com", "project2/") - require.NoError(t, err) - defer rsp.Body.Close() - require.Equal(t, http.StatusOK, rsp.StatusCode) + require.Equal(t, test.expectedStatus, rsp.StatusCode) + }) + } } func TestHttpsOnlyProjectEnabled(t *testing.T) { |