Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip Aleksic <faleksic@gitlab.com>2022-07-26 10:53:41 +0300
committerJaime Martinez <jmartinez@gitlab.com>2022-07-26 10:53:41 +0300
commita131f2bdf10e2815d79e3581fe6536b1499839b6 (patch)
tree723189f5398744b7e5a0e260835a0c38f84f2f66 /test/acceptance/acme_test.go
parent0674de2e8e74a35bec70380b02da63dd7db1b8bb (diff)
Fixes acme redirection issues when using a wildcard redirect
Changelog: fixed
Diffstat (limited to 'test/acceptance/acme_test.go')
-rw-r--r--test/acceptance/acme_test.go54
1 files changed, 54 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)
+ })
+ }
+}