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:
wxiaoguang
2026-08-24 15:28:17 +08:00
committed by GitHub
parent e50e4ed869
commit 51b8da8b01
35 changed files with 106 additions and 182 deletions

View File

@@ -37,7 +37,7 @@ jobs:
- uses: ./.github/actions/go-setup
- run: make deps-backend deps-tools
- run: TAGS="bindata" make backend
- run: TAGS="bindata gogit" GOEXPERIMENT="" make backend
- run: TAGS="bindata gogit" make backend
- name: warm test compile cache (bindata)
env:
TAGS: bindata
@@ -46,13 +46,12 @@ jobs:
- name: warm test compile cache (bindata gogit)
env:
TAGS: bindata gogit
GOEXPERIMENT:
GOTEST_FLAGS: -race -list=^$$ -count=1
run: make test-backend
- name: warm integration compile cache
run: |
TAGS="bindata" make test-integration-compile
TAGS="bindata gogit" GOEXPERIMENT="" make test-integration-compile
TAGS="bindata gogit" make test-integration-compile
TAGS="bindata gogit" GOTEST_FLAGS="-race" make test-integration-compile
lint:

View File

@@ -96,7 +96,6 @@ jobs:
- run: make backend
env:
TAGS: bindata gogit
GOEXPERIMENT:
- run: GITEA_TEST_DATABASE=sqlite make test-migration
env:
TAGS: bindata gogit
@@ -107,7 +106,6 @@ jobs:
# sqlite driver can contain large amount of Golang code, so don't use race detector for it, otherwise, extremely slow
GOTEST_FLAGS: -timeout=40m
TAGS: bindata gogit
GOEXPERIMENT:
test-unit:
if: needs.files-changed.outputs.backend == 'true'
@@ -170,7 +168,6 @@ jobs:
env:
GOTEST_FLAGS: -race -timeout=20m
TAGS: bindata gogit
GOEXPERIMENT:
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}
GITEA_TEST_CI_SKIP_EXTERNAL: true
- run: make test-check

View File

@@ -17,7 +17,7 @@ linters:
- govet
- ineffassign
- mirror
- modernize
# - modernize # re-enable it in a future PR, after clearly fixing all the issues it reports
- nakedret
- nilnil
- nolintlint
@@ -182,7 +182,8 @@ formatters:
- blank
- default
gofumpt:
extra-rules: true
extra:
group-params: true
exclusions:
generated: lax
paths:

View File

@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1
# Build frontend on the native platform to avoid QEMU-related issues with nodejs ecosystem
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.24 AS frontend-build
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.27-alpine3.24 AS frontend-build
RUN apk --no-cache add build-base git nodejs pnpm
WORKDIR /src
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
@@ -9,7 +9,7 @@ COPY --exclude=.git/ . .
RUN make frontend
# Build backend for each target platform
FROM docker.io/library/golang:1.26-alpine3.24 AS build-env
FROM docker.io/library/golang:1.27-alpine3.24 AS build-env
ARG GITEA_VERSION
ARG TAGS=""

View File

@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1
# Build frontend on the native platform to avoid QEMU-related issues with nodejs ecosystem
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.26-alpine3.24 AS frontend-build
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.27-alpine3.24 AS frontend-build
RUN apk --no-cache add build-base git nodejs pnpm
WORKDIR /src
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
@@ -9,7 +9,7 @@ COPY --exclude=.git/ . .
RUN make frontend
# Build backend for each target platform
FROM docker.io/library/golang:1.26-alpine3.24 AS build-env
FROM docker.io/library/golang:1.27-alpine3.24 AS build-env
ARG GITEA_VERSION
ARG TAGS=""

View File

