diff options
author | Filip Aleksic <faleksic@gitlab.com> | 2022-07-26 10:53:41 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2022-07-26 10:53:41 +0300 |
commit | a131f2bdf10e2815d79e3581fe6536b1499839b6 (patch) | |
tree | 723189f5398744b7e5a0e260835a0c38f84f2f66 /test | |
parent | 0674de2e8e74a35bec70380b02da63dd7db1b8bb (diff) |
Fixes acme redirection issues when using a wildcard redirect
Changelog: fixed
Diffstat (limited to 'test')
-rw-r--r-- | test/acceptance/acme_test.go | 54 | ||||
-rw-r--r-- | test/gitlabstub/api_responses.go | 4 |
2 files changed, 58 insertions, 0 deletions
diff --git a/test/acceptance/acme_test.go b/test/acceptance/acme_test.go index 40d98a21..89c57c96 100644 --- a/test/acceptance/acme_test.go +++ b/test/acceptance/acme_test.go @@ -7,6 +7,8 @@ import ( "testing" "github.com/stretchr/testify/require" + + "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers" ) const ( @@ -97,3 +99,55 @@ func TestAcmeChallengesWhenItIsConfigured(t *testing.T) { }) } } + +func TestAcmeChallengesNoRedirection(t *testing.T) { + RunPagesProcess(t, + withListeners([]ListenSpec{httpListener}), + withExtraArgument("gitlab-server", "https://gitlab-acme.com"), + ) + + tests := map[string]struct { + path string + expectedStatus int + expectedContent string + expectedLocation string + }{ + "wildcard redirect should not redirect acme challenge": { + path: existingAcmeTokenPath, + expectedStatus: http.StatusOK, + expectedContent: "this is token\n", + }, + "non-acme paths should be redirected": { + path: "/example", + // rule inside _redirects is a 200 rewrite of /index.html + expectedStatus: http.StatusOK, + expectedContent: "acme-challenge-project\n", + }, + "When domain folder doesn't contain requested acme challenge it redirects to GitLab": { + path: notExistingAcmeTokenPath, + expectedStatus: http.StatusTemporaryRedirect, + expectedContent: "", + expectedLocation: "https://gitlab-acme.com/-/acme-challenge?domain=acmewithredirects.domain.com&token=notexistingtoken", + }, + } + + for tn, tt := range tests { + t.Run(tn, func(t *testing.T) { + rsp, err := GetRedirectPage(t, httpListener, "acmewithredirects.domain.com", tt.path) + require.NoError(t, err) + testhelpers.Close(t, rsp.Body) + + require.Equal(t, tt.expectedStatus, rsp.StatusCode) + body, err := io.ReadAll(rsp.Body) + require.NoError(t, rsp.Body.Close()) + require.NoError(t, err) + + require.Contains(t, string(body), tt.expectedContent) + + redirectURL, err := url.Parse(rsp.Header.Get("Location")) + require.NoError(t, err) + + require.Equal(t, redirectURL.String(), tt.expectedLocation) + }) + } +} diff --git a/test/gitlabstub/api_responses.go b/test/gitlabstub/api_responses.go index 3ebf4e1f..93bc8995 100644 --- a/test/gitlabstub/api_responses.go +++ b/test/gitlabstub/api_responses.go @@ -110,6 +110,10 @@ var domainResponses = map[string]responseFn{ accessControl: true, pathOnDisk: "group.auth/private.project", }), + "acmewithredirects.domain.com": customDomain(projectConfig{ + projectID: 1008, + pathOnDisk: "group.acme/with.redirects", + }), // 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 |