diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-07-15 09:41:28 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-07-15 09:41:28 +0300 |
commit | 4f6452e22c1a375163765dc2fa61f187f7dd8941 (patch) | |
tree | 6189508dc2760c7ffb1dbe8e1b63650320320d34 /test | |
parent | ec465142275e62f2251bc6e27c500714d92e7ec2 (diff) |
Update redirect tests
Diffstat (limited to 'test')
-rw-r--r-- | test/acceptance/redirects_test.go | 16 | ||||
-rw-r--r-- | test/acceptance/testdata/api_responses.go | 16 |
2 files changed, 25 insertions, 7 deletions
diff --git a/test/acceptance/redirects_test.go b/test/acceptance/redirects_test.go index 7fd7caab..c7feafca 100644 --- a/test/acceptance/redirects_test.go +++ b/test/acceptance/redirects_test.go @@ -10,8 +10,10 @@ import ( ) func TestDisabledRedirects(t *testing.T) { - teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, supportedListeners(), "", []string{"FF_ENABLE_REDIRECTS=false"}) - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpListener}), + withEnv([]string{"FF_ENABLE_REDIRECTS=false"}), + ) // Test that redirects status page is forbidden rsp, err := GetPageFromListener(t, httpListener, "group.redirects.gitlab-example.com", "/project-redirects/_redirects") @@ -29,8 +31,9 @@ func TestDisabledRedirects(t *testing.T) { } func TestRedirectStatusPage(t *testing.T) { - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "") - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpListener}), + ) rsp, err := GetPageFromListener(t, httpListener, "group.redirects.gitlab-example.com", "/project-redirects/_redirects") require.NoError(t, err) @@ -44,8 +47,9 @@ func TestRedirectStatusPage(t *testing.T) { } func TestRedirect(t *testing.T) { - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "") - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpListener}), + ) // Test that serving a file still works with redirects enabled rsp, err := GetRedirectPage(t, httpListener, "group.redirects.gitlab-example.com", "/project-redirects/index.html") diff --git a/test/acceptance/testdata/api_responses.go b/test/acceptance/testdata/api_responses.go index 07349466..227a72fd 100644 --- a/test/acceptance/testdata/api_responses.go +++ b/test/acceptance/testdata/api_responses.go @@ -46,6 +46,11 @@ var DomainResponses = map[string]responseFn{ projectID: 1234, pathOnDisk: "group.acme/with.acme.challenge", }), + "group.redirects.gitlab-example.com": generateVirtualDomainFromDir("group.redirects", "group.redirects.gitlab-example.com", nil), + "redirects.custom-domain.com": customDomain(projectConfig{ + projectID: 1001, + pathOnDisk: "group.redirects/custom-domain", + }), // 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 @@ -102,7 +107,8 @@ func generateVirtualDomainFromDir(dir, rootDomain string, perPrefixConfig map[st ProjectID: cfg.projectID, AccessControl: cfg.accessControl, HTTPSOnly: cfg.https, - Prefix: prefix, + // gitlab.Resolve logic expects prefix to have ending slash + Prefix: ensureEndingSlash(prefix), Source: api.Source{ Type: "zip", Path: fmt.Sprintf("file://%s", wd+"/"+dir+project), @@ -152,3 +158,11 @@ func customDomain(config projectConfig) responseFn { } } } + +func ensureEndingSlash(path string) string { + if strings.HasSuffix(path, "/") { + return path + } + + return path + "/" +} |