summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorChongyi Zheng <git@zcy.dev>2024-04-27 18:50:35 +0200
committerEarl Warren <contact@earl-warren.org>2024-04-28 15:39:02 +0200
commit781789e779f6ab8a85db4d5a252f706485ef7824 (patch)
treecd314a1ee8d8243b00b26d7e96f36503de76f3f2 /modules
parentRename migration package name for 1.22-rc1 (#30730) (diff)
downloadforgejo-781789e779f6ab8a85db4d5a252f706485ef7824.tar.xz
forgejo-781789e779f6ab8a85db4d5a252f706485ef7824.zip
Replace deprecated `math/rand` functions (#30733)
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 (cherry picked from commit 7b8e418da1e082786b844562a05864ec1177ce97)
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())