Skip to content

Commit 38cbf10

Browse files
committed
chore: Remove gosec from test files
1 parent 238c99e commit 38cbf10

28 files changed

Lines changed: 81 additions & 71 deletions

File tree

.gosec-golangci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ linters:
33
default: none
44
enable:
55
- gosec
6+
exclusions:
7+
rules:
8+
# Exclude some linters from running on test files.
9+
# 1. Exclude the top level tests/ directory.
10+
# 2. Exclude any file prefixed with test_ in any directory.
11+
# 3. Exclude any directory suffixed with test.
12+
# 4. Exclude any file suffixed with _test.go.
13+
- path: "(^tests/)|(^(.*/)*test_[^/]*\\.go$)|(.*test/.*)|(.*_test\\.go$)"
14+
linters:
15+
- gosec

chains/atomic/atomictest/shared_memory.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ func TestSharedMemoryPutAndGet(t *testing.T, chainID0, chainID1 ids.ID, sm0, sm1
4646
// can support large values.
4747
func TestSharedMemoryLargePutGetAndRemove(t *testing.T, chainID0, chainID1 ids.ID, sm0, sm1 atomic.SharedMemory, _ database.Database) {
4848
require := require.New(t)
49-
rand := rand.New(rand.NewSource(0)) //#nosec G404
49+
rand := rand.New(rand.NewSource(0))
5050

5151
totalSize := 16 * units.MiB // 16 MiB
5252
elementSize := 4 * units.KiB // 4 KiB
5353
pairSize := 2 * elementSize // 8 KiB
5454

5555
b := make([]byte, totalSize)
56-
_, err := rand.Read(b) // #nosec G404
56+
_, err := rand.Read(b)
5757
require.NoError(err)
5858

5959
elems := []*atomic.Element{}
@@ -152,7 +152,7 @@ func TestSharedMemoryLargeIndexed(t *testing.T, chainID0, chainID1 ids.ID, sm0,
152152
pairSize := 3 * elementSize // 3 KiB
153153

154154
b := make([]byte, totalSize)
155-
_, err := rand.Read(b) // #nosec G404
155+
_, err := rand.Read(b)
156156
require.NoError(err)
157157

158158
elems := []*atomic.Element{}
@@ -307,14 +307,14 @@ func TestPutAndRemoveBatch(t *testing.T, chainID0, _ ids.ID, _, sm1 atomic.Share
307307
// support large batches.
308308
func TestSharedMemoryLargeBatchSize(t *testing.T, _, chainID1 ids.ID, sm0, _ atomic.SharedMemory, db database.Database) {
309309
require := require.New(t)
310-
rand := rand.New(rand.NewSource(0)) //#nosec G404
310+
rand := rand.New(rand.NewSource(0))
311311

312312
totalSize := 8 * units.MiB // 8 MiB
313313
elementSize := 4 * units.KiB // 4 KiB
314314
pairSize := 2 * elementSize // 8 KiB
315315

316316
bytes := make([]byte, totalSize)
317-
_, err := rand.Read(bytes) // #nosec G404
317+
_, err := rand.Read(bytes)
318318
require.NoError(err)
319319

320320
batch := db.NewBatch()

database/dbtest/benchmark.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ func SetupBenchmark(b *testing.B, count int, keySize, valueSize int) ([][]byte,
4646
for i := 0; i < count; i++ {
4747
keyBytes := make([]byte, keySize)
4848
valueBytes := make([]byte, valueSize)
49-
_, err := rand.Read(keyBytes) // #nosec G404
49+
_, err := rand.Read(keyBytes)
5050
require.NoError(err)
51-
_, err = rand.Read(valueBytes) // #nosec G404
51+
_, err = rand.Read(valueBytes)
5252
require.NoError(err)
5353
keys[i], values[i] = keyBytes, valueBytes
5454
}

database/dbtest/dbtest.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,16 +1241,16 @@ func FuzzNewIteratorWithPrefix(f *testing.F, db database.Database) {
12411241
numKeyValues uint,
12421242
) {
12431243
require := require.New(t)
1244-
r := rand.New(rand.NewSource(randSeed)) // #nosec G404
1244+
r := rand.New(rand.NewSource(randSeed))
12451245

12461246
// Put a bunch of key-values
12471247
expected := map[string][]byte{}
12481248
for i := 0; i < int(numKeyValues); i++ {
12491249
key := make([]byte, r.Intn(maxKeyLen))
1250-
_, _ = r.Read(key) // #nosec G404
1250+
_, _ = r.Read(key)
12511251

12521252
value := make([]byte, r.Intn(maxValueLen))
1253-
_, _ = r.Read(value) // #nosec G404
1253+
_, _ = r.Read(value)
12541254

12551255
if len(value) == 0 {
12561256
// Consistently treat zero length values as nil
@@ -1305,17 +1305,17 @@ func FuzzNewIteratorWithStartAndPrefix(f *testing.F, db database.Database) {
13051305
numKeyValues uint,
13061306
) {
13071307
require := require.New(t)
1308-
r := rand.New(rand.NewSource(randSeed)) // #nosec G404
1308+
r := rand.New(rand.NewSource(randSeed))
13091309

13101310
expected := map[string][]byte{}
13111311

13121312
// Put a bunch of key-values
13131313
for i := 0; i < int(numKeyValues); i++ {
13141314
key := make([]byte, r.Intn(maxKeyLen))
1315-
_, _ = r.Read(key) // #nosec G404
1315+
_, _ = r.Read(key)
13161316

13171317
value := make([]byte, r.Intn(maxValueLen))
1318-
_, _ = r.Read(value) // #nosec G404
1318+
_, _ = r.Read(value)
13191319

13201320
if len(value) == 0 {
13211321
// Consistently treat zero length values as nil

ids/bits_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestEqualSubsetBadMiddle(t *testing.T) {
7070
}
7171

7272
func TestEqualSubsetAll3Bytes(t *testing.T) {
73-
seed := rand.Uint64() //#nosec G404
73+
seed := rand.Uint64()
7474
t.Logf("seed: %d", seed)
7575
id1 := ID{}.Prefix(seed)
7676

tests/fixture/bootstrapmonitor/e2e/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func buildImage(tc tests.TestContext, imageName string, forceNewHash bool, scrip
254254
tc.ContextWithTimeout(e2e.DefaultTimeout*2), // Double the timeout to account for CI being really slow
255255
"bash",
256256
args...,
257-
) // #nosec G204
257+
)
258258
cmd.Env = append(os.Environ(),
259259
"DOCKER_IMAGE="+imageName,
260260
"FORCE_TAG_MASTER=1",

tests/fixture/e2e/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork
235235
func (te *TestEnvironment) GetRandomNodeURI() tmpnet.NodeURI {
236236
var (
237237
tc = te.testContext
238-
r = rand.New(rand.NewSource(time.Now().Unix())) //#nosec G404
238+
r = rand.New(rand.NewSource(time.Now().Unix()))
239239
network = te.GetNetwork()
240240
availableNodes = []*tmpnet.Node{}
241241
)

tests/load/tests.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ func NewRandomTest(
7474
// twice is practically zero. Using random values simplifies gas calculations
7575
// as it removes the need to use an SLOAD operation to verify a different
7676
// value is being written.
77-
writeRand = rand.New(rand.NewSource(0)) //#nosec G404
78-
modifyRand = rand.New(rand.NewSource(1)) //#nosec G404
77+
writeRand = rand.New(rand.NewSource(0))
78+
modifyRand = rand.New(rand.NewSource(1))
7979
)
8080

8181
weightedTests := []WeightedTest{
@@ -190,7 +190,7 @@ func NewRandomWeightedTest(
190190
)
191191
}
192192

193-
rand := rand.New(source) //#nosec G404
193+
rand := rand.New(source)
194194

195195
return &RandomWeightedTest{
196196
tests: tests,

utils/bag/bag_benchmark_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func BenchmarkBagListSmall(b *testing.B) {
12-
rand := rand.New(rand.NewSource(1337)) //#nosec G404
12+
rand := rand.New(rand.NewSource(1337))
1313
smallLen := 5
1414
bag := Bag[int]{}
1515
for i := 0; i < smallLen; i++ {
@@ -22,7 +22,7 @@ func BenchmarkBagListSmall(b *testing.B) {
2222
}
2323

2424
func BenchmarkBagListMedium(b *testing.B) {
25-
rand := rand.New(rand.NewSource(1337)) //#nosec G404
25+
rand := rand.New(rand.NewSource(1337))
2626
mediumLen := 25
2727
bag := Bag[int]{}
2828
for i := 0; i < mediumLen; i++ {
@@ -36,7 +36,7 @@ func BenchmarkBagListMedium(b *testing.B) {
3636
}
3737

3838
func BenchmarkBagListLarge(b *testing.B) {
39-
rand := rand.New(rand.NewSource(1337)) //#nosec G404
39+
rand := rand.New(rand.NewSource(1337))
4040
largeLen := 100000
4141
bag := Bag[int]{}
4242
for i := 0; i < largeLen; i++ {

utils/bloom/filter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestNormalUsage(t *testing.T) {
6060

6161
toAdd := make([]uint64, 1024)
6262
for i := range toAdd {
63-
toAdd[i] = rand.Uint64() //#nosec G404
63+
toAdd[i] = rand.Uint64()
6464
}
6565

6666
initialNumHashes, initialNumBytes := OptimalParameters(1024, 0.01)

0 commit comments

Comments
 (0)