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:
Diffstat (limited to 'test/acceptance/redirects_test.go')
-rw-r--r--test/acceptance/redirects_test.go116
1 files changed, 116 insertions, 0 deletions
diff --git a/test/acceptance/redirects_test.go b/test/acceptance/redirects_test.go
new file mode 100644
index 00000000..6c564ce6
--- /dev/null
+++ b/test/acceptance/redirects_test.go
@@ -0,0 +1,116 @@
+package acceptance_test
+
+import (
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestDisabledRedirects(t *testing.T) {
+ skipUnlessEnabled(t)
+
+ teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{"FF_ENABLE_REDIRECTS=false"})
+ defer teardown()
+
+ // Test that redirects status page is forbidden
+ rsp, err := GetPageFromListener(t, httpListener, "group.redirects.gitlab-example.com", "/project-redirects/_redirects")
+ require.NoError(t, err)
+ defer rsp.Body.Close()
+
+ require.Equal(t, http.StatusForbidden, rsp.StatusCode)
+
+ // Test that redirects are disabled
+ rsp, err = GetRedirectPage(t, httpListener, "group.redirects.gitlab-example.com", "/project-redirects/redirect-portal.html")
+ require.NoError(t, err)
+ defer rsp.Body.Close()
+
+ require.Equal(t, http.StatusNotFound, rsp.StatusCode)
+}
+
+func TestRedirectStatusPage(t *testing.T) {
+ skipUnlessEnabled(t)
+
+ teardown := RunPagesProcess(t, *pagesBinary, listeners, "")
+ defer teardown()
+
+ rsp, err := GetPageFromListener(t, httpListener, "group.redirects.gitlab-example.com", "/project-redirects/_redirects")
+ require.NoError(t, err)
+
+ body, err := ioutil.ReadAll(rsp.Body)
+ require.NoError(t, err)
+ defer rsp.Body.Close()
+
+ require.Contains(t, string(body), "11 rules")
+ require.Equal(t, http.StatusOK, rsp.StatusCode)
+}
+
+func TestRedirect(t *testing.T) {
+ skipUnlessEnabled(t)
+
+ teardown := RunPagesProcess(t, *pagesBinary, listeners, "")
+ defer teardown()
+
+ // Test that serving a file still works with redirects enabled
+ rsp, err := GetRedirectPage(t, httpListener, "group.redirects.gitlab-example.com", "/project-redirects/index.html")
+ require.NoError(t, err)
+ defer rsp.Body.Close()
+
+ require.Equal(t, http.StatusOK, rsp.StatusCode)
+
+ tests := []struct {
+ host string
+ path string
+ expectedStatus int
+ expectedLocation string
+ }{
+ // Project domain
+ {
+ host: "group.redirects.gitlab-example.com",
+ path: "/project-redirects/redirect-portal.html",
+ expectedStatus: http.StatusFound,
+ expectedLocation: "/project-redirects/magic-land.html",
+ },
+ // Make sure invalid rule does not redirect
+ {
+ host: "group.redirects.gitlab-example.com",
+ path: "/project-redirects/goto-domain.html",
+ expectedStatus: http.StatusNotFound,
+ expectedLocation: "",
+ },
+ // Actual file on disk should override any redirects that match
+ {
+ host: "group.redirects.gitlab-example.com",
+ path: "/project-redirects/file-override.html",
+ expectedStatus: http.StatusOK,
+ expectedLocation: "",
+ },
+ // Group-level domain
+ {
+ host: "group.redirects.gitlab-example.com",
+ path: "/redirect-portal.html",
+ expectedStatus: http.StatusFound,
+ expectedLocation: "/magic-land.html",
+ },
+ // Custom domain
+ {
+ host: "redirects.custom-domain.com",
+ path: "/redirect-portal.html",
+ expectedStatus: http.StatusFound,
+ expectedLocation: "/magic-land.html",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(fmt.Sprintf("%s%s -> %s (%d)", tt.host, tt.path, tt.expectedLocation, tt.expectedStatus), func(t *testing.T) {
+ rsp, err := GetRedirectPage(t, httpListener, tt.host, tt.path)
+ require.NoError(t, err)
+ defer rsp.Body.Close()
+
+ require.Equal(t, tt.expectedLocation, rsp.Header.Get("Location"))
+ require.Equal(t, tt.expectedStatus, rsp.StatusCode)
+ })
+ }
+}