Skip to content

Commit a58fc9e

Browse files
authored
Merge branch 'main' into cache-last-commit-data-as-found
2 parents a741466 + 28f6f7b commit a58fc9e

Some content is hidden

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

51 files changed

+445
-138
lines changed

.drone.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ steps:
217217
GITHUB_READ_TOKEN:
218218
from_secret: github_read_token
219219

220+
- name: unit-test-race
221+
image: golang:1.16
222+
commands:
223+
- make test-backend
224+
environment:
225+
GOPROXY: off
226+
TAGS: sqlite sqlite_unlock_notify
227+
RACE_ENABLED: true
228+
GITHUB_READ_TOKEN:
229+
from_secret: github_read_token
230+
220231
- name: unit-test-gogit
221232
pull: always
222233
image: golang:1.16

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ test: test-frontend test-backend
359359

360360
.PHONY: test-backend
361361
test-backend:
362-
@echo "Running go test with -tags '$(TEST_TAGS)'..."
362+
@echo "Running go test with $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
363363
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' $(GO_PACKAGES)
364364

365365
.PHONY: test-frontend
@@ -389,7 +389,7 @@ coverage:
389389

390390
.PHONY: unit-test-coverage
391391
unit-test-coverage:
392-
@echo "Running unit-test-coverage -tags '$(TEST_TAGS)'..."
392+
@echo "Running unit-test-coverage $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
393393
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
394394

395395
.PHONY: vendor

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,11 @@ relation to port exhaustion.
527527
- `USER_DELETE_WITH_COMMENTS_MAX_TIME`: **0** Minimum amount of time a user must exist before comments are kept when the user is deleted.
528528
- `VALID_SITE_URL_SCHEMES`: **http, https**: Valid site url schemes for user profiles
529529

530-
### Service - Expore (`service.explore`)
530+
### Service - Explore (`service.explore`)
531531

532532
- `REQUIRE_SIGNIN_VIEW`: **false**: Only allow signed in users to view the explore pages.
533533
- `DISABLE_USERS_PAGE`: **false**: Disable the users explore page.
534534

535-
536535
## SSH Minimum Key Sizes (`ssh.minimum_key_sizes`)
537536

538537
Define allowed algorithms and their minimum key length (use -1 to disable a type):

docs/content/doc/advanced/customizing-gitea.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ to the file `templates/custom/footer.tmpl`
200200

