Skip to content

Commit 201d49d

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Catch the error before the response is processed by goth. (go-gitea#20000) Adjust transaction handling via db.Context (go-gitea#20031) Add more linters to improve code readability (go-gitea#19989) [skip ci] Updated translations via Crowdin Disable federation by default (go-gitea#20045) Respond with a 401 on git push when password isn't changed yet (go-gitea#20026) Alter hook_task TEXT fields to LONGTEXT (go-gitea#20038) Simplify and fix migration 216 (go-gitea#20035) use quoted regexp instead of git fixed-value (go-gitea#20029) fix delete pull head ref for DeleteIssue (go-gitea#20032) User keypairs and HTTP signatures for ActivityPub federation using go-ap (go-gitea#19133) Backtick table name in generic orphan check (go-gitea#20019) Update document to clarify that ALLOWED_DOMAINS/BLOCKED_DOMAINS support wildcard (go-gitea#20016) Return 404 when tag is broken (go-gitea#20017) Dump should only copy regular files and symlink regular files (go-gitea#20015)
2 parents d03cd54 + e67e685 commit 201d49d

File tree

197 files changed

+1286
-459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+1286
-459
lines changed

.golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ linters:
1919
- revive
2020
- gofumpt
2121
- depguard
22+
- nakedret
23+
- unconvert
24+
- wastedassign
25+
- nolintlint
26+
- stylecheck
2227
enable-all: false
2328
disable-all: true
2429
fast: false
@@ -32,6 +37,10 @@ run:
3237
- web_src
3338

3439
linters-settings:
40+
stylecheck:
41+
checks: ["all", "-ST1005", "-ST1003"]
42+
nakedret:
43+
max-func-lines: 0
3544
gocritic:
3645
disabled-checks:
3746
- ifElseChain

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func writeDataPktLine(out io.Writer, data []byte) error {
792792
if err != nil {
793793
return fail("Internal Server Error", "Pkt-Line response failed: %v", err)
794794
}
795-
if 4 != lr {
795+
if lr != 4 {
796796
return fail("Internal Server Error", "Pkt-Line response failed: %v", err)
797797
}
798798

custom/conf/app.example.ini

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,10 +2231,12 @@ PATH =
22312231
;;
22322232
;; Allowed domains for migrating, default is blank. Blank means everything will be allowed.
22332233
;; Multiple domains could be separated by commas.
2234+
;; Wildcard is supported: "github.com, *.github.com"
22342235
;ALLOWED_DOMAINS =
22352236
;;
22362237
;; Blocklist for migrating, default is blank. Multiple domains could be separated by commas.
22372238
;; When ALLOWED_DOMAINS is not blank, this option has a higher priority to deny domains.
2239+
;; Wildcard is supported.
22382240
;BLOCKED_DOMAINS =
22392241
;;
22402242
;; Allow private addresses defined by RFC 1918, RFC 1122, RFC 4632 and RFC 4291 (false by default)
@@ -2247,10 +2249,27 @@ PATH =
22472249
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22482250
;;
22492251
;; Enable/Disable federation capabilities
2250-
; ENABLED = true
2252+
;ENABLED = false
22512253
;;
22522254
;; Enable/Disable user statistics for nodeinfo if federation is enabled
2253-
; SHARE_USER_STATISTICS = true
2255+
;SHARE_USER_STATISTICS = true
2256+
;;
2257+
;; Maximum federation request and response size (MB)
2258+
;MAX_SIZE = 4
2259+
;;
2260+
;; WARNING: Changing the settings below can break federation.
2261+
;;
2262+
;; HTTP signature algorithms
2263+
;ALGORITHMS = rsa-sha256, rsa-sha512, ed25519
2264+
;;
2265+
;; HTTP signature digest algorithm
2266+
;DIGEST_ALGORITHM = SHA-256
2267+
;;
2268+
;; GET headers for federation requests
2269+
;GET_HEADERS = (request-target), Date
2270+
;;
2271+
;; POST headers for federation requests
2272+
;POST_HEADERS = (request-target), Date, Digest
22542273

22552274
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22562275
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,15 +1081,23 @@ Task queue configuration has been moved to `queue.task`. However, the below conf
10811081

10821082
- `MAX_ATTEMPTS`: **3**: Max attempts per http/https request on migrations.
10831083
- `RETRY_BACKOFF`: **3**: Backoff time per http/https request retry (seconds)
1084-
- `ALLOWED_DOMAINS`: **\<empty\>**: Domains allowlist for migrating repositories, default is blank. It means everything will be allowed. Multiple domains could be separated by commas.
1085-
- `BLOCKED_DOMAINS`: **\<empty\>**: Domains blocklist for migrating repositories, default is blank. Multiple domains could be separated by commas. When `ALLOWED_DOMAINS` is not blank, this option has a higher priority to deny domains.
1084+
- `ALLOWED_DOMAINS`: **\<empty\>**: Domains allowlist for migrating repositories, default is blank. It means everything will be allowed. Multiple domains could be separated by commas. Wildcard is supported: `github.com, *.github.com`.
1085+
- `BLOCKED_DOMAINS`: **\<empty\>**: Domains blocklist for migrating repositories, default is blank. Multiple domains could be separated by commas. When `ALLOWED_DOMAINS` is not blank, this option has a higher priority to deny domains. Wildcard is supported.
10861086
- `ALLOW_LOCALNETWORKS`: **false**: Allow private addresses defined by RFC 1918, RFC 1122, RFC 4632 and RFC 4291
10871087
- `SKIP_TLS_VERIFY`: **false**: Allow skip tls verify
10881088

10891089
## Federation (`federation`)
10901090

1091-
- `ENABLED`: **true**: Enable/Disable federation capabilities
1091+
- `ENABLED`: **false**: Enable/Disable federation capabilities
10921092
- `SHARE_USER_STATISTICS`: **true**: Enable/Disable user statistics for nodeinfo if federation is enabled
1093+
- `MAX_SIZE`: **4**: Maximum federation request and response size (MB)
1094+
1095+
WARNING: Changing the settings below can break federation.
1096+
1097+
- `ALGORITHMS`: **rsa-sha256, rsa-sha512, ed25519**: HTTP signature algorithms
1098+
- `DIGEST_ALGORITHM`: **SHA-256**: HTTP signature digest algorithm
1099+
- `GET_HEADERS`: **(request-target), Date**: GET headers for federation requests
1100+
- `POST_HEADERS`: **(request-target), Date, Digest**: POST headers for federation requests
10931101

10941102
## Packages (`packages`)
10951103

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ require (
2828
github.com/ethantkoenig/rupture v1.0.1
2929
github.com/felixge/fgprof v0.9.2
3030
github.com/gliderlabs/ssh v0.3.4
31+
github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b
32+
github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d
3133
github.com/go-chi/chi/v5 v5.0.7
3234
github.com/go-chi/cors v1.2.1
3335
github.com/go-enry/go-enry/v2 v2.8.2
34-
github.com/go-fed/httpsig v1.1.0
36+
github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e
3537
github.com/go-git/go-billy/v5 v5.3.1
3638
github.com/go-git/go-git/v5 v5.4.3-0.20210630082519-b4368b2a2ca4
3739
github.com/go-ldap/ldap/v3 v3.4.3
@@ -107,6 +109,7 @@ require (
107109

108110
require (
109111
cloud.google.com/go v0.99.0 // indirect
112+
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20200411073322-f0bcc40f0bf2 // indirect
110113
github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e // indirect
111114
github.com/Microsoft/go-winio v0.5.2 // indirect
112115
github.com/ProtonMail/go-crypto v0.0.0-20220407094043-a94812496cf5 // indirect
@@ -160,6 +163,7 @@ require (
160163
github.com/fsnotify/fsnotify v1.5.4 // indirect
161164
github.com/fullstorydev/grpcurl v1.8.1 // indirect
162165
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
166+
github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f // indirect
163167
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
164168
github.com/go-enry/go-oniguruma v1.2.1 // indirect
165169
github.com/go-git/gcfg v1.5.0 // indirect
@@ -252,6 +256,7 @@ require (
252256
github.com/toqueteos/webbrowser v1.2.0 // indirect
253257
github.com/ulikunitz/xz v0.5.10 // indirect
254258
github.com/unknwon/com v1.0.1 // indirect
259+
github.com/valyala/fastjson v1.6.3 // indirect
255260
github.com/x448/float16 v0.8.4 // indirect
256261
github.com/xanzy/ssh-agent v0.3.1 // indirect
257262
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect

go.sum

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ contrib.go.opencensus.io/exporter/stackdriver v0.13.5/go.mod h1:aXENhDJ1Y4lIg4EU
6969
contrib.go.opencensus.io/integrations/ocsql v0.1.4/go.mod h1:8DsSdjz3F+APR+0z0WkU1aRorQCFfRxvqjUUPMbF3fE=
7070
contrib.go.opencensus.io/resource v0.1.1/go.mod h1:F361eGI91LCmW1I/Saf+rX0+OFcigGlFvXwEGEnkRLA=
7171
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
72+
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20200411073322-f0bcc40f0bf2 h1:2OrsyJYZp7J6nyAsKi2q1SELYRaIc0aQmcQ/EQqPfk8=
73+
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20200411073322-f0bcc40f0bf2/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
7274
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb h1:Yy0Bxzc8R2wxiwXoG/rECGplJUSpXqCsog9PuJFgiHs=
7375
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb/go.mod h1:77TZu701zMXWJFvB8gvTbQ92zQ3DQq/H7l5wAEjQRKc=
7476
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0=
@@ -460,6 +462,12 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0
460462
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
461463
github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
462464
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
465+
github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b h1:+RjYfEfoZdM3wHFs752dlOpGaoRhwRRyQxjajg08LcQ=
466+
github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b/go.mod h1:DE3vvc6Didgfd3k7M1Mos6qMDFNmMrxJmYVMHG9h9Io=
467+
github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f h1:kJhGo4NApJP0Lt9lkJnfmuTnRWVFbCynY0kiTxpPUR4=
468+
github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f/go.mod h1:KHkKFKZvc05lr79+RGoq/zG8YjWi3+FK60Bxd+mpCew=
469+
github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d h1:Z/oRXMlZHjvjIqDma1FrIGL3iE5YL7MUI0bwYEZ6qbA=
470+
github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA=
463471
github.com/go-asn1-ber/asn1-ber v1.5.4 h1:vXT6d/FNDiELJnLb6hGNa309LMsrCoYFvpwHDF0+Y1A=
464472
github.com/go-asn1-ber/asn1-ber v1.5.4/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
465473
github.com/go-chi/chi/v5 v5.0.1/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
@@ -472,8 +480,8 @@ github.com/go-enry/go-enry/v2 v2.8.2 h1:uiGmC+3K8sVd/6DOe2AOJEOihJdqda83nPyJNtMR
472480
github.com/go-enry/go-enry/v2 v2.8.2/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
473481
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=
474482
github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4=
475-
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
476-
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
483+
github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e h1:oRq/fiirun5HqlEWMLIcDmLpIELlG4iGbd0s8iqgPi8=
484+
github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
477485
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
478486
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
479487
github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
@@ -1507,6 +1515,8 @@ github.com/urfave/cli v1.22.9 h1:cv3/KhXGBGjEXLC4bH0sLuJ9BewaAbpk5oyMOveu4pw=
15071515
github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
15081516
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
15091517
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
1518+
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
1519+
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
15101520
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
15111521
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
15121522
github.com/weppos/publicsuffix-go v0.13.1-0.20210123135404-5fd73613514e/go.mod h1:HYux0V0Zi04bHNwOHy4cXJVz/TQjYonnF6aoYhj+3QE=
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"context"
9+
"fmt"
10+
"net/http"
11+
"net/http/httptest"
12+
"net/url"
13+
"testing"
14+
15+
user_model "code.gitea.io/gitea/models/user"
16+
"code.gitea.io/gitea/modules/activitypub"
17+
"code.gitea.io/gitea/modules/setting"
18+
"code.gitea.io/gitea/routers"
19+
20+
ap "github.com/go-ap/activitypub"
21+
"github.com/stretchr/testify/assert"
22+
)
23+
24+
func TestActivityPubPerson(t *testing.T) {
25+
setting.Federation.Enabled = true
26+
c = routers.NormalRoutes()
27+
defer func() {
28+
setting.Federation.Enabled = false
29+
c = routers.NormalRoutes()
30+
}()
31+
32+
onGiteaRun(t, func(*testing.T, *url.URL) {
33+
username := "user2"
34+
req := NewRequestf(t, "GET", fmt.Sprintf("/api/v1/activitypub/user/%s", username))
35+
resp := MakeRequest(t, req, http.StatusOK)
36+
body := resp.Body.Bytes()
37+
assert.Contains(t, string(body), "@context")
38+
39+
var person ap.Person
40+
err := person.UnmarshalJSON(body)
41+
assert.NoError(t, err)
42+
43+
assert.Equal(t, ap.PersonType, person.Type)
44+
assert.Equal(t, username, person.PreferredUsername.String())
45+
keyID := person.GetID().String()
46+
assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyID)
47+
assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.Outbox.GetID().String())
48+
assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.Inbox.GetID().String())
49+
50+
pubKey := person.PublicKey
51+
assert.NotNil(t, pubKey)
52+
publicKeyID := keyID + "#main-key"
53+
assert.Equal(t, pubKey.ID.String(), publicKeyID)
54+
55+
pubKeyPem := pubKey.PublicKeyPem
56+
assert.NotNil(t, pubKeyPem)
57+
assert.Regexp(t, "^-----BEGIN PUBLIC KEY-----", pubKeyPem)
58+
})
59+
}
60+
61+
func TestActivityPubMissingPerson(t *testing.T) {
62+
setting.Federation.Enabled = true
63+
c = routers.NormalRoutes()
64+
defer func() {
65+
setting.Federation.Enabled = false
66+
c = routers.NormalRoutes()
67+
}()
68+
69+
onGiteaRun(t, func(*testing.T, *url.URL) {
70+
req := NewRequestf(t, "GET", "/api/v1/activitypub/user/nonexistentuser")
71+
resp := MakeRequest(t, req, http.StatusNotFound)
72+
assert.Contains(t, resp.Body.String(), "user redirect does not exist")
73+
})
74+
}
75+
76+
func TestActivityPubPersonInbox(t *testing.T) {
77+
setting.Federation.Enabled = true
78+
c = routers.NormalRoutes()
79+
defer func() {
80+
setting.Federation.Enabled = false
81+
c = routers.NormalRoutes()
82+
}()
83+
84+
srv := httptest.NewServer(c)
85+
defer srv.Close()
86+
87+
onGiteaRun(t, func(*testing.T, *url.URL) {
88+
appURL := setting.AppURL
89+
setting.AppURL = srv.URL
90+
defer func() {
91+
setting.Database.LogSQL = false
92+
setting.AppURL = appURL
93+
}()
94+
username1 := "user1"
95+
ctx := context.Background()
96+
user1, err := user_model.GetUserByName(ctx, username1)
97+
assert.NoError(t, err)
98+
user1url := fmt.Sprintf("%s/api/v1/activitypub/user/%s#main-key", srv.URL, username1)
99+
c, err := activitypub.NewClient(user1, user1url)
100+
assert.NoError(t, err)
101+
username2 := "user2"
102+
user2inboxurl := fmt.Sprintf("%s/api/v1/activitypub/user/%s/inbox", srv.URL, username2)
103+
104+
// Signed request succeeds
105+
resp, err := c.Post([]byte{}, user2inboxurl)
106+
assert.NoError(t, err)
107+
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
108+
109+
// Unsigned request fails
110+
req := NewRequest(t, "POST", user2inboxurl)
111+
MakeRequest(t, req, http.StatusInternalServerError)
112+
})
113+
}

integrations/api_issue_stopwatch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestAPIListStopWatches(t *testing.T) {
3838
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
3939
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
4040
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
41-
assert.Greater(t, int64(apiWatches[0].Seconds), int64(0))
41+
assert.Greater(t, apiWatches[0].Seconds, int64(0))
4242
}
4343
}
4444

integrations/api_nodeinfo_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ import (
1111

1212
"code.gitea.io/gitea/modules/setting"
1313
api "code.gitea.io/gitea/modules/structs"
14+
"code.gitea.io/gitea/routers"
1415

1516
"github.com/stretchr/testify/assert"
1617
)
1718

1819
func TestNodeinfo(t *testing.T) {
19-
onGiteaRun(t, func(*testing.T, *url.URL) {
20-
setting.Federation.Enabled = true
21-
defer func() {
22-
setting.Federation.Enabled = false
23-
}()
20+
setting.Federation.Enabled = true
21+
c = routers.NormalRoutes()
22+
defer func() {
23+
setting.Federation.Enabled = false
24+
c = routers.NormalRoutes()
25+
}()
2426

27+
onGiteaRun(t, func(*testing.T, *url.URL) {
2528
req := NewRequestf(t, "GET", "/api/v1/nodeinfo")
2629
resp := MakeRequest(t, req, http.StatusOK)
2730
var nodeinfo api.NodeInfo

integrations/api_packages_container_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestPackageContainer(t *testing.T) {
8888

8989
req = NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL))
9090
addTokenAuthHeader(req, anonymousToken)
91-
resp = MakeRequest(t, req, http.StatusOK)
91+
MakeRequest(t, req, http.StatusOK)
9292
})
9393

9494
t.Run("User", func(t *testing.T) {
@@ -112,7 +112,7 @@ func TestPackageContainer(t *testing.T) {
112112

113113
req = NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL))
114114
addTokenAuthHeader(req, userToken)
115-
resp = MakeRequest(t, req, http.StatusOK)
115+
MakeRequest(t, req, http.StatusOK)
116116
})
117117
})
118118

integrations/editor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
8282
"_csrf": csrf,
8383
"protected": "off",
8484
})
85-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
85+
session.MakeRequest(t, req, http.StatusSeeOther)
8686
// Check if master branch has been locked successfully
8787
flashCookie = session.GetCookie("macaron_flash")
8888
assert.NotNil(t, flashCookie)
@@ -109,7 +109,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
109109
"commit_choice": "direct",
110110
},
111111
)
112-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
112+
session.MakeRequest(t, req, http.StatusSeeOther)
113113

114114
// Verify the change
115115
req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", branch, filePath))
@@ -139,7 +139,7 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
139139
"new_branch_name": targetBranch,
140140
},
141141
)
142-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
142+
session.MakeRequest(t, req, http.StatusSeeOther)
143143

144144
// Verify the change
145145
req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", targetBranch, filePath))

0 commit comments

Comments
 (0)