diff --git a/proxy/socks/protocol/socks_fuzz_test.go b/proxy/socks/protocol/socks_fuzz_test.go index d8ed17686..05c27e1c2 100644 --- a/proxy/socks/protocol/socks_fuzz_test.go +++ b/proxy/socks/protocol/socks_fuzz_test.go @@ -1,8 +1,9 @@ package protocol import ( - "crypto/rand" "testing" + + "github.com/v2ray/v2ray-core/testing/fuzzing" ) const ( @@ -11,18 +12,18 @@ const ( func TestReadAuthentication(t *testing.T) { for i := 0; i < Iterations; i++ { - ReadAuthentication(rand.Reader) + ReadAuthentication(fuzzing.RandomReader()) } } func TestReadUserPassRequest(t *testing.T) { for i := 0; i < Iterations; i++ { - ReadUserPassRequest(rand.Reader) + ReadUserPassRequest(fuzzing.RandomReader()) } } func TestReadRequest(t *testing.T) { for i := 0; i < Iterations; i++ { - ReadRequest(rand.Reader) + ReadRequest(fuzzing.RandomReader()) } } diff --git a/proxy/vmess/protocol/vmess_fuzz_test.go b/proxy/vmess/protocol/vmess_fuzz_test.go index 83bb086b5..2a4688138 100644 --- a/proxy/vmess/protocol/vmess_fuzz_test.go +++ b/proxy/vmess/protocol/vmess_fuzz_test.go @@ -1,15 +1,15 @@ package protocol import ( - "crypto/rand" "testing" "github.com/v2ray/v2ray-core/proxy/vmess/protocol/user/testing/mocks" + "github.com/v2ray/v2ray-core/testing/fuzzing" ) func TestVMessRequestReader(t *testing.T) { reader := NewVMessRequestReader(&mocks.StaticUserSet{}) for i := 0; i < 10000000; i++ { - reader.Read(rand.Reader) + reader.Read(fuzzing.RandomReader()) } } diff --git a/testing/fuzzing/fuzzing.go b/testing/fuzzing/fuzzing.go new file mode 100644 index 000000000..64d71dcde --- /dev/null +++ b/testing/fuzzing/fuzzing.go @@ -0,0 +1,17 @@ +package fuzzing + +import ( + "bytes" + "crypto/rand" + "io" +) + +func RandomBytes() []byte { + buffer := make([]byte, 256) + rand.Read(buffer) + return buffer[1 : 1+int(buffer[0])] +} + +func RandomReader() io.Reader { + return bytes.NewReader(RandomBytes()) +}