mirror of https://github.com/v2ray/v2ray-core
Smarter reader generator
parent
2a6f4740c1
commit
bd48556b98
|
@ -1,8 +1,9 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/v2ray/v2ray-core/testing/fuzzing"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -11,18 +12,18 @@ const (
|
||||||
|
|
||||||
func TestReadAuthentication(t *testing.T) {
|
func TestReadAuthentication(t *testing.T) {
|
||||||
for i := 0; i < Iterations; i++ {
|
for i := 0; i < Iterations; i++ {
|
||||||
ReadAuthentication(rand.Reader)
|
ReadAuthentication(fuzzing.RandomReader())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadUserPassRequest(t *testing.T) {
|
func TestReadUserPassRequest(t *testing.T) {
|
||||||
for i := 0; i < Iterations; i++ {
|
for i := 0; i < Iterations; i++ {
|
||||||
ReadUserPassRequest(rand.Reader)
|
ReadUserPassRequest(fuzzing.RandomReader())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadRequest(t *testing.T) {
|
func TestReadRequest(t *testing.T) {
|
||||||
for i := 0; i < Iterations; i++ {
|
for i := 0; i < Iterations; i++ {
|
||||||
ReadRequest(rand.Reader)
|
ReadRequest(fuzzing.RandomReader())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user/testing/mocks"
|
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user/testing/mocks"
|
||||||
|
"github.com/v2ray/v2ray-core/testing/fuzzing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVMessRequestReader(t *testing.T) {
|
func TestVMessRequestReader(t *testing.T) {
|
||||||
reader := NewVMessRequestReader(&mocks.StaticUserSet{})
|
reader := NewVMessRequestReader(&mocks.StaticUserSet{})
|
||||||
for i := 0; i < 10000000; i++ {
|
for i := 0; i < 10000000; i++ {
|
||||||
reader.Read(rand.Reader)
|
reader.Read(fuzzing.RandomReader())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())
|
||||||
|
}
|
Loading…
Reference in New Issue