Skip to content

Commit 4c19a1e

Browse files
authored
Merge branch 'main' into wip-stats
2 parents ef39703 + 7ba1b71 commit 4c19a1e

File tree

13 files changed

+84
-42
lines changed

13 files changed

+84
-42
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ endif
6060

6161
EXTRA_GOFLAGS ?=
6262

63-
MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
63+
MAKE_VERSION := $(shell "$(MAKE)" -v | head -n 1)
6464
MAKE_EVIDENCE_DIR := .make_evidence
6565

6666
ifeq ($(RACE_ENABLED),true)

integrations/api_oauth2_apps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func testAPICreateOAuth2Application(t *testing.T) {
4343
DecodeJSON(t, resp, &createdApp)
4444

4545
assert.EqualValues(t, appBody.Name, createdApp.Name)
46-
assert.Len(t, createdApp.ClientSecret, 44)
46+
assert.Len(t, createdApp.ClientSecret, 56)
4747
assert.Len(t, createdApp.ClientID, 36)
4848
assert.NotEmpty(t, createdApp.Created)
4949
assert.EqualValues(t, appBody.RedirectURIs[0], createdApp.RedirectURIs[0])

models/auth/oauth2.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ package auth
66

77
import (
88
"crypto/sha256"
9+
"encoding/base32"
910
"encoding/base64"
1011
"fmt"
1112
"net/url"
1213
"strings"
1314

1415
"code.gitea.io/gitea/models/db"
15-
"code.gitea.io/gitea/modules/secret"
1616
"code.gitea.io/gitea/modules/timeutil"
1717
"code.gitea.io/gitea/modules/util"
1818

@@ -57,12 +57,22 @@ func (app *OAuth2Application) ContainsRedirectURI(redirectURI string) bool {
5757
return util.IsStringInSlice(redirectURI, app.RedirectURIs, true)
5858
}
5959

60+
// Base32 characters, but lowercased.
61+
const lowerBase32Chars = "abcdefghijklmnopqrstuvwxyz234567"
62+
63+
// base32 encoder that uses lowered characters without padding.
64+
var base32Lower = base32.NewEncoding(lowerBase32Chars).WithPadding(base32.NoPadding)
65+
6066
// GenerateClientSecret will generate the client secret and returns the plaintext and saves the hash at the database
6167
func (app *OAuth2Application) GenerateClientSecret() (string, error) {
62-
clientSecret, err := secret.New()
68+
rBytes, err := util.CryptoRandomBytes(32)
6369
if err != nil {
6470
return "", err
6571
}
72+
// Add a prefix to the base32, this is in order to make it easier
73+
// for code scanners to grab sensitive tokens.
74+
clientSecret := "gto_" + base32Lower.EncodeToString(rBytes)
75+
6676
hashedSecret, err := bcrypt.GenerateFromPassword([]byte(clientSecret), bcrypt.DefaultCost)
6777
if err != nil {
6878
return "", err
@@ -394,10 +404,14 @@ func (grant *OAuth2Grant) GenerateNewAuthorizationCode(redirectURI, codeChalleng
394404
}
395405

396406
func (grant *OAuth2Grant) generateNewAuthorizationCode(e db.Engine, redirectURI, codeChallenge, codeChallengeMethod string) (code *OAuth2AuthorizationCode, err error) {
397-
var codeSecret string
398-
if codeSecret, err = secret.New(); err != nil {
407+
rBytes, err := util.CryptoRandomBytes(32)
408+
if err != nil {
399409
return &OAuth2AuthorizationCode{}, err
400410
}
411+
// Add a prefix to the base32, this is in order to make it easier
412+
// for code scanners to grab sensitive tokens.
413+
codeSecret := "gta_" + base32Lower.EncodeToString(rBytes)
414+
401415
code = &OAuth2AuthorizationCode{
402416
Grant: grant,
403417
GrantID: grant.ID,

modules/queue/manager.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ type ManagedPool interface {
8484
BoostWorkers() int
8585
// SetPoolSettings sets the user updatable settings for the pool
8686
SetPoolSettings(maxNumberOfWorkers, boostWorkers int, timeout time.Duration)
87+
// Done returns a channel that will be closed when the Pool's baseCtx is closed
88+
Done() <-chan struct{}
8789
}
8890

8991
// ManagedQueueList implements the sort.Interface
@@ -211,6 +213,15 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
211213
continue
212214
}
213215
}
216+
if pool, ok := mq.Managed.(ManagedPool); ok {
217+
// No point into flushing pools when their base's ctx is already done.
218+
select {
219+
case <-pool.Done():
220+
wg.Done()
221+
continue
222+
default:
223+
}
224+
}
214225

215226
allEmpty = false
216227
if flushable, ok := mq.Managed.(Flushable); ok {

modules/queue/workerpool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func NewWorkerPool(handle HandlerFunc, config WorkerPoolConfiguration) *WorkerPo
7474
return pool
7575
}
7676

77+
// Done returns when this worker pool's base context has been cancelled
78+
func (p *WorkerPool) Done() <-chan struct{} {
79+
return p.baseCtx.Done()
80+
}
81+
7782
// Push pushes the data to the internal channel
7883
func (p *WorkerPool) Push(data Data) {
7984
atomic.AddInt64(&p.numInQueue, 1)

modules/secret/secret.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,8 @@ import (
1313
"encoding/hex"
1414
"errors"
1515
"io"
16-
17-
"code.gitea.io/gitea/modules/util"
1816
)
1917

20-
// New creates a new secret
21-
func New() (string, error) {
22-
return NewWithLength(44)
23-
}
24-
25-
// NewWithLength creates a new secret for a given length
26-
func NewWithLength(length int64) (string, error) {
27-
return util.CryptoRandomString(length)
28-
}
29-
3018
// AesEncrypt encrypts text and given key with AES.
3119
func AesEncrypt(key, text []byte) ([]byte, error) {
3220
block, err := aes.NewCipher(key)

modules/secret/secret_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13-
func TestNew(t *testing.T) {
14-
result, err := New()
15-
assert.NoError(t, err)
16-
assert.True(t, len(result) == 44)
17-
18-
result2, err := New()
19-
assert.NoError(t, err)
20-
// check if secrets
21-
assert.NotEqual(t, result, result2)
22-
}
23-
2413
func TestEncryptDecrypt(t *testing.T) {
2514
var hex string
2615
var str string

routers/web/repo/compare.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,15 @@ func ExcerptBlob(ctx *context.Context) {
787787
direction := ctx.FormString("direction")
788788
filePath := ctx.FormString("path")
789789
gitRepo := ctx.Repo.GitRepo
790+
if ctx.FormBool("wiki") {
791+
var err error
792+
gitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath())
793+
if err != nil {
794+
ctx.ServerError("OpenRepository", err)
795+
return
796+
}
797+
defer gitRepo.Close()
798+
}
790799
chunkSize := gitdiff.BlobExcerptChunkSize
791800
commit, err := gitRepo.GetCommit(commitID)
792801
if err != nil {

routers/web/web.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package web
66

77
import (
8+
gocontext "context"
89
"net/http"
910
"os"
1011
"path"
@@ -956,7 +957,25 @@ func RegisterRoutes(m *web.Route) {
956957

957958
m.Group("/blob_excerpt", func() {
958959
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
959-
}, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader)
960+
}, func(ctx *context.Context) (cancel gocontext.CancelFunc) {
961+
if ctx.FormBool("wiki") {
962+
ctx.Data["PageIsWiki"] = true
963+
repo.MustEnableWiki(ctx)
964+
return
965+
}
966+
967+
reqRepoCodeReader(ctx)
968+
if ctx.Written() {
969+
return
970+
}
971+
cancel = context.RepoRef()(ctx)
972+
if ctx.Written() {
973+
return
974+
}
975+
976+
repo.MustBeNotEmpty(ctx)
977+
return
978+
})
960979

961980
m.Group("/pulls/{index}", func() {
962981
m.Get(".diff", repo.DownloadPullDiff)

templates/repo/diff/blob_excerpt.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
{{if eq .GetType 4}}
55
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}">
66
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }}
7-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down" data-anchor="{{$.Anchor}}">
7+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
88
{{svg "octicon-fold-down"}}
99
</a>
1010
{{end}}
1111
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }}
12-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up" data-anchor="{{$.Anchor}}">
12+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
1313
{{svg "octicon-fold-up"}}
1414
</a>
1515
{{end}}
1616
{{if eq $line.GetExpandDirection 2}}
17-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=" data-anchor="{{$.Anchor}}">
17+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
1818
{{svg "octicon-fold"}}
1919
</a>
2020
{{end}}
@@ -43,17 +43,17 @@
4343
{{if eq .GetType 4}}
4444
<td colspan="2" class="lines-num">
4545
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }}
46-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=down" data-anchor="{{$.Anchor}}">
46+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
4747
{{svg "octicon-fold-down"}}
4848
</a>
4949
{{end}}
5050
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }}
51-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=up" data-anchor="{{$.Anchor}}">
51+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
5252
{{svg "octicon-fold-up"}}
5353
</a>
5454
{{end}}
5555
{{if eq $line.GetExpandDirection 2}}
56-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=" data-anchor="{{$.Anchor}}">
56+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}" data-anchor="{{$.Anchor}}">
5757
{{svg "octicon-fold"}}
5858
</a>
5959
{{end}}

templates/repo/diff/section_split.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
{{if eq .GetType 4}}
88
<td class="lines-num lines-num-old">
99
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }}
10-
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
10+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
1111
{{svg "octicon-fold-down"}}
1212
</a>
1313
{{end}}
1414
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }}
15-
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
15+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
1616
{{svg "octicon-fold-up"}}
1717
</a>
1818
{{end}}
1919
{{if eq $line.GetExpandDirection 2}}
20-
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
20+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
2121
{{svg "octicon-fold"}}
2222
</a>
2323
{{end}}

templates/repo/diff/section_unified.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
{{if eq .GetType 4}}
77
<td colspan="2" class="lines-num">
88
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }}
9-
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=down" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
9+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
1010
{{svg "octicon-fold-down"}}
1111
</a>
1212
{{end}}
1313
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }}
14-
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=up" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
14+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
1515
{{svg "octicon-fold-up"}}
1616
</a>
1717
{{end}}
1818
{{if eq $line.GetExpandDirection 2}}
19-
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
19+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
2020
{{svg "octicon-fold"}}
2121
</a>
2222
{{end}}

web_src/less/_repository.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
// otherwise some part of the popup will be hidden by viewport boundary
55
max-height: 45vh;
66
max-width: 60vw;
7+
8+
&.ui.right {
9+
// Override `.ui.attached.header .right:not(.dropdown) height: 30px;` which would otherwise lead to
10+
// the status popup box having its height fixed at 30px. See https://github.com/go-gitea/gitea/issues/18498
11+
height: auto;
12+
}
13+
714
overflow: auto;
815
padding: 0;
916

0 commit comments

Comments
 (0)