@cryptotaxi247 / kubo / commits / e671ab2f4

Swap all 'crypto/rand' rng in tests with 'math/rand'

rht committed Jun 3, 2015 at 18:12 UTC e671ab2f42dd61d79bd3beb3f9c182ade7960448
7 files changed +12 -14
fuse/ipns/ipns_test.go
+2 -2
@@ -4,7 +4,6 @@ package ipns
4
5 import (
6 "bytes"
7 - "crypto/rand"
7 "fmt"
8 "io/ioutil"
9 mrand "math/rand"
@@ -19,6 +18,7 @@ import (
18 core "github.com/ipfs/go-ipfs/core"
19 coremock "github.com/ipfs/go-ipfs/core/mock"
20 nsfs "github.com/ipfs/go-ipfs/ipnsfs"
21 + u "github.com/ipfs/go-ipfs/util"
22 ci "github.com/ipfs/go-ipfs/util/testutil/ci"
23 )
24
@@ -30,7 +30,7 @@ func maybeSkipFuseTests(t *testing.T) {
30
31 func randBytes(size int) []byte {
32 b := make([]byte, size)
33 - rand.Read(b)
33 + u.NewTimeSeededRand().Read(b)
34 return b
35 }
36
importer/balanced/balanced_test.go
+1 -2
@@ -2,7 +2,6 @@ package balanced
2
3 import (
4 "bytes"
5 - "crypto/rand"
5 "fmt"
6 "io"
7 "io/ioutil"
@@ -130,7 +129,7 @@ func TestRabinBlockSize(t *testing.T) {
129 }
130 buf := new(bytes.Buffer)
131 nbytes := 1024 * 1024
133 - io.CopyN(buf, rand.Reader, int64(nbytes))
132 + io.CopyN(buf, u.NewTimeSeededRand(), int64(nbytes))
133 rab := chunk.NewMaybeRabin(4096)
134 blkch := rab.Split(buf)
135
importer/chunk/splitting_test.go
+3 -2
@@ -2,14 +2,15 @@ package chunk
2
3 import (
4 "bytes"
5 - "crypto/rand"
5 "io"
6 "testing"
7 +
8 + u "github.com/ipfs/go-ipfs/util"
9 )
10
11 func randBuf(t *testing.T, size int) []byte {
12 buf := make([]byte, size)
12 - if _, err := rand.Read(buf); err != nil {
13 + if _, err := u.NewTimeSeededRand().Read(buf); err != nil {
14 t.Fatal("failed to read enough randomness")
15 }
16 return buf
importer/trickle/trickle_test.go
+1 -2
@@ -2,7 +2,6 @@ package trickle
2
3 import (
4 "bytes"
5 - "crypto/rand"
5 "fmt"
6 "io"
7 "io/ioutil"
@@ -136,7 +135,7 @@ func TestRabinBlockSize(t *testing.T) {
135 }
136 buf := new(bytes.Buffer)
137 nbytes := 1024 * 1024
139 - io.CopyN(buf, rand.Reader, int64(nbytes))
138 + io.CopyN(buf, u.NewTimeSeededRand(), int64(nbytes))
139 rab := chunk.NewMaybeRabin(4096)
140 blkch := rab.Split(buf)
141
p2p/test/backpressure/backpressure_test.go
+2 -2
@@ -1,7 +1,6 @@
1 package backpressure_tests
2
3 import (
4 - crand "crypto/rand"
4 "io"
5 "math/rand"
6 "testing"
@@ -15,6 +14,7 @@ import (
14 eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
15
16 context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
17 + u "github.com/ipfs/go-ipfs/util"
18 )
19
20 var log = eventlog.Logger("backpressure")
@@ -236,7 +236,7 @@ func TestStBackpressureStreamWrite(t *testing.T) {
236
237 // ready a buffer of random data
238 buf := make([]byte, 65536)
239 - crand.Read(buf)
239 + u.NewTimeSeededRand().Read(buf)
240
241 for {
242 // send a randomly sized subchunk
p2p/test/reconnects/reconnect_test.go
+2 -2
@@ -1,7 +1,6 @@
1 package reconnect
2
3 import (
4 - crand "crypto/rand"
4 "io"
5 "math/rand"
6 "sync"
@@ -14,6 +13,7 @@ import (
13 protocol "github.com/ipfs/go-ipfs/p2p/protocol"
14 testutil "github.com/ipfs/go-ipfs/p2p/test/util"
15 eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
16 + u "github.com/ipfs/go-ipfs/util"
17
18 ps "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
19 context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
@@ -66,7 +66,7 @@ func newSender() (chan sendChans, func(s inet.Stream)) {
66
67 buf := make([]byte, 65536)
68 buf2 := make([]byte, 65536)
69 - crand.Read(buf)
69 + u.NewTimeSeededRand().Read(buf)
70
71 for {
72 select {
util/testutil/gen.go
+1 -2
@@ -2,7 +2,6 @@ package testutil
2
3 import (
4 "bytes"
5 - crand "crypto/rand"
5 "errors"
6 "fmt"
7 "io"
@@ -44,7 +43,7 @@ func SeededTestKeyPair(seed int64) (ci.PrivKey, ci.PubKey, error) {
43 // id, _ := peer.IDFromPublicKey(pk)
44 func RandPeerID() (peer.ID, error) {
45 buf := make([]byte, 16)
47 - if _, err := io.ReadFull(crand.Reader, buf); err != nil {
46 + if _, err := io.ReadFull(u.NewTimeSeededRand(), buf); err != nil {
47 return "", err
48 }
49 h := u.Hash(buf)