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:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-11-16 04:16:51 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-11-16 04:16:51 +0300
commit85621f69f855e43afe983e2ca107e921aa14c8c8 (patch)
tree670f67b327fb18afd399ed9f1231fdf6bc1f114b /test
parentd7562ebf963c4c5f2069899776231ed882e5ed75 (diff)
feat: handle extra headers when serving from compressed zip archive
Related to https://gitlab.com/gitlab-org/gitlab-pages/-/issues/466 Changelog: added
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/zip_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/acceptance/zip_test.go b/test/acceptance/zip_test.go
index 97a35e2b..f7623340 100644
--- a/test/acceptance/zip_test.go
+++ b/test/acceptance/zip_test.go
@@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"testing"
+ "time"
"github.com/stretchr/testify/require"
)
@@ -96,6 +97,59 @@ func TestZipServing(t *testing.T) {
}
}
+func TestZipServingCache(t *testing.T) {
+ _, cleanup := newZipFileServerURL(t, "../../shared/pages/group/zip.gitlab.io/public.zip")
+ t.Cleanup(cleanup)
+
+ RunPagesProcess(t,
+ withListeners([]ListenSpec{httpListener}),
+ )
+
+ tests := map[string]struct {
+ host string
+ urlSuffix string
+ expectedStatusCode int
+ expectedContent string
+ extraHeaders http.Header
+ }{
+ "base_domain_if_modified": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusNotModified,
+ extraHeaders: http.Header{
+ "If-Modified-Since": {time.Now().Format(http.TimeFormat)},
+ },
+ },
+ "base_domain_if_unmodified": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusPreconditionFailed,
+ extraHeaders: http.Header{
+ "If-Unmodified-Since": {time.Now().AddDate(-10, 0, 0).Format(http.TimeFormat)},
+ },
+ },
+ }
+
+ for name, tt := range tests {
+ t.Run(name, func(t *testing.T) {
+ response, err := GetPageFromListenerWithHeaders(t, httpListener, tt.host, tt.urlSuffix, tt.extraHeaders)
+ require.NoError(t, err)
+ defer response.Body.Close()
+
+ require.Equal(t, tt.expectedStatusCode, response.StatusCode)
+
+ if tt.expectedStatusCode == http.StatusOK {
+ require.NotEmpty(t, response.Header.Get("Last-Modified"))
+ }
+
+ body, err := io.ReadAll(response.Body)
+ require.NoError(t, err)
+
+ require.Contains(t, string(body), tt.expectedContent, "content mismatch")
+ })
+ }
+}
+
func TestZipServingFromDisk(t *testing.T) {
RunPagesProcess(t,
withListeners([]ListenSpec{httpListener}),