Skip to content

Commit 207adbe

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Use `ProtonMail/go-crypto` for `opengpg` in tests (go-gitea#30736) Replace deprecated `math/rand` functions (go-gitea#30733)
2 parents 289aed7 + 8b8b48e commit 207adbe

File tree

6 files changed

+13
-19
lines changed

6 files changed

+13
-19
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4
1717
github.com/42wim/sshsig v0.0.0-20211121163825-841cf5bbc121
1818
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358
19+
github.com/ProtonMail/go-crypto v1.0.0
1920
github.com/PuerkitoBio/goquery v1.9.1
2021
github.com/alecthomas/chroma/v2 v2.13.0
2122
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb
@@ -135,7 +136,6 @@ require (
135136
github.com/Masterminds/semver/v3 v3.2.1 // indirect
136137
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
137138
github.com/Microsoft/go-winio v0.6.1 // indirect
138-
github.com/ProtonMail/go-crypto v1.0.0 // indirect
139139
github.com/RoaringBitmap/roaring v1.9.0 // indirect
140140
github.com/andybalholm/brotli v1.1.0 // indirect
141141
github.com/andybalholm/cascadia v1.3.2 // indirect

models/user/user_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ package user_test
55

66
import (
77
"context"
8+
"crypto/rand"
89
"fmt"
9-
"math/rand"
1010
"strings"
1111
"testing"
1212
"time"

modules/auth/password/pwn/pwn_test.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
package pwn
55

66
import (
7-
"math/rand"
7+
"math/rand/v2"
88
"net/http"
9-
"os"
109
"strings"
1110
"testing"
1211
"time"
@@ -18,11 +17,6 @@ var client = New(WithHTTP(&http.Client{
1817
Timeout: time.Second * 2,
1918
}))
2019

21-
func TestMain(m *testing.M) {
22-
rand.Seed(time.Now().Unix())
23-
os.Exit(m.Run())
24-
}
25-
2620
func TestPassword(t *testing.T) {
2721
// Check input error
2822
_, err := client.CheckPassword("", false)
@@ -81,24 +75,24 @@ func testPassword() string {
8175

8276
// Set special character
8377
for i := 0; i < 5; i++ {
84-
random := rand.Intn(len(specialCharSet))
78+
random := rand.IntN(len(specialCharSet))
8579
password.WriteString(string(specialCharSet[random]))
8680
}
8781

8882
// Set numeric
8983
for i := 0; i < 5; i++ {
90-
random := rand.Intn(len(numberSet))
84+
random := rand.IntN(len(numberSet))
9185
password.WriteString(string(numberSet[random]))
9286
}
9387

9488
// Set uppercase
9589
for i := 0; i < 5; i++ {
96-
random := rand.Intn(len(upperCharSet))
90+
random := rand.IntN(len(upperCharSet))
9791
password.WriteString(string(upperCharSet[random]))
9892
}
9993

10094
for i := 0; i < 5; i++ {
101-
random := rand.Intn(len(allCharSet))
95+
random := rand.IntN(len(allCharSet))
10296
password.WriteString(string(allCharSet[random]))
10397
}
10498
inRune := []rune(password.String())

tests/integration/benchmarks_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package integration
55

66
import (
7-
"math/rand"
7+
"math/rand/v2"
88
"net/http"
99
"net/url"
1010
"testing"
@@ -18,7 +18,7 @@ import (
1818
func StringWithCharset(length int, charset string) string {
1919
b := make([]byte, length)
2020
for i := range b {
21-
b[i] = charset[rand.Intn(len(charset))]
21+
b[i] = charset[rand.IntN(len(charset))]
2222
}
2323
return string(b)
2424
}
@@ -37,7 +37,7 @@ func BenchmarkRepoBranchCommit(b *testing.B) {
3737
b.ResetTimer()
3838
b.Run("CreateBranch", func(b *testing.B) {
3939
b.StopTimer()
40-
branchName := StringWithCharset(5+rand.Intn(10), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
40+
branchName := StringWithCharset(5+rand.IntN(10), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
4141
b.StartTimer()
4242
for i := 0; i < b.N; i++ {
4343
b.Run("new_"+branchName, func(b *testing.B) {

tests/integration/git_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ package integration
55

66
import (
77
"bytes"
8+
"crypto/rand"
89
"encoding/hex"
910
"fmt"
10-
"math/rand"
1111
"net/http"
1212
"net/url"
1313
"os"

tests/integration/gpg_git_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import (
1919
"code.gitea.io/gitea/modules/test"
2020
"code.gitea.io/gitea/tests"
2121

22+
"github.com/ProtonMail/go-crypto/openpgp"
23+
"github.com/ProtonMail/go-crypto/openpgp/armor"
2224
"github.com/stretchr/testify/assert"
23-
"golang.org/x/crypto/openpgp"
24-
"golang.org/x/crypto/openpgp/armor"
2525
)
2626

2727
func TestGPGGit(t *testing.T) {

0 commit comments

Comments
 (0)