201201
You also need to download the content of the library [Madeleine.js](https://jinjunho.github.io/Madeleine.js/) and place it under `$GITEA_CUSTOM/public/` folder.
202202

203-
You should end-up with a folder structucture similar to:
203+
You should end-up with a folder structure similar to:
204204

205205
```
206206
$GITEA_CUSTOM/templates

docs/content/doc/advanced/make.fr-fr.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ sudo yum install make
3737

3838
Si vous utilisez Windows, vous pouvez télécharger une des versions suivantes de Make:
3939

40-
- [Simple binaire](http://www.equation.com/servlet/equation.cmd?fa=make). Copiez le quelque part et mettez à jour `PATH`.
40+
- [Simple binaire](http://www.equation.com/servlet/equation.cmd?fa=make). Copiez-le quelque part et mettez à jour `PATH`.
4141
- [32-bits version](ftp://ftp.equation.com/make/32/make.exe)
4242
- [64-bits version](ftp://ftp.equation.com/make/64/make.exe)
43-
- [MinGW](http://www.mingw.org/) includes a build. The binary is called `mingw32-make.exe` instead of `make.exe`. Add the `bin` folder to your `PATH`.
44-
- [Chocolatey package](https://chocolatey.org/packages/make). Run `choco install make`
43+
- [MinGW](http://www.mingw.org/) inclut un _build_. Le fichier binaire est nommé `mingw32-make.exe` plutôt que `make.exe`. Ajoutez le dossier `bin` à votre `PATH`.
44+
- [Chocolatey package](https://chocolatey.org/packages/make). Exécutez `choco install make`.

docs/content/doc/installation/windows-service.fr-fr.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Pour activer le service Windows Gitea, ouvrez une `cmd` en tant qu'Administrateu
2121
sc create gitea start= auto binPath= "\"C:\gitea\gitea.exe\" web --config \"C:\gitea\custom\conf\app.ini\""
2222
```
2323

24-
N'oubliez pas de remplacer `C:\gitea` par le chemin que vous avez utilisez pour votre installation.
24+
N'oubliez pas de remplacer `C:\gitea` par le chemin que vous avez utilisé pour votre installation.
2525

26-
Ensuite, ouvrez "Services Windows", puis recherchez le service `gitea`, faites un clique droit et selectionnez "Run". Si tout fonctionne, vous devriez être capable d'accèder à Gitea à l'URL `http://localhost:3000` (ou sur le port configuré si différent de 3000).
26+
Ensuite, ouvrez "Services Windows", puis recherchez le service `gitea`, faites un clic droit et selectionnez "Run". Si tout fonctionne, vous devriez être capable d'accèder à Gitea à l'URL `http://localhost:3000` (ou sur le port configuré si différent de 3000).
2727

2828
## Désactiver un service Windows
2929

integrations/auth_ldap_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,60 @@ func TestLDAPUserSignin(t *testing.T) {
144144
assert.Equal(t, u.Email, htmlDoc.Find(`label[for="email"]`).Siblings().First().Text())
145145
}
146146

147+
func TestLDAPAuthChange(t *testing.T) {
148+
defer prepareTestEnv(t)()
149+
addAuthSourceLDAP(t, "")
150+
151+
session := loginUser(t, "user1")
152+
req := NewRequest(t, "GET", "/admin/auths")
153+
resp := session.MakeRequest(t, req, http.StatusOK)
154+
doc := NewHTMLParser(t, resp.Body)
155+
href, exists := doc.Find("table.table td a").Attr("href")
156+
if !exists {
157+
assert.True(t, exists, "No authentication source found")
158+
return
159+
}
160+
161+
req = NewRequest(t, "GET", href)
162+
resp = session.MakeRequest(t, req, http.StatusOK)
163+
doc = NewHTMLParser(t, resp.Body)
164+
csrf := doc.GetCSRF()
165+
host, _ := doc.Find(`input[name="host"]`).Attr("value")
166+
assert.Equal(t, host, getLDAPServerHost())
167+
binddn, _ := doc.Find(`input[name="bind_dn"]`).Attr("value")
168+
assert.Equal(t, binddn, "uid=gitea,ou=service,dc=planetexpress,dc=com")
169+
170+
req = NewRequestWithValues(t, "POST", href, map[string]string{
171+
"_csrf": csrf,
172+
"type": "2",
173+
"name": "ldap",
174+
"host": getLDAPServerHost(),
175+
"port": "389",
176+
"bind_dn": "uid=gitea,ou=service,dc=planetexpress,dc=com",
177+
"bind_password": "password",
178+
"user_base": "ou=people,dc=planetexpress,dc=com",
179+
"filter": "(&(objectClass=inetOrgPerson)(memberOf=cn=git,ou=people,dc=planetexpress,dc=com)(uid=%s))",
180+
"admin_filter": "(memberOf=cn=admin_staff,ou=people,dc=planetexpress,dc=com)",
181+
"restricted_filter": "(uid=leela)",
182+
"attribute_username": "uid",
183+
"attribute_name": "givenName",
184+
"attribute_surname": "sn",
185+
"attribute_mail": "mail",
186+
"attribute_ssh_public_key": "",
187+
"is_sync_enabled": "on",
188+
"is_active": "on",
189+
})
190+
session.MakeRequest(t, req, http.StatusFound)
191+
192+
req = NewRequest(t, "GET", href)
193+
resp = session.MakeRequest(t, req, http.StatusOK)
194+
doc = NewHTMLParser(t, resp.Body)
195+
host, _ = doc.Find(`input[name="host"]`).Attr("value")
196+
assert.Equal(t, host, getLDAPServerHost())
197+
binddn, _ = doc.Find(`input[name="bind_dn"]`).Attr("value")
198+
assert.Equal(t, binddn, "uid=gitea,ou=service,dc=planetexpress,dc=com")
199+
}
200+
147201
func TestLDAPUserSync(t *testing.T) {
148202
if skipLDAPTests() {
149203
t.Skip()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
423313fbd38093bb10d0c8387db9105409c6f196
1+
0dca5bd9b5d7ef937710e056f575e86c0184ba85

models/login_source.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package models
77

88
import (
99
"crypto/tls"
10+
"encoding/binary"
1011
"errors"
1112
"fmt"
1213
"net/smtp"
@@ -70,11 +71,30 @@ var (
7071
_ convert.Conversion = &SSPIConfig{}
7172
)
7273

73-
// jsonUnmarshalIgnoreErroneousBOM - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
74-
// possible that a Blob may gain an unwanted prefix of 0xff 0xfe.
75-
func jsonUnmarshalIgnoreErroneousBOM(bs []byte, v interface{}) error {
74+
// jsonUnmarshalHandleDoubleEncode - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
75+
// possible that a Blob may be double encoded or gain an unwanted prefix of 0xff 0xfe.
76+
func jsonUnmarshalHandleDoubleEncode(bs []byte, v interface{}) error {
7677
json := jsoniter.ConfigCompatibleWithStandardLibrary
7778
err := json.Unmarshal(bs, v)
79+
if err != nil {
80+
ok := true
81+
rs := []byte{}
82+
temp := make([]byte, 2)
83+
for _, rn := range string(bs) {
84+
if rn > 0xffff {
85+
ok = false
86+
break
87+
}
88+
binary.LittleEndian.PutUint16(temp, uint16(rn))
89+
rs = append(rs, temp...)
90+
}
91+
if ok {
92+
if rs[0] == 0xff && rs[1] == 0xfe {
93+
rs = rs[2:]
94+
}
95+
err = json.Unmarshal(rs, v)
96+
}
97+
}
7898
if err != nil && len(bs) > 2 && bs[0] == 0xff && bs[1] == 0xfe {
7999
err = json.Unmarshal(bs[2:], v)
80100
}
@@ -88,7 +108,7 @@ type LDAPConfig struct {
88108

89109
// FromDB fills up a LDAPConfig from serialized format.
90110
func (cfg *LDAPConfig) FromDB(bs []byte) error {
91-
err := jsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
111+
err := jsonUnmarshalHandleDoubleEncode(bs, &cfg)
92112
if err != nil {
93113
return err
94114
}
@@ -129,7 +149,7 @@ type SMTPConfig struct {
129149

130150
// FromDB fills up an SMTPConfig from serialized format.
131151
func (cfg *SMTPConfig) FromDB(bs []byte) error {
132-
return jsonUnmarshalIgnoreErroneousBOM(bs, cfg)
152+
return jsonUnmarshalHandleDoubleEncode(bs, cfg)
133153
}
134154

135155
// ToDB exports an SMTPConfig to a serialized format.
@@ -146,7 +166,7 @@ type PAMConfig struct {
146166

147167
// FromDB fills up a PAMConfig from serialized format.
148168
func (cfg *PAMConfig) FromDB(bs []byte) error {
149-
return jsonUnmarshalIgnoreErroneousBOM(bs, cfg)
169+
return jsonUnmarshalHandleDoubleEncode(bs, cfg)
150170
}
151171

152172
// ToDB exports a PAMConfig to a serialized format.
@@ -167,7 +187,7 @@ type OAuth2Config struct {
167187

168188
// FromDB fills up an OAuth2Config from serialized format.
169189
func (cfg *OAuth2Config) FromDB(bs []byte) error {
170-
return jsonUnmarshalIgnoreErroneousBOM(bs, cfg)
190+
return jsonUnmarshalHandleDoubleEncode(bs, cfg)
171191
}
172192

173193
// ToDB exports an SMTPConfig to a serialized format.
@@ -187,7 +207,7 @@ type SSPIConfig struct {
187207

188208
// FromDB fills up an SSPIConfig from serialized format.
189209
func (cfg *SSPIConfig) FromDB(bs []byte) error {
190-
return jsonUnmarshalIgnoreErroneousBOM(bs, cfg)
210+
return jsonUnmarshalHandleDoubleEncode(bs, cfg)
191211
}
192212

193213
// ToDB exports an SSPIConfig to a serialized format.

models/repo_unit.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type UnitConfig struct{}
2828

2929
// FromDB fills up a UnitConfig from serialized format.
3030
func (cfg *UnitConfig) FromDB(bs []byte) error {
31-
return jsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
31+
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
3232
}
3333

3434
// ToDB exports a UnitConfig to a serialized format.
@@ -44,7 +44,7 @@ type ExternalUncycloConfig struct {
4444

4545
// FromDB fills up a ExternalUncycloConfig from serialized format.
4646
func (cfg *ExternalUncycloConfig) FromDB(bs []byte) error {
47-
return jsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
47+
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
4848
}
4949

5050
// ToDB exports a ExternalUncycloConfig to a serialized format.
@@ -62,7 +62,7 @@ type ExternalTrackerConfig struct {
6262

6363
// FromDB fills up a ExternalTrackerConfig from serialized format.
6464
func (cfg *ExternalTrackerConfig) FromDB(bs []byte) error {
65-
return jsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
65+
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
6666
}
6767

6868
// ToDB exports a ExternalTrackerConfig to a serialized format.
@@ -80,7 +80,7 @@ type IssuesConfig struct {
8080

8181
// FromDB fills up a IssuesConfig from serialized format.
8282
func (cfg *IssuesConfig) FromDB(bs []byte) error {
83-
return jsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
83+
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
8484
}
8585

8686
// ToDB exports a IssuesConfig to a serialized format.
@@ -104,7 +104,7 @@ type PullRequestsConfig struct {
104104

105105
// FromDB fills up a PullRequestsConfig from serialized format.
106106
func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
107-
return jsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
107+
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
108108
}
109109

110110
// ToDB exports a PullRequestsConfig to a serialized format.

modules/git/batch_reader.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package git
77
import (
88
"bufio"
99
"bytes"
10+
"context"
1011
"io"
1112
"math"
1213
"strconv"
@@ -28,23 +29,28 @@ type WriteCloserError interface {
2829
func CatFileBatchCheck(repoPath string) (WriteCloserError, *bufio.Reader, func()) {
2930
batchStdinReader, batchStdinWriter := io.Pipe()
3031
batchStdoutReader, batchStdoutWriter := io.Pipe()
32+
ctx, ctxCancel := context.WithCancel(DefaultContext)
33+
closed := make(chan struct{})
3134
cancel := func() {
3235
_ = batchStdinReader.Close()
3336
_ = batchStdinWriter.Close()
3437
_ = batchStdoutReader.Close()
3538
_ = batchStdoutWriter.Close()
39+
ctxCancel()
40+
<-closed
3641
}
3742

3843
go func() {
3944
stderr := strings.Builder{}
40-
err := NewCommand("cat-file", "--batch-check").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
45+
err := NewCommandContext(ctx, "cat-file", "--batch-check").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
4146
if err != nil {
4247
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
4348
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
4449
} else {
4550
_ = batchStdoutWriter.Close()
4651
_ = batchStdinReader.Close()
4752
}
53+
close(closed)
4854
}()
4955

5056
// For simplicities sake we'll use a buffered reader to read from the cat-file --batch-check
@@ -59,23 +65,28 @@ func CatFileBatch(repoPath string) (WriteCloserError, *bufio.Reader, func()) {
5965
// so let's create a batch stdin and stdout
6066
batchStdinReader, batchStdinWriter := io.Pipe()
6167
batchStdoutReader, batchStdoutWriter := nio.Pipe(buffer.New(32 * 1024))
68+
ctx, ctxCancel := context.WithCancel(DefaultContext)
69+
closed := make(chan struct{})
6270
cancel := func() {
6371
_ = batchStdinReader.Close()
6472
_ = batchStdinWriter.Close()
6573
_ = batchStdoutReader.Close()
6674
_ = batchStdoutWriter.Close()
75+
ctxCancel()
76+
<-closed
6777
}
6878

6979
go func() {
7080
stderr := strings.Builder{}
71-
err := NewCommand("cat-file", "--batch").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
81+
err := NewCommandContext(ctx, "cat-file", "--batch").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
7282
if err != nil {
7383
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
7484
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
7585
} else {
7686
_ = batchStdoutWriter.Close()
7787
_ = batchStdinReader.Close()
7888
}
89+
close(closed)
7990
}()
8091

8192
// For simplicities sake we'll us a buffered reader to read from the cat-file --batch

modules/git/tree.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package git
77

88
import (
9+
"bytes"
910
"strings"
1011
)
1112

@@ -45,3 +46,23 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) {
4546
}
4647
return g, nil
4748
}
49+
50+
// LsTree checks if the given filenames are in the tree
51+
func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error) {
52+
cmd := NewCommand("ls-tree", "-z", "--name-only", "--", ref)
53+
for _, arg := range filenames {
54+
if arg != "" {
55+
cmd.AddArguments(arg)
56+
}
57+
}
58+
res, err := cmd.RunInDirBytes(repo.Path)
59+
if err != nil {
60+
return nil, err
61+
}
62+
filelist := make([]string, 0, len(filenames))
63+
for _, line := range bytes.Split(res, []byte{'\000'}) {
64+
filelist = append(filelist, string(line))
65+
}
66+
67+
return filelist, err
68+
}

0 commit comments

Comments
 (0)