@@ -1,16 +1,12 @@
DIST := dist
DIST_DIRS := $(DIST)/binaries $(DIST)/release
# By default use go's 1.25 experimental json v2 library when building
# TODO: remove when no longer experimental
export GOEXPERIMENT ?= jsonv2
GO ?= go
SHASUM ?= shasum -a 256
AIR_PACKAGE ?= github.com/air-verse/air@v1.67.4 # renovate: datasource=go
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.11.1 # renovate: datasource=go
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 # renovate: datasource=go
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.1 # renovate: datasource=go
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.16 # renovate: datasource=go
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.8.0 # renovate: datasource=go
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.36.2 # renovate: datasource=go
@@ -513,7 +509,7 @@ generate-go: $(TAGS_PREREQ)
.PHONY: security-check
security-check:
GOEXPERIMENT= go run $(GOVULNCHECK_PACKAGE) -show color ./... || true
go run $(GOVULNCHECK_PACKAGE) -show color ./... || true
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
CGO_ENABLED="$(CGO_ENABLED)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -v $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@

View File

@@ -752,7 +752,7 @@ func writeFlushPktLine(ctx context.Context, out io.Writer) error {
func writeDataPktLine(ctx context.Context, out io.Writer, data []byte) error {
hexchar := []byte("0123456789abcdef")
hex := func(n uint64) byte {
return hexchar[(n)&15]
return hexchar[n&15]
}
length := uint64(len(data) + 4)

View File

@@ -36,6 +36,7 @@ var curveStringMap = map[string]tls.CurveID{
"p256": tls.CurveP256,
"p384": tls.CurveP384,
"p521": tls.CurveP521,
"mlkem1024": tls.MLKEM1024,
"x25519mlkem768": tls.X25519MLKEM768,
"secp256r1mlkem768": tls.SecP256r1MLKEM768,
"secp384r1mlkem1024": tls.SecP384r1MLKEM1024,

4
go.mod
View File

@@ -1,8 +1,8 @@
module gitea.dev
go 1.26.0
go 1.27
toolchain go1.26.7
toolchain go1.27.0
require (
connectrpc.com/connect v1.20.0

View File

@@ -9,20 +9,12 @@ import (
"strconv"
)
// HashAvatar will generate a unique string, which ensures that when there's a
// different unique ID while the data is the same, it will generate a different
// output. It will generate the output according to:
// HEX(HASH(uniqueID || - || data))
// The hash being used is SHA256.
// The sole purpose of the unique ID is to generate a distinct hash Such that
// two unique IDs with the same data will have a different hash output.
// The "-" byte is important to ensure that data cannot be modified such that
// the first byte is a number, which could lead to a "collision" with the hash
// of another unique ID.
// HashAvatar generates a unique string for input ID and data.
// Because avatar is per-user, one user deletes their avatar should not affect another user who uses the same avatar.
func HashAvatar(uniqueID int64, data []byte) string {
h := sha256.New()
h.Write([]byte(strconv.FormatInt(uniqueID, 10)))
h.Write([]byte{'-'})
h.Write([]byte{'-'}) // make sure the bytes in data won't conflict with ID
h.Write(data)
return hex.EncodeToString(h.Sum(nil))
}

View File

@@ -4,9 +4,6 @@
package avatar_test
import (
"bytes"
"image"
"image/png"
"testing"
"gitea.dev/modules/avatar"
@@ -15,12 +12,9 @@ import (
)
func Test_HashAvatar(t *testing.T) {
myImage := image.NewRGBA(image.Rect(0, 0, 32, 32))
var buff bytes.Buffer
png.Encode(&buff, myImage)
assert.Equal(t, "9ddb5bac41d57e72aa876321d0c09d71090c05f94bc625303801be2f3240d2cb", avatar.HashAvatar(1, buff.Bytes()))
assert.Equal(t, "9a5d44e5d637b9582a976676e8f3de1dccd877c2fe3e66ca3fab1629f2f47609", avatar.HashAvatar(8, buff.Bytes()))
assert.Equal(t, "ed7399158672088770de6f5211ce15528ebd675e92fc4fc060c025f4b2794ccb", avatar.HashAvatar(1024, buff.Bytes()))
buf := []byte{1, 2}
assert.Equal(t, "057b0e5aa7ef2504b886951f1355b3386130992bc867cb00c16babcc441571da", avatar.HashAvatar(1, buf))
assert.Equal(t, "18a4a808c40d70ed532b6f19dfe7b8732eeb727e375c87a9944fde7555de285c", avatar.HashAvatar(8, buf))
assert.Equal(t, "5265546b79c483b2c399bba1df5746f77bba7145bb9f53b7b9c6b0fb57dc25eb", avatar.HashAvatar(1024, buf))
assert.Equal(t, "161178642c7d59eb25a61dddced5e6b66eae1c70880d5f148b1b497b767e72d9", avatar.HashAvatar(1024, []byte{}))
}

View File

@@ -54,24 +54,16 @@ func GetSigningKey(ctx context.Context) (*SigningKey, *Signature) {
return nil, nil
}
return &SigningKey{
KeyID: strings.TrimSpace(signingKey),
Format: strings.TrimSpace(format),
}, &Signature{
Name: strings.TrimSpace(signingName),
Email: strings.TrimSpace(signingEmail),
}
sigKey := &SigningKey{KeyID: strings.TrimSpace(signingKey), Format: strings.TrimSpace(format)}
sig := &Signature{Name: strings.TrimSpace(signingName), Email: strings.TrimSpace(signingEmail)}
return sigKey, sig
}
if setting.Repository.Signing.SigningKey == "" {
return nil, nil
}
return &SigningKey{
KeyID: setting.Repository.Signing.SigningKey,
Format: setting.Repository.Signing.SigningFormat,
}, &Signature{
Name: setting.Repository.Signing.SigningName,
Email: setting.Repository.Signing.SigningEmail,
}
sigKey := &SigningKey{KeyID: setting.Repository.Signing.SigningKey, Format: setting.Repository.Signing.SigningFormat}
sig := &Signature{Name: setting.Repository.Signing.SigningName, Email: setting.Repository.Signing.SigningEmail}
return sigKey, sig
}

View File

@@ -1,25 +0,0 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
//go:build !goexperiment.jsonv2
package json
import (
"encoding/json" //nolint:depguard // this package wraps it
"io"
)
func getDefaultJSONHandler() Interface {
return jsonV1{}
}
func MarshalKeepOptionalEmpty(v any) ([]byte, error) {
return DefaultJSONHandler.Marshal(v)
}
func NewDecoderCaseInsensitive(reader io.Reader) Decoder {
return DefaultJSONHandler.NewDecoder(reader)
}
type Value = json.RawMessage

View File

@@ -1,38 +0,0 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package json
import (
"bytes"
"encoding/json" //nolint:depguard // this package wraps it
"io"
)
type jsonV1 struct{}
var _ Interface = jsonV1{}
func (jsonV1) Marshal(v any) ([]byte, error) {
return json.Marshal(v)
}
func (jsonV1) MarshalWrite(w io.Writer, v any) error {
return json.NewEncoder(w).Encode(v)
}
func (jsonV1) Unmarshal(data []byte, v any) error {
return json.Unmarshal(data, v)
}
func (jsonV1) NewEncoder(writer io.Writer) Encoder {
return json.NewEncoder(writer)
}
func (jsonV1) NewDecoder(reader io.Reader) Decoder {
return json.NewDecoder(reader)
}
func (jsonV1) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
return json.Indent(dst, src, prefix, indent)
}

View File

@@ -1,8 +1,6 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
//go:build goexperiment.jsonv2
package json
import (
@@ -13,8 +11,6 @@ import (
"io"
)
// JSONv2 implements Interface via encoding/json/v2
// Requires GOEXPERIMENT=jsonv2 to be set at build time
type JSONv2 struct {
marshalOptions jsonv2.Options
marshalKeepOptionalEmptyOptions jsonv2.Options

View File

@@ -95,8 +95,8 @@ func TestParsePackage(t *testing.T) {
p, err := ParsePackage(data)
assert.NoError(t, err)
assert.NotNil(t, p)
assert.Equal(t, "Q1SRYURM5+uQDqfHSwTnNIOIuuDVQ=", p.FileMetadata.Checksum)
// FIXME: the logic is strange in ParsePackage, need to figure out how to calculate the checksum correctly
assert.Equal(t, "Q1GfcV5dUrPr1xIRekqPYGehdxjL8=", p.FileMetadata.Checksum)
})
t.Run("TooManyDependencyEntries", func(t *testing.T) {

View File

@@ -125,7 +125,7 @@ func EnvironmentToConfig(cfg ConfigProvider, envs []string) (changed bool) {
}
// use environment value as config value, or read the file content as value if the key indicates a file
keyValue := envValue //nolint:staticcheck // false positive
keyValue := envValue
if useFileValue {
fileContent, err := os.ReadFile(envValue)
if err != nil {

View File

@@ -795,7 +795,7 @@ func mustEnableIssuesOrPulls(ctx *context.APIContext) {
}
func mustEnableWiki(ctx *context.APIContext) {
if !(ctx.Repo.Permission.CanRead(unit.TypeWiki)) {
if !ctx.Repo.Permission.CanRead(unit.TypeWiki) {
ctx.APIErrorNotFound()
return
}

View File

@@ -70,7 +70,7 @@ func MonitorDiagnosis(ctx *context.Context) {
for _, record := range tailmsg.GetManager().GetTraceRecorder().GetRecords() {
_, _ = f.Write(util.UnsafeStringToBytes(record.Time.Format(time.RFC3339)))
_, _ = f.Write([]byte(" "))
_, _ = f.Write(util.UnsafeStringToBytes((record.Content)))
_, _ = f.Write(util.UnsafeStringToBytes(record.Content))
_, _ = f.Write([]byte("\n\n"))
}
}

View File

@@ -17,4 +17,4 @@ type sourceInterface interface {
auth_model.Config
}
var _ (sourceInterface) = &db.Source{}
var _ sourceInterface = &db.Source{}

View File

@@ -22,4 +22,4 @@ type sourceInterface interface {
auth_model.UseTLSer
}
var _ (sourceInterface) = &ldap.Source{}
var _ sourceInterface = &ldap.Source{}

View File

@@ -18,4 +18,4 @@ type sourceInterface interface {
auth.PasswordAuthenticator
}
var _ (sourceInterface) = &oauth2.Source{}
var _ sourceInterface = &oauth2.Source{}

View File

@@ -94,4 +94,4 @@ func (s *sizeWriter) Write(data []byte) (int, error) {
return len(data), nil
}
var _ (sessions.Store) = &SessionsStore{}
var _ sessions.Store = &SessionsStore{}

View File

@@ -17,4 +17,4 @@ type sourceInterface interface {
auth_model.Config
}
var _ (sourceInterface) = &pam.Source{}
var _ sourceInterface = &pam.Source{}

View File

@@ -20,4 +20,4 @@ type sourceInterface interface {
auth_model.UseTLSer
}
var _ (sourceInterface) = &smtp.Source{}
var _ sourceInterface = &smtp.Source{}

View File

@@ -15,4 +15,4 @@ type sourceInterface interface {
auth.Config
}
var _ (sourceInterface) = &sspi.Source{}
var _ sourceInterface = &sspi.Source{}

View File

@@ -169,7 +169,7 @@ func ToBranchProtection(ctx context.Context, bp *git_model.ProtectedBranch, repo
}
return &api.BranchProtection{
BranchName: branchName,
BranchName: branchName, //nolint:staticcheck // deprecated but useful to API response
RuleName: bp.RuleName,
Priority: bp.Priority,
EnablePush: bp.CanPush,

View File

@@ -130,9 +130,9 @@ func toProject(ctx context.Context, p *project_model.Project, doer *user_model.U
Description: p.Description,
OwnerID: p.OwnerID,
RepoID: p.RepoID,
CreatorID: p.CreatorID,
CreatorID: p.CreatorID, //nolint:staticcheck // deprecated but useful to API response
State: state,
IsClosed: p.IsClosed,
IsClosed: p.IsClosed, //nolint:staticcheck // deprecated but useful to API response
TemplateType: projectTemplateTypeToString(p.TemplateType),
CardType: projectCardTypeToString(p.CardType),
Type: projectTypeToString(p.Type),

View File

@@ -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())

View File

@@ -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)

View File

@@ -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)
})

View File

@@ -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)
}

View File

@@ -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) {

View File

@@ -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)
})
}

View File

@@ -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)
})
}