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-09-21 17:49:42 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2021-12-16 03:08:05 +0300
commitb4a8532a926d6f3b5cfdcc829276c7554d6c9a86 (patch)
treebd9c9853faeb030c9f22782d57667d6c6e4f5d92 /test
parent0b86a39d2c27bc548cc492bf6468cb80bde8f5ed (diff)
feat: implement ETag support for zip serving
Changelog: added
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/auth_test.go5
-rw-r--r--test/acceptance/testdata/api_responses.go5
-rw-r--r--test/acceptance/zip_test.go125
3 files changed, 120 insertions, 15 deletions
diff --git a/test/acceptance/auth_test.go b/test/acceptance/auth_test.go
index ad5c343a..d115dba5 100644
--- a/test/acceptance/auth_test.go
+++ b/test/acceptance/auth_test.go
@@ -539,7 +539,10 @@ func testAccessControl(t *testing.T, runPages runPagesFunc) {
defer rsp3.Body.Close()
require.Equal(t, tt.status, rsp3.StatusCode)
- require.Equal(t, "", rsp3.Header.Get("Cache-Control"))
+
+ // Make sure there are no cache headers
+ require.Empty(t, rsp3.Header.Values("Cache-Control"))
+ require.Empty(t, rsp3.Header.Values("Expires"))
if tt.redirectBack {
loc3, err := url.Parse(rsp3.Header.Get("Location"))
diff --git a/test/acceptance/testdata/api_responses.go b/test/acceptance/testdata/api_responses.go
index 5061dcaf..baa70f8f 100644
--- a/test/acceptance/testdata/api_responses.go
+++ b/test/acceptance/testdata/api_responses.go
@@ -2,6 +2,7 @@ package testdata
import (
"crypto/sha256"
+ "encoding/hex"
"fmt"
"os"
"path/filepath"
@@ -165,7 +166,7 @@ func generateVirtualDomainFromDir(dir, rootDomain string, perPrefixConfig map[st
sourcePath := fmt.Sprintf("file://%s", wd+"/"+dir+project)
sum := sha256.Sum256([]byte(sourcePath))
- sha := string(sum[:])
+ sha := hex.EncodeToString(sum[:])
lookupPath := api.LookupPath{
ProjectID: cfg.projectID,
@@ -204,7 +205,7 @@ func customDomain(config projectConfig) responseFn {
sourcePath := fmt.Sprintf("file://%s/%s/public.zip", wd, config.pathOnDisk)
sum := sha256.Sum256([]byte(sourcePath))
- sha := string(sum[:])
+ sha := hex.EncodeToString(sum[:])
return api.VirtualDomain{
Certificate: "",
diff --git a/test/acceptance/zip_test.go b/test/acceptance/zip_test.go
index fcaecf25..42734d14 100644
--- a/test/acceptance/zip_test.go
+++ b/test/acceptance/zip_test.go
@@ -1,6 +1,7 @@
package acceptance_test
import (
+ "fmt"
"io"
"net"
"net/http"
@@ -9,9 +10,14 @@ import (
"time"
"github.com/stretchr/testify/require"
+
+ "gitlab.com/gitlab-org/gitlab-pages/internal/feature"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
)
func TestZipServing(t *testing.T) {
+ testhelpers.StubFeatureFlagValue(t, feature.HandleCacheHeaders.EnvVariable, true)
+
runObjectStorage(t, "../../shared/pages/group/zip.gitlab.io/public.zip")
RunPagesProcess(t,
@@ -88,6 +94,11 @@ func TestZipServing(t *testing.T) {
require.Equal(t, tt.expectedStatusCode, response.StatusCode)
+ if tt.expectedStatusCode == http.StatusOK {
+ require.NotEmpty(t, response.Header.Get("ETag"))
+ require.NotEmpty(t, response.Header.Get("Last-Modified"))
+ }
+
body, err := io.ReadAll(response.Body)
require.NoError(t, err)
@@ -108,47 +119,132 @@ func TestZipServingCache(t *testing.T) {
urlSuffix string
expectedStatusCode int
expectedContent string
- extraHeaders http.Header
+ extraHeaders func(string) http.Header
}{
+ "base_domain_if_none_match": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusNotModified,
+ extraHeaders: func(etag string) http.Header {
+ return http.Header{
+ "If-None-Match": {etag},
+ }
+ },
+ },
+ "base_domain_if_none_match_fail": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusOK,
+ expectedContent: "zip.gitlab.io/project/index.html\n",
+ extraHeaders: func(etag string) http.Header {
+ return http.Header{
+ "If-None-Match": {fmt.Sprintf("%q", "badetag")},
+ }
+ },
+ },
+ "base_domain_if_match": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusOK,
+ expectedContent: "zip.gitlab.io/project/index.html\n",
+ extraHeaders: func(etag string) http.Header {
+ return http.Header{
+ "If-Match": {etag},
+ }
+ },
+ },
+ "base_domain_if_match_fail": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusPreconditionFailed,
+ extraHeaders: func(etag string) http.Header {
+ return http.Header{
+ "If-Match": {fmt.Sprintf("%q", "wrongetag")},
+ }
+ },
+ },
+ "base_domain_if_match_fail2": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusPreconditionFailed,
+ extraHeaders: func(etag string) http.Header {
+ return http.Header{
+ "If-Match": {","},
+ }
+ },
+ },
"base_domain_if_modified": {
host: "zip.gitlab.io",
urlSuffix: "/",
expectedStatusCode: http.StatusNotModified,
- extraHeaders: http.Header{
- "If-Modified-Since": {time.Now().Format(http.TimeFormat)},
+ extraHeaders: func(string) http.Header {
+ return http.Header{
+ "If-Modified-Since": {time.Now().Format(http.TimeFormat)},
+ }
+ },
+ },
+ "base_domain_if_modified_fails": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusOK,
+ expectedContent: "zip.gitlab.io/project/index.html\n",
+ extraHeaders: func(string) http.Header {
+ return http.Header{
+ "If-Modified-Since": {time.Now().AddDate(-10, 0, 0).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)},
+ extraHeaders: func(string) http.Header {
+ return http.Header{
+ "If-Unmodified-Since": {time.Now().AddDate(-10, 0, 0).Format(http.TimeFormat)},
+ }
+ },
+ },
+ "base_domain_if_unmodified_fails": {
+ host: "zip.gitlab.io",
+ urlSuffix: "/",
+ expectedStatusCode: http.StatusOK,
+ expectedContent: "zip.gitlab.io/project/index.html\n",
+ extraHeaders: func(string) http.Header {
+ return http.Header{
+ "If-Unmodified-Since": {time.Now().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)
+ // send a request to get the ETag
+ response, err := GetPageFromListener(t, httpListener, tt.host, tt.urlSuffix)
require.NoError(t, err)
defer response.Body.Close()
+ require.Equal(t, http.StatusOK, response.StatusCode)
- require.Equal(t, tt.expectedStatusCode, response.StatusCode)
+ etag := response.Header.Get("ETag")
+ require.NotEmpty(t, etag)
- if tt.expectedStatusCode == http.StatusOK {
- require.NotEmpty(t, response.Header.Get("Last-Modified"))
- }
+ // actual test
+ rsp, err := GetPageFromListenerWithHeaders(t, httpListener, tt.host, tt.urlSuffix, tt.extraHeaders(etag))
+ require.NoError(t, err)
+ require.Equal(t, tt.expectedStatusCode, rsp.StatusCode)
- body, err := io.ReadAll(response.Body)
+ body, err := io.ReadAll(rsp.Body)
require.NoError(t, err)
- require.Contains(t, string(body), tt.expectedContent, "content mismatch")
+ defer rsp.Body.Close()
+ require.Equal(t, tt.expectedContent, string(body), "content mismatch")
})
}
}
func TestZipServingFromDisk(t *testing.T) {
+ testhelpers.StubFeatureFlagValue(t, feature.HandleCacheHeaders.EnvVariable, true)
+
RunPagesProcess(t,
withListeners([]ListenSpec{httpListener}),
)
@@ -223,6 +319,11 @@ func TestZipServingFromDisk(t *testing.T) {
require.Equal(t, tt.expectedStatusCode, response.StatusCode)
+ if tt.expectedStatusCode == http.StatusOK {
+ require.NotEmpty(t, response.Header.Get("ETag"))
+ require.NotEmpty(t, response.Header.Get("Last-Modified"))
+ }
+
body, err := io.ReadAll(response.Body)
require.NoError(t, err)