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:
authorJaime Martinez <jmartinez@gitlab.com>2021-02-03 09:06:02 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-02-15 02:17:24 +0300
commit586317c827f5878444bcc86bf953b21e7e31ee10 (patch)
treeb24d2dbd5ccb4c72acb670f5464ec190c83c12c1 /test/acceptance/zip_test.go
parent24cc61d186feaefec3cc08225c58b07d3767dbbb (diff)
Add extra tests for serving zip archives from disk
Diffstat (limited to 'test/acceptance/zip_test.go')
-rw-r--r--test/acceptance/zip_test.go105
1 files changed, 102 insertions, 3 deletions
diff --git a/test/acceptance/zip_test.go b/test/acceptance/zip_test.go
index 6257458e..0f55e891 100644
--- a/test/acceptance/zip_test.go
+++ b/test/acceptance/zip_test.go
@@ -5,14 +5,20 @@ import (
"net"
"net/http"
"net/http/httptest"
+ "os"
"testing"
"github.com/stretchr/testify/require"
+
+ "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
)
func TestZipServing(t *testing.T) {
skipUnlessEnabled(t)
+ _, cleanup := newZipFileServerURL(t, "../../shared/pages/group/zip.gitlab.io/public.zip")
+ defer cleanup()
+
source := NewGitlabDomainsSourceStub(t, &stubOpts{})
defer source.Close()
@@ -22,9 +28,6 @@ func TestZipServing(t *testing.T) {
teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{}, pagesArgs...)
defer teardown()
- _, cleanup := newZipFileServerURL(t, "../../shared/pages/group/zip.gitlab.io/public.zip")
- defer cleanup()
-
tests := map[string]struct {
host string
urlSuffix string
@@ -103,6 +106,102 @@ func TestZipServing(t *testing.T) {
}
}
+func TestZipServingFromDisk(t *testing.T) {
+ skipUnlessEnabled(t, "not-inplace-chroot")
+
+ chdir := false
+ defer testhelpers.ChdirInPath(t, "../../shared/pages", &chdir)()
+
+ _, cleanup := newZipFileServerURL(t, "shared/pages/group/zip.gitlab.io/public.zip")
+ defer cleanup()
+
+ wd, err := os.Getwd()
+ require.NoError(t, err)
+
+ source := NewGitlabDomainsSourceStub(t, &stubOpts{
+ pagesRoot: wd,
+ })
+
+ defer source.Close()
+
+ gitLabAPISecretKey := CreateGitLabAPISecretKeyFixtureFile(t)
+
+ pagesArgs := []string{"-gitlab-server", source.URL, "-api-secret-key", gitLabAPISecretKey, "-domain-config-source", "gitlab", "-pages-root", wd}
+ teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{}, pagesArgs...)
+ defer teardown()
+
+ tests := map[string]struct {
+ host string
+ urlSuffix string
+ expectedStatusCode int
+ expectedContent string
+ }{
+ "base_domain_no_suffix": {
+ host: "zip-from-disk.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusOK,
+ expectedContent: "zip.gitlab.io/project/index.html\n",
+ },
+ "file_exists": {
+ host: "zip-from-disk.gitlab.io",
+ urlSuffix: "/index.html",
+ expectedStatusCode: http.StatusOK,
+ expectedContent: "zip.gitlab.io/project/index.html\n",
+ },
+ "file_exists_in_subdir": {
+ host: "zip-from-disk.gitlab.io",
+ urlSuffix: "/subdir/hello.html",
+ expectedStatusCode: http.StatusOK,
+ expectedContent: "zip.gitlab.io/project/subdir/hello.html\n",
+ },
+ "file_exists_symlink": {
+ host: "zip-from-disk.gitlab.io",
+ urlSuffix: "/symlink.html",
+ expectedStatusCode: http.StatusOK,
+ expectedContent: "symlink.html->subdir/linked.html\n",
+ },
+ "dir": {
+ host: "zip-from-disk.gitlab.io",
+ urlSuffix: "/subdir/",
+ expectedStatusCode: http.StatusNotFound,
+ expectedContent: "zip.gitlab.io/project/404.html\n",
+ },
+ "file_does_not_exist": {
+ host: "zip-from-disk.gitlab.io",
+ urlSuffix: "/unknown.html",
+ expectedStatusCode: http.StatusNotFound,
+ expectedContent: "zip.gitlab.io/project/404.html\n",
+ },
+ "bad_symlink": {
+ host: "zip-from-disk.gitlab.io",
+ urlSuffix: "/bad-symlink.html",
+ expectedStatusCode: http.StatusNotFound,
+ expectedContent: "zip.gitlab.io/project/404.html\n",
+ },
+ "with_not_found_zip": {
+ host: "zip-from-disk-not-found.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusNotFound,
+ expectedContent: "The page you're looking for could not be found",
+ },
+ }
+
+ for name, tt := range tests {
+ t.Run(name, func(t *testing.T) {
+ response, err := GetPageFromListener(t, httpListener, tt.host, tt.urlSuffix)
+ require.NoError(t, err)
+ defer response.Body.Close()
+
+ require.Equal(t, tt.expectedStatusCode, response.StatusCode)
+
+ body, err := ioutil.ReadAll(response.Body)
+ require.NoError(t, err)
+
+ require.Contains(t, string(body), tt.expectedContent, "content mismatch")
+ })
+ }
+}
+
func TestZipServingConfigShortTimeout(t *testing.T) {
skipUnlessEnabled(t)