aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorChongyi Zheng <git@zcy.dev>2024-04-27 12:50:35 -0400
committerGitHub <noreply@github.com>2024-04-27 18:50:35 +0200
commit7b8e418da1e082786b844562a05864ec1177ce97 (patch)
treec42f1034b7ae6a48421f7ddd19a534ab1e7031e6 /modules
parent8de2992ffba8cc627757ecea1e002a55581113d2 (diff)
downloadgitea-1.23.0-dev.tar.gz
gitea-1.23.0-dev.zip
Replace deprecated `math/rand` functions (#30733)v1.23.0-dev
Suggested by logs in #30729 - Remove `math/rand.Seed` `rand.Seed is deprecated: As of Go 1.20 there is no reason to call Seed with a random value.` - Replace `math/rand.Read` `rand.Read is deprecated: For almost all use cases, [crypto/rand.Read] is more appropriate.` - Replace `math/rand` with `math/rand/v2`, which is available since Go 1.22
Diffstat (limited to 'modules')
-rw-r--r--modules/auth/password/pwn/pwn_test.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/modules/auth/password/pwn/pwn_test.go b/modules/auth/password/pwn/pwn_test.go
index f9deadc8d7..a2a6b3a174 100644
--- a/modules/auth/password/pwn/pwn_test.go
+++ b/modules/auth/password/pwn/pwn_test.go
@@ -4,9 +4,8 @@
package pwn
import (
- "math/rand"
+ "math/rand/v2"
"net/http"
- "os"
"strings"
"testing"
"time"
@@ -18,11 +17,6 @@ var client = New(WithHTTP(&http.Client{
Timeout: time.Second * 2,
}))
-func TestMain(m *testing.M) {
- rand.Seed(time.Now().Unix())
- os.Exit(m.Run())
-}
-
func TestPassword(t *testing.T) {
// Check input error
_, err := client.CheckPassword("", false)
@@ -81,24 +75,24 @@ func testPassword() string {
// Set special character
for i := 0; i < 5; i++ {
- random := rand.Intn(len(specialCharSet))
+ random := rand.IntN(len(specialCharSet))
password.WriteString(string(specialCharSet[random]))
}
// Set numeric
for i := 0; i < 5; i++ {
- random := rand.Intn(len(numberSet))
+ random := rand.IntN(len(numberSet))
password.WriteString(string(numberSet[random]))
}
// Set uppercase
for i := 0; i < 5; i++ {
- random := rand.Intn(len(upperCharSet))
+ random := rand.IntN(len(upperCharSet))
password.WriteString(string(upperCharSet[random]))
}
for i := 0; i < 5; i++ {
- random := rand.Intn(len(allCharSet))
+ random := rand.IntN(len(allCharSet))
password.WriteString(string(allCharSet[random]))
}
inRune := []rune(password.String())