Add support for HEAD requests in Maven registry (#21834)
Related #18543 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
26f941fbda
commit
fc7a2d5a95
19 changed files with 162 additions and 40 deletions
|
@ -7,6 +7,7 @@ package integration
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -39,6 +40,12 @@ func TestPackageMaven(t *testing.T) {
|
|||
MakeRequest(t, req, expectedStatus)
|
||||
}
|
||||
|
||||
checkHeaders := func(t *testing.T, h http.Header, contentType string, contentLength int64) {
|
||||
assert.Equal(t, contentType, h.Get("Content-Type"))
|
||||
assert.Equal(t, strconv.FormatInt(contentLength, 10), h.Get("Content-Length"))
|
||||
assert.NotEmpty(t, h.Get("Last-Modified"))
|
||||
}
|
||||
|
||||
t.Run("Upload", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
|
@ -77,10 +84,18 @@ func TestPackageMaven(t *testing.T) {
|
|||
t.Run("Download", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s", root, packageVersion, filename))
|
||||
req := NewRequest(t, "HEAD", fmt.Sprintf("%s/%s/%s", root, packageVersion, filename))
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
checkHeaders(t, resp.Header(), "application/java-archive", 4)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s", root, packageVersion, filename))
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
checkHeaders(t, resp.Header(), "application/java-archive", 4)
|
||||
|
||||
assert.Equal(t, []byte("test"), resp.Body.Bytes())
|
||||
|
||||
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
|
||||
|
@ -150,10 +165,18 @@ func TestPackageMaven(t *testing.T) {
|
|||
t.Run("DownloadPOM", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s.pom", root, packageVersion, filename))
|
||||
req := NewRequest(t, "HEAD", fmt.Sprintf("%s/%s/%s.pom", root, packageVersion, filename))
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
checkHeaders(t, resp.Header(), "text/xml", int64(len(pomContent)))
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/%s/%s.pom", root, packageVersion, filename))
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
checkHeaders(t, resp.Header(), "text/xml", int64(len(pomContent)))
|
||||
|
||||
assert.Equal(t, []byte(pomContent), resp.Body.Bytes())
|
||||
|
||||
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
|
||||
|
@ -191,6 +214,9 @@ func TestPackageMaven(t *testing.T) {
|
|||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
expectedMetadata := `<?xml version="1.0" encoding="UTF-8"?>` + "\n<metadata><groupId>com.gitea</groupId><artifactId>test-project</artifactId><versioning><release>1.0.1</release><latest>1.0.1</latest><versions><version>1.0.1</version></versions></versioning></metadata>"
|
||||
|
||||
checkHeaders(t, resp.Header(), "text/xml", int64(len(expectedMetadata)))
|
||||
|
||||
assert.Equal(t, expectedMetadata, resp.Body.String())
|
||||
|
||||
for key, checksum := range map[string]string{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue