浏览代码

fuzzing test for vmess protocol

V2Ray 10 年之前
父节点
当前提交
2a6f4740c1
共有 2 个文件被更改,包括 44 次插入0 次删除
  1. 29 0
      proxy/vmess/protocol/user/testing/mocks/static_userset.go
  2. 15 0
      proxy/vmess/protocol/vmess_fuzz_test.go

+ 29 - 0
proxy/vmess/protocol/user/testing/mocks/static_userset.go

@@ -0,0 +1,29 @@
+package mocks
+
+import (
+	"github.com/v2ray/v2ray-core/proxy/vmess/config"
+)
+
+type StaticUser struct {
+	id *config.ID
+}
+
+func (this *StaticUser) ID() *config.ID {
+	return this.id
+}
+
+func (this *StaticUser) Level() config.UserLevel {
+	return config.UserLevelUntrusted
+}
+
+type StaticUserSet struct {
+}
+
+func (us *StaticUserSet) AddUser(user config.User) error {
+	return nil
+}
+
+func (us *StaticUserSet) GetUser(userhash []byte) (config.User, int64, bool) {
+	id, _ := config.NewID("703e9102-eb57-499c-8b59-faf4f371bb21")
+	return &StaticUser{id: id}, 0, true
+}

+ 15 - 0
proxy/vmess/protocol/vmess_fuzz_test.go

@@ -0,0 +1,15 @@
+package protocol
+
+import (
+	"crypto/rand"
+	"testing"
+
+	"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user/testing/mocks"
+)
+
+func TestVMessRequestReader(t *testing.T) {
+	reader := NewVMessRequestReader(&mocks.StaticUserSet{})
+	for i := 0; i < 10000000; i++ {
+		reader.Read(rand.Reader)
+	}
+}