|
|
|
@ -8,6 +8,7 @@ import (
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
|
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
|
v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
|
|
|
|
|
"github.com/v2ray/v2ray-core/proxy"
|
|
|
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
|
|
|
|
"github.com/v2ray/v2ray-core/transport"
|
|
|
|
@ -31,12 +32,12 @@ func TestHasAuthenticationMethod(t *testing.T) {
|
|
|
|
|
func TestAuthenticationRequestRead(t *testing.T) {
|
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
|
|
|
|
|
rawRequest := []byte{
|
|
|
|
|
buffer := alloc.NewBuffer().Clear().AppendBytes(
|
|
|
|
|
0x05, // version
|
|
|
|
|
0x01, // nMethods
|
|
|
|
|
0x02, // methods
|
|
|
|
|
}
|
|
|
|
|
request, _, err := ReadAuthentication(bytes.NewReader(rawRequest))
|
|
|
|
|
)
|
|
|
|
|
request, _, err := ReadAuthentication(buffer)
|
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
assert.Byte(request.version).Named("Version").Equals(0x05)
|
|
|
|
|
assert.Byte(request.nMethods).Named("#Methods").Equals(0x01)
|
|
|
|
@ -126,16 +127,48 @@ func TestSetDomain(t *testing.T) {
|
|
|
|
|
socksVersion, 0, 0, AddrTypeDomain, 9, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEOF(t *testing.T) {
|
|
|
|
|
func TestEmptyAuthRequest(t *testing.T) {
|
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
|
|
|
|
|
_, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 0)))
|
|
|
|
|
_, _, err := ReadAuthentication(alloc.NewBuffer().Clear())
|
|
|
|
|
assert.Error(err).Equals(io.EOF)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSignleByte(t *testing.T) {
|
|
|
|
|
func TestSingleByteAuthRequest(t *testing.T) {
|
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
|
|
|
|
|
_, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1)))
|
|
|
|
|
assert.Error(err).Equals(transport.ErrorCorruptedPacket)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestZeroAuthenticationMethod(t *testing.T) {
|
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
|
|
|
|
|
buffer := alloc.NewBuffer().Clear().AppendBytes(5, 0)
|
|
|
|
|
_, _, err := ReadAuthentication(buffer)
|
|
|
|
|
assert.Error(err).Equals(proxy.ErrorInvalidAuthentication)
|
|
|
|
|
}
|
|
|
|
|
func TestWrongProtocolVersion(t *testing.T) {
|
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
|
|
|
|
|
buffer := alloc.NewBuffer().Clear().AppendBytes(6, 1, 0)
|
|
|
|
|
_, _, err := ReadAuthentication(buffer)
|
|
|
|
|
assert.Error(err).Equals(proxy.ErrorInvalidProtocolVersion)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmptyRequest(t *testing.T) {
|
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
|
|
|
|
|
_, err := ReadRequest(alloc.NewBuffer().Clear())
|
|
|
|
|
assert.Error(err).Equals(io.EOF)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIPv6Request(t *testing.T) {
|
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
|
|
|
|
|
request, err := ReadRequest(alloc.NewBuffer().Clear().AppendBytes(5, 1, 0, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 8))
|
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
assert.Byte(request.Command).Equals(1)
|
|
|
|
|
assert.Bytes(request.IPv6[:]).Equals([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6})
|
|
|
|
|
v2netassert.Port(request.Port).Equals(8)
|
|
|
|
|
}
|
|
|
|
|