Skip to content

Commit eb2f836

Browse files
committed
Replaced math/rand with crypto/rand as gosec suggests
1 parent 164decb commit eb2f836

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

driver/inmemory/internal/generate_matcher/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func isSupportedOperator(value interface{}, operator metadata.Operator) bool {
5252
switch operator {
5353
case metadata.Equals,
5454
metadata.NotEquals:
55-
switch value.(type) {
55+
switch value.(type) {
5656
{{- range $i, $e := .Types }}
5757
{{- if eq $i 0 }}
5858
case {{ $e }},
@@ -195,7 +195,7 @@ func main() {
195195
panic(err)
196196
}
197197

198-
/* #nosec G302 */
198+
/* #nosec */
199199
f, err := os.OpenFile(matcherPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
200200
if err != nil {
201201
panic(err)

test/eventstore_integration_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ package test_test
44

55
import (
66
"context"
7-
"math/rand"
7+
"crypto/rand"
8+
"math/big"
89
"testing"
910
"time"
1011

12+
"github.com/stretchr/testify/suite"
13+
1114
"github.com/hellofresh/goengine"
1215
"github.com/hellofresh/goengine/driver/sql/postgres"
1316
"github.com/hellofresh/goengine/metadata"
@@ -16,7 +19,6 @@ import (
1619
strategySQL "github.com/hellofresh/goengine/strategy/json/sql"
1720
strategyPostgres "github.com/hellofresh/goengine/strategy/json/sql/postgres"
1821
"github.com/hellofresh/goengine/test/internal"
19-
"github.com/stretchr/testify/suite"
2022
)
2123

2224
type (
@@ -342,14 +344,18 @@ func (s *eventStoreTestSuite) generateAppendMessages(aggregateIDs []goengine.UUI
342344
if i > 2 {
343345
boolVal = false
344346
}
347+
348+
randInt, err := rand.Int(rand.Reader, big.NewInt(100))
349+
s.Require().NoError(err)
350+
345351
meta := s.appendMeta(map[string]interface{}{
346352
"_aggregate_version": i + 1,
347353
"_aggregate_version_less_then_4": boolVal,
348354
"_aggregate_type": "basic",
349355
"_aggregate_id": aggregateID.String(),
350-
"_float_val": float64(i) + float64(3.12),
351-
"rand_int": rand.Intn(100),
352-
"rand_float_32": rand.Float32(),
356+
"_float_val": float64(i) + 3.12,
357+
"rand_int": randInt.Int64(),
358+
"rand_float_32": float32(randInt.Int64() / 100),
353359
"';''; DROP DATABASE events_orders_load;": "ok",
354360
})
355361
payload := &payloadData{Name: "alice", Balance: i * 11}

0 commit comments

Comments
 (0)