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
path: root/test
diff options
context:
space:
mode:
authorNathan Friend <nathan@gitlab.com>2021-08-20 13:52:09 +0300
committerNathan Friend <nathan@gitlab.com>2021-08-20 13:52:09 +0300
commit5fff32dd852a27151a08dea0cb2a8fd2983d7f65 (patch)
tree0e5c56af88f83f1550bbaf90f433eda4da7cfd5d /test
parentca330e78ad92ea79939a5df9b70f3c627a62eecf (diff)
Splat and placeholder support in _redirects
This commit adds support for Netlify-style splats (*) and :placeholders in the _redirects file. Changelog: added
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/redirects_test.go15
-rw-r--r--test/acceptance/rewrites_test.go59
2 files changed, 72 insertions, 2 deletions
diff --git a/test/acceptance/redirects_test.go b/test/acceptance/redirects_test.go
index f2748789..dd1b6891 100644
--- a/test/acceptance/redirects_test.go
+++ b/test/acceptance/redirects_test.go
@@ -7,12 +7,14 @@ import (
"testing"
"github.com/stretchr/testify/require"
+
+ redirects "gitlab.com/gitlab-org/gitlab-pages/internal/redirects"
)
func TestDisabledRedirects(t *testing.T) {
RunPagesProcess(t,
withListeners([]ListenSpec{httpListener}),
- withEnv([]string{"FF_ENABLE_REDIRECTS=false"}),
+ withEnv([]string{"FF_ENABLE_REDIRECTS=false", redirects.FFEnablePlaceholders + "=true"}),
)
// Test that redirects status page is forbidden
@@ -33,6 +35,7 @@ func TestDisabledRedirects(t *testing.T) {
func TestRedirectStatusPage(t *testing.T) {
RunPagesProcess(t,
withListeners([]ListenSpec{httpListener}),
+ withEnv([]string{redirects.FFEnablePlaceholders + "=true"}),
)
rsp, err := GetPageFromListener(t, httpListener, "group.redirects.gitlab-example.com", "/project-redirects/_redirects")
@@ -42,13 +45,14 @@ func TestRedirectStatusPage(t *testing.T) {
require.NoError(t, err)
defer rsp.Body.Close()
- require.Contains(t, string(body), "11 rules")
+ require.Contains(t, string(body), "14 rules")
require.Equal(t, http.StatusOK, rsp.StatusCode)
}
func TestRedirect(t *testing.T) {
RunPagesProcess(t,
withListeners([]ListenSpec{httpListener}),
+ withEnv([]string{redirects.FFEnablePlaceholders + "=true"}),
)
// Test that serving a file still works with redirects enabled
@@ -99,6 +103,13 @@ func TestRedirect(t *testing.T) {
expectedStatus: http.StatusFound,
expectedLocation: "/magic-land.html",
},
+ // Permanent redirect for splat (*) with replacement (:splat)
+ {
+ host: "group.redirects.gitlab-example.com",
+ path: "/project-redirects/jobs/assistant-to-the-regional-manager.html",
+ expectedStatus: http.StatusMovedPermanently,
+ expectedLocation: "/project-redirects/careers/assistant-to-the-regional-manager.html",
+ },
}
for _, tt := range tests {
diff --git a/test/acceptance/rewrites_test.go b/test/acceptance/rewrites_test.go
new file mode 100644
index 00000000..a446a8cd
--- /dev/null
+++ b/test/acceptance/rewrites_test.go
@@ -0,0 +1,59 @@
+package acceptance_test
+
+import (
+ "io/ioutil"
+ "net/http"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ redirects "gitlab.com/gitlab-org/gitlab-pages/internal/redirects"
+)
+
+func TestRewrites(t *testing.T) {
+ RunPagesProcess(t,
+ withListeners([]ListenSpec{httpListener}),
+ withEnv([]string{redirects.FFEnablePlaceholders + "=true"}),
+ )
+
+ tests := map[string]struct {
+ host string
+ path string
+ expectedBody string
+ }{
+ "rewrite_for_splat_with_replacement": {
+ host: "group.redirects.gitlab-example.com",
+ path: "/project-redirects/arrakis/visitors-guide.html",
+ expectedBody: "Welcome to Dune!",
+ },
+ "splat_with_no_replacement": {
+ host: "group.redirects.gitlab-example.com",
+ path: "/project-redirects/spa/client/side/route",
+ expectedBody: "This is an SPA",
+ },
+ "existing_content_takes_precedence_over_rewrite_rules": {
+ host: "group.redirects.gitlab-example.com",
+ path: "/project-redirects/spa/existing-file.html",
+ expectedBody: "This is an existing file",
+ },
+ "rewrite_using_placeholders": {
+ host: "group.redirects.gitlab-example.com",
+ path: "/project-redirects/blog/2021/08/12",
+ expectedBody: "Rewrites are pretty neat!",
+ },
+ }
+
+ for name, tt := range tests {
+ t.Run(name, func(t *testing.T) {
+ rsp, err := GetPageFromListener(t, httpListener, tt.host, tt.path)
+ require.NoError(t, err)
+ defer rsp.Body.Close()
+
+ body, err := ioutil.ReadAll(rsp.Body)
+ require.NoError(t, err)
+
+ require.Contains(t, string(body), tt.expectedBody)
+ require.Equal(t, http.StatusOK, rsp.StatusCode)
+ })
+ }
+}