aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-07-03 15:33:28 +0200
committerGitHub <noreply@github.com>2023-07-03 15:33:28 +0200
commitc890454769562e0ec2978e123aaf3d9a43e5ef4f (patch)
treea152b5a0356a3da4f83083c5e7fc87214f8bd251 /tests
parentf1cb461c1fb23b68ae34ada2de6bad3bfa6ceeca (diff)
downloadgitea-c890454769562e0ec2978e123aaf3d9a43e5ef4f.tar.gz
gitea-c890454769562e0ec2978e123aaf3d9a43e5ef4f.zip
Add direct serving of package content (#25543)
Fixes #24723 Direct serving of content aka HTTP redirect is not mentioned in any of the package registry specs but lots of official registries do that so it should be supported by the usual clients.
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_packages_generic_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/integration/api_packages_generic_test.go b/tests/integration/api_packages_generic_test.go
index 765d11fd83..f5d8def0f3 100644
--- a/tests/integration/api_packages_generic_test.go
+++ b/tests/integration/api_packages_generic_test.go
@@ -6,6 +6,7 @@ package integration
import (
"bytes"
"fmt"
+ "io"
"net/http"
"testing"
@@ -139,6 +140,42 @@ func TestPackageGeneric(t *testing.T) {
req = NewRequest(t, "GET", url+"/dummy.bin")
MakeRequest(t, req, http.StatusUnauthorized)
})
+
+ t.Run("ServeDirect", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ if setting.Packages.Storage.Type != setting.MinioStorageType {
+ t.Skip("Test skipped for non-Minio-storage.")
+ return
+ }
+
+ if !setting.Packages.Storage.MinioConfig.ServeDirect {
+ old := setting.Packages.Storage.MinioConfig.ServeDirect
+ defer func() {
+ setting.Packages.Storage.MinioConfig.ServeDirect = old
+ }()
+
+ setting.Packages.Storage.MinioConfig.ServeDirect = true
+ }
+
+ req := NewRequest(t, "GET", url+"/"+filename)
+ resp := MakeRequest(t, req, http.StatusSeeOther)
+
+ checkDownloadCount(3)
+
+ location := resp.Header().Get("Location")
+ assert.NotEmpty(t, location)
+
+ resp2, err := (&http.Client{}).Get(location)
+ assert.NoError(t, err)
+ assert.Equal(t, http.StatusOK, resp2.StatusCode)
+
+ body, err := io.ReadAll(resp2.Body)
+ assert.NoError(t, err)
+ assert.Equal(t, content, body)
+
+ checkDownloadCount(3)
+ })
})
t.Run("Delete", func(t *testing.T) {