mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 14:03:24 +09: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:
@@ -37,7 +37,7 @@ jobs:
|
|||||||
- uses: ./.github/actions/go-setup
|
- uses: ./.github/actions/go-setup
|
||||||
- run: make deps-backend deps-tools
|
- run: make deps-backend deps-tools
|
||||||
- run: TAGS="bindata" make backend
|
- run: TAGS="bindata" make backend
|
||||||
- run: TAGS="bindata gogit" GOEXPERIMENT="" make backend
|
- run: TAGS="bindata gogit" make backend
|
||||||
- name: warm test compile cache (bindata)
|
- name: warm test compile cache (bindata)
|
||||||
env:
|
env:
|
||||||
TAGS: bindata
|
TAGS: bindata
|
||||||
@@ -46,13 +46,12 @@ jobs:
|
|||||||
- name: warm test compile cache (bindata gogit)
|
- name: warm test compile cache (bindata gogit)
|
||||||
env:
|
env:
|
||||||
TAGS: bindata gogit
|
TAGS: bindata gogit
|
||||||
GOEXPERIMENT:
|
|
||||||
GOTEST_FLAGS: -race -list=^$$ -count=1
|
GOTEST_FLAGS: -race -list=^$$ -count=1
|
||||||
run: make test-backend
|
run: make test-backend
|
||||||
- name: warm integration compile cache
|
- name: warm integration compile cache
|
||||||
run: |
|
run: |
|
||||||
TAGS="bindata" make test-integration-compile
|
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
|
TAGS="bindata gogit" GOTEST_FLAGS="-race" make test-integration-compile
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ jobs:
|
|||||||
- run: make backend
|
- run: make backend
|
||||||
env:
|
env:
|
||||||
TAGS: bindata gogit
|
TAGS: bindata gogit
|
||||||
GOEXPERIMENT:
|
|
||||||
- run: GITEA_TEST_DATABASE=sqlite make test-migration
|
- run: GITEA_TEST_DATABASE=sqlite make test-migration
|
||||||
env:
|
env:
|
||||||
TAGS: bindata gogit
|
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
|
# sqlite driver can contain large amount of Golang code, so don't use race detector for it, otherwise, extremely slow
|
||||||
GOTEST_FLAGS: -timeout=40m
|
GOTEST_FLAGS: -timeout=40m
|
||||||
TAGS: bindata gogit
|
TAGS: bindata gogit
|
||||||
GOEXPERIMENT:
|
|
||||||
|
|
||||||
test-unit:
|
test-unit:
|
||||||
if: needs.files-changed.outputs.backend == 'true'
|
if: needs.files-changed.outputs.backend == 'true'
|
||||||
@@ -170,7 +168,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GOTEST_FLAGS: -race -timeout=20m
|
GOTEST_FLAGS: -race -timeout=20m
|
||||||
TAGS: bindata gogit
|
TAGS: bindata gogit
|
||||||
GOEXPERIMENT:
|
|
||||||
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}
|
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}
|
||||||
GITEA_TEST_CI_SKIP_EXTERNAL: true
|
GITEA_TEST_CI_SKIP_EXTERNAL: true
|
||||||
- run: make test-check
|
- run: make test-check
|
||||||
|
|||||||
+3
-2
@@ -17,7 +17,7 @@ linters:
|
|||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- mirror
|
- mirror
|
||||||
- modernize
|
# - modernize # re-enable it in a future PR, after clearly fixing all the issues it reports
|
||||||
- nakedret
|
- nakedret
|
||||||
- nilnil
|
- nilnil
|
||||||
- nolintlint
|
- nolintlint
|
||||||
@@ -182,7 +182,8 @@ formatters:
|
|||||||
- blank
|
- blank
|
||||||
- default
|
- default
|
||||||
gofumpt:
|
gofumpt:
|
||||||
extra-rules: true
|
extra:
|
||||||
|
group-params: true
|
||||||
exclusions:
|
exclusions:
|
||||||
generated: lax
|
generated: lax
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
# Build frontend on the native platform to avoid QEMU-related issues with nodejs ecosystem
|
# 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
|
RUN apk --no-cache add build-base git nodejs pnpm
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
||||||
@@ -9,7 +9,7 @@ COPY --exclude=.git/ . .
|
|||||||
RUN make frontend
|
RUN make frontend
|
||||||
|
|
||||||
# Build backend for each target platform
|
# 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 GITEA_VERSION
|
||||||
ARG TAGS=""
|
ARG TAGS=""
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
# Build frontend on the native platform to avoid QEMU-related issues with nodejs ecosystem
|
# 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
|
RUN apk --no-cache add build-base git nodejs pnpm
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
||||||
@@ -9,7 +9,7 @@ COPY --exclude=.git/ . .
|
|||||||
RUN make frontend
|
RUN make frontend
|
||||||
|
|
||||||
# Build backend for each target platform
|
# 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 GITEA_VERSION
|
||||||
ARG TAGS=""
|
ARG TAGS=""
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
DIST := dist
|
DIST := dist
|
||||||
DIST_DIRS := $(DIST)/binaries $(DIST)/release
|
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
|
GO ?= go
|
||||||
SHASUM ?= shasum -a 256
|
SHASUM ?= shasum -a 256
|
||||||
|
|
||||||
AIR_PACKAGE ?= github.com/air-verse/air@v1.67.4 # renovate: datasource=go
|
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
|
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
|
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
|
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
|
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
|
.PHONY: security-check
|
||||||
security-check:
|
security-check:
|
||||||
GOEXPERIMENT= go run $(GOVULNCHECK_PACKAGE) -show color ./... || true
|
go run $(GOVULNCHECK_PACKAGE) -show color ./... || true
|
||||||
|
|
||||||
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
|
$(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 $@
|
CGO_ENABLED="$(CGO_ENABLED)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -v $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
|
||||||
|
|||||||
+1
-1
@@ -752,7 +752,7 @@ func writeFlushPktLine(ctx context.Context, out io.Writer) error {
|
|||||||
func writeDataPktLine(ctx context.Context, out io.Writer, data []byte) error {
|
func writeDataPktLine(ctx context.Context, out io.Writer, data []byte) error {
|
||||||
hexchar := []byte("0123456789abcdef")
|
hexchar := []byte("0123456789abcdef")
|
||||||
hex := func(n uint64) byte {
|
hex := func(n uint64) byte {
|
||||||
return hexchar[(n)&15]
|
return hexchar[n&15]
|
||||||
}
|
}
|
||||||
|
|
||||||
length := uint64(len(data) + 4)
|
length := uint64(len(data) + 4)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ var curveStringMap = map[string]tls.CurveID{
|
|||||||
"p256": tls.CurveP256,
|
"p256": tls.CurveP256,
|
||||||
"p384": tls.CurveP384,
|
"p384": tls.CurveP384,
|
||||||
"p521": tls.CurveP521,
|
"p521": tls.CurveP521,
|
||||||
|
"mlkem1024": tls.MLKEM1024,
|
||||||
"x25519mlkem768": tls.X25519MLKEM768,
|
"x25519mlkem768": tls.X25519MLKEM768,
|
||||||
"secp256r1mlkem768": tls.SecP256r1MLKEM768,
|
"secp256r1mlkem768": tls.SecP256r1MLKEM768,
|
||||||
"secp384r1mlkem1024": tls.SecP384r1MLKEM1024,
|
"secp384r1mlkem1024": tls.SecP384r1MLKEM1024,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
module gitea.dev
|
module gitea.dev
|
||||||
|
|
||||||
go 1.26.0
|
go 1.27
|
||||||
|
|
||||||
toolchain go1.26.7
|
toolchain go1.27.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
connectrpc.com/connect v1.20.0
|
connectrpc.com/connect v1.20.0
|
||||||
|
|||||||
+3
-11
@@ -9,20 +9,12 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HashAvatar will generate a unique string, which ensures that when there's a
|
// HashAvatar generates a unique string for input ID and data.
|
||||||
// different unique ID while the data is the same, it will generate a different
|
// Because avatar is per-user, one user deletes their avatar should not affect another user who uses the same avatar.
|
||||||
// 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.
|
|
||||||
func HashAvatar(uniqueID int64, data []byte) string {
|
func HashAvatar(uniqueID int64, data []byte) string {
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write([]byte(strconv.FormatInt(uniqueID, 10)))
|
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)
|
h.Write(data)
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
package avatar_test
|
package avatar_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"image"
|
|
||||||
"image/png"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.dev/modules/avatar"
|
"gitea.dev/modules/avatar"
|
||||||
@@ -15,12 +12,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Test_HashAvatar(t *testing.T) {
|
func Test_HashAvatar(t *testing.T) {
|
||||||
myImage := image.NewRGBA(image.Rect(0, 0, 32, 32))
|
buf := []byte{1, 2}
|
||||||
var buff bytes.Buffer
|
assert.Equal(t, "057b0e5aa7ef2504b886951f1355b3386130992bc867cb00c16babcc441571da", avatar.HashAvatar(1, buf))
|
||||||
png.Encode(&buff, myImage)
|
assert.Equal(t, "18a4a808c40d70ed532b6f19dfe7b8732eeb727e375c87a9944fde7555de285c", avatar.HashAvatar(8, buf))
|
||||||
|
assert.Equal(t, "5265546b79c483b2c399bba1df5746f77bba7145bb9f53b7b9c6b0fb57dc25eb", avatar.HashAvatar(1024, buf))
|
||||||
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()))
|
|
||||||
assert.Equal(t, "161178642c7d59eb25a61dddced5e6b66eae1c70880d5f148b1b497b767e72d9", avatar.HashAvatar(1024, []byte{}))
|
assert.Equal(t, "161178642c7d59eb25a61dddced5e6b66eae1c70880d5f148b1b497b767e72d9", avatar.HashAvatar(1024, []byte{}))
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-14
@@ -54,24 +54,16 @@ func GetSigningKey(ctx context.Context) (*SigningKey, *Signature) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &SigningKey{
|
sigKey := &SigningKey{KeyID: strings.TrimSpace(signingKey), Format: strings.TrimSpace(format)}
|
||||||
KeyID: strings.TrimSpace(signingKey),
|
sig := &Signature{Name: strings.TrimSpace(signingName), Email: strings.TrimSpace(signingEmail)}
|
||||||
Format: strings.TrimSpace(format),
|
return sigKey, sig
|
||||||
}, &Signature{
|
|
||||||
Name: strings.TrimSpace(signingName),
|
|
||||||
Email: strings.TrimSpace(signingEmail),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if setting.Repository.Signing.SigningKey == "" {
|
if setting.Repository.Signing.SigningKey == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &SigningKey{
|
sigKey := &SigningKey{KeyID: setting.Repository.Signing.SigningKey, Format: setting.Repository.Signing.SigningFormat}
|
||||||
KeyID: setting.Repository.Signing.SigningKey,
|
sig := &Signature{Name: setting.Repository.Signing.SigningName, Email: setting.Repository.Signing.SigningEmail}
|
||||||
Format: setting.Repository.Signing.SigningFormat,
|
return sigKey, sig
|
||||||
}, &Signature{
|
|
||||||
Name: setting.Repository.Signing.SigningName,
|
|
||||||
Email: setting.Repository.Signing.SigningEmail,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright 2025 The Gitea Authors. All rights reserved.
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
//go:build goexperiment.jsonv2
|
|
||||||
|
|
||||||
package json
|
package json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -13,8 +11,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// JSONv2 implements Interface via encoding/json/v2
|
|
||||||
// Requires GOEXPERIMENT=jsonv2 to be set at build time
|
|
||||||
type JSONv2 struct {
|
type JSONv2 struct {
|
||||||
marshalOptions jsonv2.Options
|
marshalOptions jsonv2.Options
|
||||||
marshalKeepOptionalEmptyOptions jsonv2.Options
|
marshalKeepOptionalEmptyOptions jsonv2.Options
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ func TestParsePackage(t *testing.T) {
|
|||||||
p, err := ParsePackage(data)
|
p, err := ParsePackage(data)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, p)
|
assert.NotNil(t, p)
|
||||||
|
// FIXME: the logic is strange in ParsePackage, need to figure out how to calculate the checksum correctly
|
||||||
assert.Equal(t, "Q1SRYURM5+uQDqfHSwTnNIOIuuDVQ=", p.FileMetadata.Checksum)
|
assert.Equal(t, "Q1GfcV5dUrPr1xIRekqPYGehdxjL8=", p.FileMetadata.Checksum)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("TooManyDependencyEntries", func(t *testing.T) {
|
t.Run("TooManyDependencyEntries", func(t *testing.T) {
|
||||||
|
|||||||
@@ -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
|
// 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 {
|
if useFileValue {
|
||||||
fileContent, err := os.ReadFile(envValue)
|
fileContent, err := os.ReadFile(envValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -795,7 +795,7 @@ func mustEnableIssuesOrPulls(ctx *context.APIContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mustEnableWiki(ctx *context.APIContext) {
|
func mustEnableWiki(ctx *context.APIContext) {
|
||||||
if !(ctx.Repo.Permission.CanRead(unit.TypeWiki)) {
|
if !ctx.Repo.Permission.CanRead(unit.TypeWiki) {
|
||||||
ctx.APIErrorNotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func MonitorDiagnosis(ctx *context.Context) {
|
|||||||
for _, record := range tailmsg.GetManager().GetTraceRecorder().GetRecords() {
|
for _, record := range tailmsg.GetManager().GetTraceRecorder().GetRecords() {
|
||||||
_, _ = f.Write(util.UnsafeStringToBytes(record.Time.Format(time.RFC3339)))
|
_, _ = f.Write(util.UnsafeStringToBytes(record.Time.Format(time.RFC3339)))
|
||||||
_, _ = f.Write([]byte(" "))
|
_, _ = f.Write([]byte(" "))
|
||||||
_, _ = f.Write(util.UnsafeStringToBytes((record.Content)))
|
_, _ = f.Write(util.UnsafeStringToBytes(record.Content))
|
||||||
_, _ = f.Write([]byte("\n\n"))
|
_, _ = f.Write([]byte("\n\n"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ type sourceInterface interface {
|
|||||||
auth_model.Config
|
auth_model.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ (sourceInterface) = &db.Source{}
|
var _ sourceInterface = &db.Source{}
|
||||||
|
|||||||
@@ -22,4 +22,4 @@ type sourceInterface interface {
|
|||||||
auth_model.UseTLSer
|
auth_model.UseTLSer
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ (sourceInterface) = &ldap.Source{}
|
var _ sourceInterface = &ldap.Source{}
|
||||||
|
|||||||
@@ -18,4 +18,4 @@ type sourceInterface interface {
|
|||||||
auth.PasswordAuthenticator
|
auth.PasswordAuthenticator
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ (sourceInterface) = &oauth2.Source{}
|
var _ sourceInterface = &oauth2.Source{}
|
||||||
|
|||||||
@@ -94,4 +94,4 @@ func (s *sizeWriter) Write(data []byte) (int, error) {
|
|||||||
return len(data), nil
|
return len(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ (sessions.Store) = &SessionsStore{}
|
var _ sessions.Store = &SessionsStore{}
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ type sourceInterface interface {
|
|||||||
auth_model.Config
|
auth_model.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ (sourceInterface) = &pam.Source{}
|
var _ sourceInterface = &pam.Source{}
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ type sourceInterface interface {
|
|||||||
auth_model.UseTLSer
|
auth_model.UseTLSer
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ (sourceInterface) = &smtp.Source{}
|
var _ sourceInterface = &smtp.Source{}
|
||||||
|
|||||||
@@ -15,4 +15,4 @@ type sourceInterface interface {
|
|||||||
auth.Config
|
auth.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ (sourceInterface) = &sspi.Source{}
|
var _ sourceInterface = &sspi.Source{}
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ func ToBranchProtection(ctx context.Context, bp *git_model.ProtectedBranch, repo
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &api.BranchProtection{
|
return &api.BranchProtection{
|
||||||
BranchName: branchName,
|
BranchName: branchName, //nolint:staticcheck // deprecated but useful to API response
|
||||||
RuleName: bp.RuleName,
|
RuleName: bp.RuleName,
|
||||||
Priority: bp.Priority,
|
Priority: bp.Priority,
|
||||||
EnablePush: bp.CanPush,
|
EnablePush: bp.CanPush,
|
||||||
|
|||||||
@@ -130,9 +130,9 @@ func toProject(ctx context.Context, p *project_model.Project, doer *user_model.U
|
|||||||
Description: p.Description,
|
Description: p.Description,
|
||||||
OwnerID: p.OwnerID,
|
OwnerID: p.OwnerID,
|
||||||
RepoID: p.RepoID,
|
RepoID: p.RepoID,
|
||||||
CreatorID: p.CreatorID,
|
CreatorID: p.CreatorID, //nolint:staticcheck // deprecated but useful to API response
|
||||||
State: state,
|
State: state,
|
||||||
IsClosed: p.IsClosed,
|
IsClosed: p.IsClosed, //nolint:staticcheck // deprecated but useful to API response
|
||||||
TemplateType: projectTemplateTypeToString(p.TemplateType),
|
TemplateType: projectTemplateTypeToString(p.TemplateType),
|
||||||
CardType: projectCardTypeToString(p.CardType),
|
CardType: projectCardTypeToString(p.CardType),
|
||||||
Type: projectTypeToString(p.Type),
|
Type: projectTypeToString(p.Type),
|
||||||
|
|||||||
@@ -530,9 +530,9 @@ jobs:
|
|||||||
assert.Equal(t, apiPull.Head.Ref, gtCtx["head_ref"].GetStringValue())
|
assert.Equal(t, apiPull.Head.Ref, gtCtx["head_ref"].GetStringValue())
|
||||||
assert.Equal(t, actionRunJob.JobID, gtCtx["job"].GetStringValue())
|
assert.Equal(t, actionRunJob.JobID, gtCtx["job"].GetStringValue())
|
||||||
assert.Equal(t, actionRun.Ref, gtCtx["ref"].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.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+"/"+actionRun.Repo.Name, gtCtx["repository"].GetStringValue())
|
||||||
assert.Equal(t, actionRun.Repo.OwnerName, gtCtx["repository_owner"].GetStringValue())
|
assert.Equal(t, actionRun.Repo.OwnerName, gtCtx["repository_owner"].GetStringValue())
|
||||||
assert.Equal(t, actionRun.Repo.HTMLURL(), gtCtx["repositoryUrl"].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, apiPull.Head.Ref, gtCtx["head_ref"].GetStringValue())
|
||||||
assert.Equal(t, actionRunJob.JobID, gtCtx["job"].GetStringValue())
|
assert.Equal(t, actionRunJob.JobID, gtCtx["job"].GetStringValue())
|
||||||
assert.Equal(t, actionRun.Ref, gtCtx["ref"].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.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+"/"+actionRun.Repo.Name, gtCtx["repository"].GetStringValue())
|
||||||
assert.Equal(t, actionRun.Repo.OwnerName, gtCtx["repository_owner"].GetStringValue())
|
assert.Equal(t, actionRun.Repo.OwnerName, gtCtx["repository_owner"].GetStringValue())
|
||||||
assert.Equal(t, actionRun.Repo.HTMLURL(), gtCtx["repositoryUrl"].GetStringValue())
|
assert.Equal(t, actionRun.Repo.HTMLURL(), gtCtx["repositoryUrl"].GetStringValue())
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ package integration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/sha1"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
neturl "net/url"
|
neturl "net/url"
|
||||||
@@ -56,6 +58,7 @@ func TestPackageComposer(t *testing.T) {
|
|||||||
]
|
]
|
||||||
}`,
|
}`,
|
||||||
}).Bytes()
|
}).Bytes()
|
||||||
|
contentChecksum := sha1.Sum(content)
|
||||||
|
|
||||||
url := fmt.Sprintf("%sapi/packages/%s/composer", setting.AppURL, user.Name)
|
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.Len(t, pkgs[0].Authors, 1)
|
||||||
assert.Equal(t, packageAuthor, pkgs[0].Authors[0].Name)
|
assert.Equal(t, packageAuthor, pkgs[0].Authors[0].Name)
|
||||||
assert.Equal(t, "zip", pkgs[0].Dist.Type)
|
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.Len(t, pkgs[0].Bin, 1)
|
||||||
assert.Equal(t, packageBin, pkgs[0].Bin[0])
|
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.Len(t, pkgs[0].Authors, 1)
|
||||||
assert.Equal(t, packageAuthor, pkgs[0].Authors[0].Name)
|
assert.Equal(t, packageAuthor, pkgs[0].Authors[0].Name)
|
||||||
assert.Equal(t, "zip", pkgs[0].Dist.Type)
|
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.Len(t, pkgs[0].Bin, 1)
|
||||||
assert.Equal(t, packageBin, pkgs[0].Bin[0])
|
assert.Equal(t, packageBin, pkgs[0].Bin[0])
|
||||||
assert.Equal(t, repo1.HTMLURL(), pkgs[0].Source.URL)
|
assert.Equal(t, repo1.HTMLURL(), pkgs[0].Source.URL)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@@ -374,7 +373,7 @@ func TestPackageNuGet(t *testing.T) {
|
|||||||
t.Run("SymbolPackage", func(t *testing.T) {
|
t.Run("SymbolPackage", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
createSymbolPackage := func(id, packageType string) io.Reader {
|
createSymbolPackage := func(id, packageType string) []byte {
|
||||||
symbolData, _ := base64.StdEncoding.DecodeString(`QlNKQgEAAQAAAAAADAAAAFBEQiB2MS4wAAAAAAAABgB8AAAAWAAAACNQZGIAAAAA1AAAAAgBAAAj
|
symbolData, _ := base64.StdEncoding.DecodeString(`QlNKQgEAAQAAAAAADAAAAFBEQiB2MS4wAAAAAAAABgB8AAAAWAAAACNQZGIAAAAA1AAAAAgBAAAj
|
||||||
fgAA3AEAAAQAAAAjU3RyaW5ncwAAAADgAQAABAAAACNVUwDkAQAAMAAAACNHVUlEAAAAFAIAACgB
|
fgAA3AEAAAQAAAAjU3RyaW5ncwAAAADgAQAABAAAACNVUwDkAQAAMAAAACNHVUlEAAAAFAIAACgB
|
||||||
AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
||||||
@@ -390,19 +389,19 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
|||||||
</metadata>
|
</metadata>
|
||||||
</package>`,
|
</package>`,
|
||||||
symbolFilename: string(symbolData),
|
symbolFilename: string(symbolData),
|
||||||
})
|
}).Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
req := NewRequestWithBody(t, "PUT", url+"/symbolpackage", createSymbolPackage("unknown-package", "SymbolsPackage")).
|
pkgSymbolsPackageErr := createSymbolPackage("unknown-package", "SymbolsPackage")
|
||||||
AddBasicAuth(user.Name)
|
req := NewRequestWithBody(t, "PUT", url+"/symbolpackage", bytes.NewReader(pkgSymbolsPackageErr)).AddBasicAuth(user.Name)
|
||||||
MakeRequest(t, req, http.StatusNotFound)
|
MakeRequest(t, req, http.StatusNotFound)
|
||||||
|
|
||||||
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", createSymbolPackage(packageName, "DummyPackage")).
|
pkgDummyPackage := createSymbolPackage(packageName, "DummyPackage")
|
||||||
AddBasicAuth(user.Name)
|
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", bytes.NewReader(pkgDummyPackage)).AddBasicAuth(user.Name)
|
||||||
MakeRequest(t, req, http.StatusBadRequest)
|
MakeRequest(t, req, http.StatusBadRequest)
|
||||||
|
|
||||||
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", createSymbolPackage(packageName, "SymbolsPackage")).
|
pkgSymbolsPackage := createSymbolPackage(packageName, "SymbolsPackage")
|
||||||
AddBasicAuth(user.Name)
|
req = NewRequestWithBody(t, "PUT", url+"/symbolpackage", bytes.NewReader(pkgSymbolsPackage)).AddBasicAuth(user.Name)
|
||||||
MakeRequest(t, req, http.StatusCreated)
|
MakeRequest(t, req, http.StatusCreated)
|
||||||
|
|
||||||
pvs, err := packages.GetVersionsByPackageType(t.Context(), user.ID, packages.TypeNuGet)
|
pvs, err := packages.GetVersionsByPackageType(t.Context(), user.ID, packages.TypeNuGet)
|
||||||
@@ -426,13 +425,13 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
|
|||||||
|
|
||||||
pb, err := packages.GetBlobByID(t.Context(), pf.BlobID)
|
pb, err := packages.GetBlobByID(t.Context(), pf.BlobID)
|
||||||
assert.NoError(t, err)
|
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):
|
case fmt.Sprintf("%s.%s.snupkg", packageName, packageVersion):
|
||||||
assert.False(t, pf.IsLead)
|
assert.False(t, pf.IsLead)
|
||||||
|
|
||||||
pb, err := packages.GetBlobByID(t.Context(), pf.BlobID)
|
pb, err := packages.GetBlobByID(t.Context(), pf.BlobID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int64(616), pb.Size)
|
assert.EqualValues(t, len(pkgSymbolsPackage), pb.Size)
|
||||||
case packageName + ".nuspec":
|
case packageName + ".nuspec":
|
||||||
assert.False(t, pf.IsLead)
|
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)
|
AddBasicAuth(user.Name)
|
||||||
MakeRequest(t, req, http.StatusConflict)
|
MakeRequest(t, req, http.StatusConflict)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -238,15 +238,12 @@ gpgkey=%sapi/packages/%s/rpm/repository.key`,
|
|||||||
|
|
||||||
switch d.Type {
|
switch d.Type {
|
||||||
case "primary":
|
case "primary":
|
||||||
assert.EqualValues(t, 722, d.Size)
|
|
||||||
assert.EqualValues(t, 1759, d.OpenSize)
|
assert.EqualValues(t, 1759, d.OpenSize)
|
||||||
assert.Equal(t, "repodata/primary.xml.gz", d.Location.Href)
|
assert.Equal(t, "repodata/primary.xml.gz", d.Location.Href)
|
||||||
case "filelists":
|
case "filelists":
|
||||||
assert.EqualValues(t, 257, d.Size)
|
|
||||||
assert.EqualValues(t, 326, d.OpenSize)
|
assert.EqualValues(t, 326, d.OpenSize)
|
||||||
assert.Equal(t, "repodata/filelists.xml.gz", d.Location.Href)
|
assert.Equal(t, "repodata/filelists.xml.gz", d.Location.Href)
|
||||||
case "other":
|
case "other":
|
||||||
assert.EqualValues(t, 306, d.Size)
|
|
||||||
assert.EqualValues(t, 394, d.OpenSize)
|
assert.EqualValues(t, 394, d.OpenSize)
|
||||||
assert.Equal(t, "repodata/other.xml.gz", d.Location.Href)
|
assert.Equal(t, "repodata/other.xml.gz", d.Location.Href)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ import (
|
|||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"compress/zlib"
|
||||||
|
"crypto/md5"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -180,6 +183,7 @@ func TestPackageRubyGems(t *testing.T) {
|
|||||||
|
|
||||||
testAnotherGemName := "gitea-another"
|
testAnotherGemName := "gitea-another"
|
||||||
testAnotherGemVersion := "0.99"
|
testAnotherGemVersion := "0.99"
|
||||||
|
contentTestAnother := makeRubyGem(testAnotherGemName, testAnotherGemVersion)
|
||||||
|
|
||||||
root := fmt.Sprintf("/api/packages/%s/rubygems", user.Name)
|
root := fmt.Sprintf("/api/packages/%s/rubygems", user.Name)
|
||||||
|
|
||||||
@@ -243,11 +247,12 @@ func TestPackageRubyGems(t *testing.T) {
|
|||||||
AddBasicAuth(user.Name)
|
AddBasicAuth(user.Name)
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
b, _ := base64.StdEncoding.DecodeString(`eJxi4Si1EndPzbWyCi5ITc5My0xOLMnMz2M8zMIRLeGpxGWsZ6RnzGbF5hqSyempxJWeWZKayGbN
|
r, err := zlib.NewReader(resp.Body)
|
||||||
EBJqJQjWFZZaVJyZnxfN5qnEZahnoGcKkjTwVBJyB6lUKEhMzk5MTwULGngqcRaVJlWCONEMBp5K
|
assert.NoError(t, err)
|
||||||
DGAWSKc7zFhPJamg0qRK99TcYphehZLU4hKInFhGSUlBsZW+PtgZepn5+iDxECRzDUDGcfh6hoA4
|
b, err := io.ReadAll(r)
|
||||||
gAAAAP//MS06Gw==`)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, b, resp.Body.Bytes())
|
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)
|
pvs, err := packages.GetVersionsByPackageType(t.Context(), user.ID, packages.TypeRubyGems)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -258,12 +263,19 @@ gAAAAP//MS06Gw==`)
|
|||||||
t.Run("EnumeratePackages", func(t *testing.T) {
|
t.Run("EnumeratePackages", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
enumeratePackages := func(t *testing.T, endpoint string, expectedContent []byte) {
|
readGzBytes := func(t *testing.T, in []byte) []byte {
|
||||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/%s", root, endpoint)).
|
r, err := gzip.NewReader(bytes.NewReader(in))
|
||||||
AddBasicAuth(user.Name)
|
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)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
expectedBytes := readGzBytes(t, expectedGzip)
|
||||||
assert.Equal(t, expectedContent, resp.Body.Bytes())
|
actualBytes := readGzBytes(t, resp.Body.Bytes())
|
||||||
|
assert.Equal(t, expectedBytes, actualBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
b, _ := base64.StdEncoding.DecodeString(`H4sICAAAAAAA/3NwZWNzLjQuOABi4Yhmi+bwVOJKzyxJTWSzYnMNCbUSdE/NtbIKSy0qzszPi2bzVOIy1DPQM2WzZgjxVOIsKk2qBDEBAQAA///xOEYKOwAAAA==`)
|
b, _ := base64.StdEncoding.DecodeString(`H4sICAAAAAAA/3NwZWNzLjQuOABi4Yhmi+bwVOJKzyxJTWSzYnMNCbUSdE/NtbIKSy0qzszPi2bzVOIy1DPQM2WzZgjxVOIsKk2qBDEBAQAA///xOEYKOwAAAA==`)
|
||||||
@@ -276,7 +288,7 @@ gAAAAP//MS06Gw==`)
|
|||||||
|
|
||||||
t.Run("UploadAnother", func(t *testing.T) {
|
t.Run("UploadAnother", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
uploadFile(t, makeRubyGem(testAnotherGemName, testAnotherGemVersion), http.StatusCreated)
|
uploadFile(t, contentTestAnother, http.StatusCreated)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("PackageInfo", func(t *testing.T) {
|
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
|
1.0.5 runtime-dep:>= 1.2.0&< 2.0|checksum:%s,ruby:>= 2.3.0,rubygems:>= 1.0
|
||||||
`, testGemContentChecksum)
|
`, testGemContentChecksum)
|
||||||
assert.Equal(t, expected, resp.Body.String())
|
assert.Equal(t, expected, resp.Body.String())
|
||||||
})
|
testGemInfoMd5 := fmt.Sprintf("%x", md5.Sum(resp.Body.Bytes()))
|
||||||
|
|
||||||
t.Run("Versions", func(t *testing.T) {
|
req = NewRequest(t, "GET", fmt.Sprintf("%s/info/%s", root, testAnotherGemName)).AddBasicAuth(user.Name)
|
||||||
defer tests.PrintCurrentTest(t)()
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
req := NewRequest(t, "GET", root+"/versions").AddBasicAuth(user.Name)
|
testAnotherGemInfoMd5 := fmt.Sprintf("%x", md5.Sum(resp.Body.Bytes()))
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
|
||||||
assert.Equal(t, `---
|
t.Run("Versions", func(t *testing.T) {
|
||||||
gitea 1.0.5 08843c2dd0ea19910e6b056b98e38f1c
|
defer tests.PrintCurrentTest(t)()
|
||||||
gitea-another 0.99 8b639e4048d282941485368ec42609be
|
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())
|
`, resp.Body.String())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
deleteGemPackage := func(t *testing.T, packageName, packageVersion string) {
|
deleteGemPackage := func(t *testing.T, packageName, packageVersion string) {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"crypto/sha512"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -52,6 +54,7 @@ func TestPackageVagrant(t *testing.T) {
|
|||||||
archive.Close()
|
archive.Close()
|
||||||
zw.Close()
|
zw.Close()
|
||||||
content := buf.Bytes()
|
content := buf.Bytes()
|
||||||
|
contentChecksum := sha512.Sum512(content)
|
||||||
|
|
||||||
root := fmt.Sprintf("/api/packages/%s/vagrant", user.Name)
|
root := fmt.Sprintf("/api/packages/%s/vagrant", user.Name)
|
||||||
|
|
||||||
@@ -164,6 +167,6 @@ func TestPackageVagrant(t *testing.T) {
|
|||||||
provider := version.Providers[0]
|
provider := version.Providers[0]
|
||||||
assert.Equal(t, packageProvider, provider.Name)
|
assert.Equal(t, packageProvider, provider.Name)
|
||||||
assert.Equal(t, "sha512", provider.ChecksumType)
|
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)
|
resp := performUpload(t, assetURL, bufImageBytes, http.StatusCreated)
|
||||||
attachment := DecodeJSON(t, resp, &api.Attachment{})
|
attachment := DecodeJSON(t, resp, &api.Attachment{})
|
||||||
assert.Equal(t, filename, attachment.Name)
|
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) {
|
t.Run("UploadWithName", func(t *testing.T) {
|
||||||
resp := performUpload(t, assetURL+"?name=test-asset", bufImageBytes, http.StatusCreated)
|
resp := performUpload(t, assetURL+"?name=test-asset", bufImageBytes, http.StatusCreated)
|
||||||
attachment := DecodeJSON(t, resp, &api.Attachment{})
|
attachment := DecodeJSON(t, resp, &api.Attachment{})
|
||||||
assert.Equal(t, "test-asset", attachment.Name)
|
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{})
|
attachment := DecodeJSON(t, resp, &api.Attachment{})
|
||||||
|
|
||||||
assert.Equal(t, "stream.bin", attachment.Name)
|
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