From f2cf4a1f8929ef6342e99bc8064693f5bc771696 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Mon, 2 Nov 2015 23:48:47 +0100 Subject: [PATCH] Test case for too-short request --- proxy/socks/protocol/socks_test.go | 16 ++++++++++++++++ proxy/vmess/protocol/vmess_test.go | 9 +++++++++ 2 files changed, 25 insertions(+) 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)}