diff --git a/proxy/socks/protocol/socks_test.go b/proxy/socks/protocol/socks_test.go index 4bce563e..d501dc19 100644 --- a/proxy/socks/protocol/socks_test.go +++ b/proxy/socks/protocol/socks_test.go @@ -2,10 +2,12 @@ package protocol import ( "bytes" + "io" "testing" "github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/testing/unit" + "github.com/v2ray/v2ray-core/transport" ) func TestHasAuthenticationMethod(t *testing.T) { @@ -94,3 +96,17 @@ func TestResponseWrite(t *testing.T) { } assert.Bytes(buffer.Value).Named("raw response").Equals(expectedBytes) } + +func TestEOF(t *testing.T) { + assert := unit.Assert(t) + + _, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 0))) + assert.Error(err).Equals(io.EOF) +} + +func TestSignleByte(t *testing.T) { + assert := unit.Assert(t) + + _, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1))) + assert.Error(err).Equals(transport.CorruptedPacket) +} diff --git a/proxy/vmess/protocol/vmess_test.go b/proxy/vmess/protocol/vmess_test.go index 0fe691fc..72d39233 100644 --- a/proxy/vmess/protocol/vmess_test.go +++ b/proxy/vmess/protocol/vmess_test.go @@ -3,6 +3,7 @@ package protocol import ( "bytes" "crypto/rand" + "io" "testing" v2net "github.com/v2ray/v2ray-core/common/net" @@ -79,6 +80,14 @@ func TestVMessSerialization(t *testing.T) { assert.String(actualRequest.Address.String()).Named("Address").Equals(request.Address.String()) } +func TestReadSingleByte(t *testing.T) { + assert := unit.Assert(t) + + reader := NewVMessRequestReader(nil) + _, err := reader.Read(bytes.NewReader(make([]byte, 1))) + assert.Error(err).Equals(io.EOF) +} + func BenchmarkVMessRequestWriting(b *testing.B) { userId, _ := config.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51") userSet := mocks.MockUserSet{[]config.User{}, make(map[string]int), make(map[string]int64)}