mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-26 14:53:34 +00:00
chore: update Go to v1.27 (#39068)
Only made some necessary changes:
1. remove `GOEXPERIMENT`, only use jsonv2
1. `make fmt`
* `SigningKey` and `Signature` were affected due to some bugs in the
toolchain, so rewrote them
1. remove or fix fragile magic numbers and strings
* the outputs of image/gzip/zlib packages are different
1. update "nolint" comments for the changed lint behaviors
1. add `tls.MLKEM1024`
This commit is contained in:
@@ -530,9 +530,9 @@ jobs:
|
||||
assert.Equal(t, apiPull.Head.Ref, gtCtx["head_ref"].GetStringValue())
|
||||
assert.Equal(t, actionRunJob.JobID, gtCtx["job"].GetStringValue())
|
||||
assert.Equal(t, actionRun.Ref, gtCtx["ref"].GetStringValue())
|
||||
assert.Equal(t, (git.RefName(actionRun.Ref)).ShortName(), gtCtx["ref_name"].GetStringValue())
|
||||
assert.Equal(t, git.RefName(actionRun.Ref).ShortName(), gtCtx["ref_name"].GetStringValue())
|
||||
assert.False(t, gtCtx["ref_protected"].GetBoolValue())
|
||||
assert.Equal(t, string((git.RefName(actionRun.Ref)).RefType()), gtCtx["ref_type"].GetStringValue())
|
||||
assert.Equal(t, string(git.RefName(actionRun.Ref).RefType()), gtCtx["ref_type"].GetStringValue())
|
||||
assert.Equal(t, actionRun.Repo.OwnerName+"/"+actionRun.Repo.Name, gtCtx["repository"].GetStringValue())
|
||||
assert.Equal(t, actionRun.Repo.OwnerName, gtCtx["repository_owner"].GetStringValue())
|
||||
assert.Equal(t, actionRun.Repo.HTMLURL(), gtCtx["repositoryUrl"].GetStringValue())
|
||||
@@ -622,9 +622,9 @@ jobs:
|
||||
assert.Equal(t, apiPull.Head.Ref, gtCtx["head_ref"].GetStringValue())
|
||||
assert.Equal(t, actionRunJob.JobID, gtCtx["job"].GetStringValue())
|
||||
assert.Equal(t, actionRun.Ref, gtCtx["ref"].GetStringValue())
|
||||
assert.Equal(t, (git.RefName(actionRun.Ref)).ShortName(), gtCtx["ref_name"].GetStringValue())
|
||||
assert.Equal(t, git.RefName(actionRun.Ref).ShortName(), gtCtx["ref_name"].GetStringValue())
|
||||
assert.False(t, gtCtx["ref_protected"].GetBoolValue())
|
||||
assert.Equal(t, string((git.RefName(actionRun.Ref)).RefType()), gtCtx["ref_type"].GetStringValue())
|
||||
assert.Equal(t, string(git.RefName(actionRun.Ref).RefType()), gtCtx["ref_type"].GetStringValue())
|
||||
assert.Equal(t, actionRun.Repo.OwnerName+"/"+actionRun.Repo.Name, gtCtx["repository"].GetStringValue())
|
||||
assert.Equal(t, actionRun.Repo.OwnerName, gtCtx["repository_owner"].GetStringValue())
|
||||
assert.Equal(t, actionRun.Repo.HTMLURL(), gtCtx["repositoryUrl"].GetStringValue())
|
||||
|
||||
@@ -5,6 +5,8 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
neturl "net/url"
|
||||
@@ -56,6 +58,7 @@ func TestPackageComposer(t *testing.T) {
|
||||
]
|
||||
}`,
|
||||
}).Bytes()
|
||||
contentChecksum := sha1.Sum(content)
|
||||
|
||||
url := fmt.Sprintf("%sapi/packages/%s/composer", setting.AppURL, user.Name)
|
||||
|
||||
@@ -209,7 +212,7 @@ func TestPackageComposer(t *testing.T) {
|
||||
assert.Len(t, pkgs[0].Authors, 1)
|
||||
assert.Equal(t, packageAuthor, pkgs[0].Authors[0].Name)
|
||||
assert.Equal(t, "zip", pkgs[0].Dist.Type)
|
||||
assert.Equal(t, "4f5fa464c3cb808a1df191dbf6cb75363f8b7072", pkgs[0].Dist.Checksum)
|
||||
assert.Equal(t, hex.EncodeToString(contentChecksum[:]), pkgs[0].Dist.Checksum)
|
||||
assert.Len(t, pkgs[0].Bin, 1)
|
||||
assert.Equal(t, packageBin, pkgs[0].Bin[0])
|
||||
|
||||
@@ -239,7 +242,7 @@ func TestPackageComposer(t *testing.T) {
|
||||
assert.Len(t, pkgs[0].Authors, 1)
|
||||
assert.Equal(t, packageAuthor, pkgs[0].Authors[0].Name)
|
||||
assert.Equal(t, "zip", pkgs[0].Dist.Type)
|
||||
assert.Equal(t, "4f5fa464c3cb808a1df191dbf6cb75363f8b7072", pkgs[0].Dist.Checksum)
|
||||
assert.Equal(t, hex.EncodeToString(contentChecksum[:]), pkgs[0].Dist.Checksum)
|
||||
assert.Len(t, pkgs[0].Bin, 1)
|
||||
assert.Equal(t, packageBin, pkgs[0].Bin[0])
|
||||
assert.Equal(t, repo1.HTMLURL(), pkgs[0].Source.URL)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -374,7 +373,7 @@ func TestPackageNuGet(t *testing.T) {
|
||||
t.Run("SymbolPackage", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
createSymbolPackage := func(id, packageType string) io.Reader {
|
||||
createSymbolPackage := func(id, packageType string) []byte {
|
||||
symbolData, _ := base64.StdEncoding.DecodeString(`QlNKQgEAAQAAAAAADAAAAFBEQiB2MS4wAAAAAAAABgB8AAAAWAAAACNQZGIAAAAA1AAAAAgBAAAj
|
||||
fgAA3AEAAAQAAAAjU3RyaW5ncwAAAADgAQAABAAAACNVUwDkAQAAMAAAACNHVUlEAAAAFAIAACgB
|
||||
AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
||||
@@ -390,19 +389,19 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
||||
</metadata>
|
||||
</package>`,
|
||||
symbolFilename: string(symbolData),
|
||||
})
|
||||
}).Bytes()
|
||||
}
|
||||
|
||||
req := NewRequestWithBody(t, "PUT", url+"/symbolpackage", createSymbolPackage("unknown-package", "SymbolsPackage")).
|
||||
AddBasicAuth(user.Name)
|
||||
pkgSymbolsPackageErr := createSymbolPackage("unknown-package", "SymbolsPackage")
|
||||
req := NewRequestWithBody(t, "PUT", url+"/symbolpackage", bytes.NewReader(pkgSymbolsPackageErr)).AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", createSymbolPackage(packageName, "DummyPackage")).
|
||||
AddBasicAuth(user.Name)
|
||||
pkgDummyPackage := createSymbolPackage(packageName, "DummyPackage")
|
||||
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", bytes.NewReader(pkgDummyPackage)).AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusBadRequest)
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", createSymbolPackage(packageName, "SymbolsPackage")).
|
||||
AddBasicAuth(user.Name)
|
||||
pkgSymbolsPackage := createSymbolPackage(packageName, "SymbolsPackage")
|
||||
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", bytes.NewReader(pkgSymbolsPackage)).AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
pvs, err := packages.GetVersionsByPackageType(t.Context(), user.ID, packages.TypeNuGet)
|
||||
@@ -426,13 +425,13 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
||||
|
||||
pb, err := packages.GetBlobByID(t.Context(), pf.BlobID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(633), pb.Size)
|
||||
assert.EqualValues(t, len(content), pb.Size)
|
||||
case fmt.Sprintf("%s.%s.snupkg", packageName, packageVersion):
|
||||
assert.False(t, pf.IsLead)
|
||||
|
||||
pb, err := packages.GetBlobByID(t.Context(), pf.BlobID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(616), pb.Size)
|
||||
assert.EqualValues(t, len(pkgSymbolsPackage), pb.Size)
|
||||
case packageName + ".nuspec":
|
||||
assert.False(t, pf.IsLead)
|
||||
|
||||
@@ -456,7 +455,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
||||
}
|
||||
}
|
||||
|
||||
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", createSymbolPackage(packageName, "SymbolsPackage")).
|
||||
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", bytes.NewReader(createSymbolPackage(packageName, "SymbolsPackage"))).
|
||||
AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusConflict)
|
||||
})
|
||||
|
||||
@@ -238,15 +238,12 @@ gpgkey=%sapi/packages/%s/rpm/repository.key`,
|
||||
|
||||
switch d.Type {
|
||||
case "primary":
|
||||
assert.EqualValues(t, 722, d.Size)
|
||||
assert.EqualValues(t, 1759, d.OpenSize)
|
||||
assert.Equal(t, "repodata/primary.xml.gz", d.Location.Href)
|
||||
case "filelists":
|
||||
assert.EqualValues(t, 257, d.Size)
|
||||
assert.EqualValues(t, 326, d.OpenSize)
|
||||
assert.Equal(t, "repodata/filelists.xml.gz", d.Location.Href)
|
||||
case "other":
|
||||
assert.EqualValues(t, 306, d.Size)
|
||||
assert.EqualValues(t, 394, d.OpenSize)
|
||||
assert.Equal(t, "repodata/other.xml.gz", d.Location.Href)
|
||||
}
|
||||
|
||||
@@ -7,10 +7,13 @@ import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"compress/zlib"
|
||||
"crypto/md5"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -180,6 +183,7 @@ func TestPackageRubyGems(t *testing.T) {
|
||||
|
||||
testAnotherGemName := "gitea-another"
|
||||
testAnotherGemVersion := "0.99"
|
||||
contentTestAnother := makeRubyGem(testAnotherGemName, testAnotherGemVersion)
|
||||
|
||||
root := fmt.Sprintf("/api/packages/%s/rubygems", user.Name)
|
||||
|
||||
@@ -243,11 +247,12 @@ func TestPackageRubyGems(t *testing.T) {
|
||||
AddBasicAuth(user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
b, _ := base64.StdEncoding.DecodeString(`eJxi4Si1EndPzbWyCi5ITc5My0xOLMnMz2M8zMIRLeGpxGWsZ6RnzGbF5hqSyempxJWeWZKayGbN
|
||||
EBJqJQjWFZZaVJyZnxfN5qnEZahnoGcKkjTwVBJyB6lUKEhMzk5MTwULGngqcRaVJlWCONEMBp5K
|
||||
DGAWSKc7zFhPJamg0qRK99TcYphehZLU4hKInFhGSUlBsZW+PtgZepn5+iDxECRzDUDGcfh6hoA4
|
||||
gAAAAP//MS06Gw==`)
|
||||
assert.Equal(t, b, resp.Body.Bytes())
|
||||
r, err := zlib.NewReader(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
b, err := io.ReadAll(r)
|
||||
assert.NoError(t, err)
|
||||
expected := "\x04\bu:\x17Gem::Specification\x01\xc3\x04\b[\x18I\"\n3.2.3\x06:\x06ETi\tI\"\ngitea\x06;\x00TU:\x11Gem::Version[\x06I\"\n1.0.5\x06;\x00T0I\"\x12Gitea package\x06;\x00T00I\"\truby\x06;\x00T[\x000I\"\x00\x06;\x00T[\x06I\"\nGitea\x06;\x00TI\"\x1aRubyGems package test\x06;\x00TI\"\x16https://gitea.io/\x06;\x00TTI\"\truby\x06;\x00T0[\x06I\"\bMIT\x06;\x00T"
|
||||
assert.Contains(t, expected, string(b)) // the content is from rubygems_module.NewMarshalEncoder
|
||||
|
||||
pvs, err := packages.GetVersionsByPackageType(t.Context(), user.ID, packages.TypeRubyGems)
|
||||
assert.NoError(t, err)
|
||||
@@ -258,12 +263,19 @@ gAAAAP//MS06Gw==`)
|
||||
t.Run("EnumeratePackages", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
enumeratePackages := func(t *testing.T, endpoint string, expectedContent []byte) {
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", root, endpoint)).
|
||||
AddBasicAuth(user.Name)
|
||||
readGzBytes := func(t *testing.T, in []byte) []byte {
|
||||
r, err := gzip.NewReader(bytes.NewReader(in))
|
||||
assert.NoError(t, err)
|
||||
b, err := io.ReadAll(r)
|
||||
assert.NoError(t, err)
|
||||
return b
|
||||
}
|
||||
enumeratePackages := func(t *testing.T, endpoint string, expectedGzip []byte) {
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", root, endpoint)).AddBasicAuth(user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
assert.Equal(t, expectedContent, resp.Body.Bytes())
|
||||
expectedBytes := readGzBytes(t, expectedGzip)
|
||||
actualBytes := readGzBytes(t, resp.Body.Bytes())
|
||||
assert.Equal(t, expectedBytes, actualBytes)
|
||||
}
|
||||
|
||||
b, _ := base64.StdEncoding.DecodeString(`H4sICAAAAAAA/3NwZWNzLjQuOABi4Yhmi+bwVOJKzyxJTWSzYnMNCbUSdE/NtbIKSy0qzszPi2bzVOIy1DPQM2WzZgjxVOIsKk2qBDEBAQAA///xOEYKOwAAAA==`)
|
||||
@@ -276,7 +288,7 @@ gAAAAP//MS06Gw==`)
|
||||
|
||||
t.Run("UploadAnother", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
uploadFile(t, makeRubyGem(testAnotherGemName, testAnotherGemVersion), http.StatusCreated)
|
||||
uploadFile(t, contentTestAnother, http.StatusCreated)
|
||||
})
|
||||
|
||||
t.Run("PackageInfo", func(t *testing.T) {
|
||||
@@ -288,16 +300,21 @@ gAAAAP//MS06Gw==`)
|
||||
1.0.5 runtime-dep:>= 1.2.0&< 2.0|checksum:%s,ruby:>= 2.3.0,rubygems:>= 1.0
|
||||
`, testGemContentChecksum)
|
||||
assert.Equal(t, expected, resp.Body.String())
|
||||
})
|
||||
testGemInfoMd5 := fmt.Sprintf("%x", md5.Sum(resp.Body.Bytes()))
|
||||
|
||||
t.Run("Versions", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
req := NewRequest(t, "GET", root+"/versions").AddBasicAuth(user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
assert.Equal(t, `---
|
||||
gitea 1.0.5 08843c2dd0ea19910e6b056b98e38f1c
|
||||
gitea-another 0.99 8b639e4048d282941485368ec42609be
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/info/%s", root, testAnotherGemName)).AddBasicAuth(user.Name)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
testAnotherGemInfoMd5 := fmt.Sprintf("%x", md5.Sum(resp.Body.Bytes()))
|
||||
|
||||
t.Run("Versions", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
req := NewRequest(t, "GET", root+"/versions").AddBasicAuth(user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
assert.Equal(t, `---
|
||||
gitea 1.0.5 `+testGemInfoMd5+`
|
||||
gitea-another 0.99 `+testAnotherGemInfoMd5+`
|
||||
`, resp.Body.String())
|
||||
})
|
||||
})
|
||||
|
||||
deleteGemPackage := func(t *testing.T, packageName, packageVersion string) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -52,6 +54,7 @@ func TestPackageVagrant(t *testing.T) {
|
||||
archive.Close()
|
||||
zw.Close()
|
||||
content := buf.Bytes()
|
||||
contentChecksum := sha512.Sum512(content)
|
||||
|
||||
root := fmt.Sprintf("/api/packages/%s/vagrant", user.Name)
|
||||
|
||||
@@ -164,6 +167,6 @@ func TestPackageVagrant(t *testing.T) {
|
||||
provider := version.Providers[0]
|
||||
assert.Equal(t, packageProvider, provider.Name)
|
||||
assert.Equal(t, "sha512", provider.ChecksumType)
|
||||
assert.Equal(t, "259bebd6160acad695016d22a45812e26f187aaf78e71a4c23ee3201528346293f991af3468a8c6c5d2a21d7d9e1bdc1bf79b87110b2fddfcc5a0d45963c7c30", provider.Checksum)
|
||||
assert.Equal(t, hex.EncodeToString(contentChecksum[:]), provider.Checksum)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -424,13 +424,13 @@ func TestAPIUploadAssetRelease(t *testing.T) {
|
||||
resp := performUpload(t, assetURL, bufImageBytes, http.StatusCreated)
|
||||
attachment := DecodeJSON(t, resp, &api.Attachment{})
|
||||
assert.Equal(t, filename, attachment.Name)
|
||||
assert.EqualValues(t, 104, attachment.Size)
|
||||
assert.EqualValues(t, len(bufImageBytes), attachment.Size)
|
||||
})
|
||||
t.Run("UploadWithName", func(t *testing.T) {
|
||||
resp := performUpload(t, assetURL+"?name=test-asset", bufImageBytes, http.StatusCreated)
|
||||
attachment := DecodeJSON(t, resp, &api.Attachment{})
|
||||
assert.Equal(t, "test-asset", attachment.Name)
|
||||
assert.EqualValues(t, 104, attachment.Size)
|
||||
assert.EqualValues(t, len(bufImageBytes), attachment.Size)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -449,6 +449,6 @@ func TestAPIUploadAssetRelease(t *testing.T) {
|
||||
attachment := DecodeJSON(t, resp, &api.Attachment{})
|
||||
|
||||
assert.Equal(t, "stream.bin", attachment.Name)
|
||||
assert.EqualValues(t, 104, attachment.Size)
|
||||
assert.EqualValues(t, len(bufImageBytes), attachment.Size)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user