mirror of
https://github.com/v2fly/v2ray-core
synced 2024-02-27 03:18:06 +00:00
simplify testing
This commit is contained in:
@@ -12,14 +12,13 @@ import (
|
||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||
. "github.com/v2ray/v2ray-core/proxy/dokodemo"
|
||||
"github.com/v2ray/v2ray-core/proxy/freedom"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
||||
"github.com/v2ray/v2ray-core/testing/servers/udp"
|
||||
)
|
||||
|
||||
func TestDokodemoTCP(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
tcpServer := &tcp.Server{
|
||||
Port: v2nettesting.PickPort(),
|
||||
@@ -73,11 +72,11 @@ func TestDokodemoTCP(t *testing.T) {
|
||||
assert.Error(err).IsNil()
|
||||
tcpClient.Close()
|
||||
|
||||
assert.StringLiteral("Processed: " + data2Send).Equals(string(response[:nBytes]))
|
||||
assert.String("Processed: " + data2Send).Equals(string(response[:nBytes]))
|
||||
}
|
||||
|
||||
func TestDokodemoUDP(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
udpServer := &udp.Server{
|
||||
Port: v2nettesting.PickPort(),
|
||||
|
||||
@@ -15,14 +15,13 @@ import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||
. "github.com/v2ray/v2ray-core/proxy/freedom"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
"github.com/v2ray/v2ray-core/testing/servers/tcp"
|
||||
"github.com/v2ray/v2ray-core/transport/ray"
|
||||
)
|
||||
|
||||
func TestSinglePacket(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
port := v2nettesting.PickPort()
|
||||
|
||||
tcpServer := &tcp.Server{
|
||||
@@ -56,7 +55,7 @@ func TestSinglePacket(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnreachableDestination(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
freedom := NewFreedomConnection(&Config{}, app.NewSpace())
|
||||
traffic := ray.NewRay()
|
||||
@@ -68,7 +67,7 @@ func TestUnreachableDestination(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIPResolution(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
space := app.NewSpace()
|
||||
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
|
||||
|
||||
@@ -8,12 +8,11 @@ import (
|
||||
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
. "github.com/v2ray/v2ray-core/proxy/http"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestOwnHosts(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
rawJson := `{
|
||||
"ownHosts": [
|
||||
|
||||
+12
-13
@@ -9,12 +9,11 @@ import (
|
||||
testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing"
|
||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||
. "github.com/v2ray/v2ray-core/proxy/http"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestHopByHopHeadersStrip(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
rawRequest := `GET /pkg/net/http/ HTTP/1.1
|
||||
Host: golang.org
|
||||
@@ -33,22 +32,22 @@ Accept-Language: de,en;q=0.7,en-us;q=0.3
|
||||
b := bufio.NewReader(strings.NewReader(rawRequest))
|
||||
req, err := http.ReadRequest(b)
|
||||
assert.Error(err).IsNil()
|
||||
assert.StringLiteral(req.Header.Get("Foo")).Equals("foo")
|
||||
assert.StringLiteral(req.Header.Get("Bar")).Equals("bar")
|
||||
assert.StringLiteral(req.Header.Get("Connection")).Equals("keep-alive,Foo, Bar")
|
||||
assert.StringLiteral(req.Header.Get("Proxy-Connection")).Equals("keep-alive")
|
||||
assert.StringLiteral(req.Header.Get("Proxy-Authenticate")).Equals("abc")
|
||||
assert.String(req.Header.Get("Foo")).Equals("foo")
|
||||
assert.String(req.Header.Get("Bar")).Equals("bar")
|
||||
assert.String(req.Header.Get("Connection")).Equals("keep-alive,Foo, Bar")
|
||||
assert.String(req.Header.Get("Proxy-Connection")).Equals("keep-alive")
|
||||
assert.String(req.Header.Get("Proxy-Authenticate")).Equals("abc")
|
||||
|
||||
StripHopByHopHeaders(req)
|
||||
assert.StringLiteral(req.Header.Get("Connection")).Equals("close")
|
||||
assert.StringLiteral(req.Header.Get("Foo")).Equals("")
|
||||
assert.StringLiteral(req.Header.Get("Bar")).Equals("")
|
||||
assert.StringLiteral(req.Header.Get("Proxy-Connection")).Equals("")
|
||||
assert.StringLiteral(req.Header.Get("Proxy-Authenticate")).Equals("")
|
||||
assert.String(req.Header.Get("Connection")).Equals("close")
|
||||
assert.String(req.Header.Get("Foo")).Equals("")
|
||||
assert.String(req.Header.Get("Bar")).Equals("")
|
||||
assert.String(req.Header.Get("Proxy-Connection")).Equals("")
|
||||
assert.String(req.Header.Get("Proxy-Authenticate")).Equals("")
|
||||
}
|
||||
|
||||
func TestNormalGetRequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)
|
||||
|
||||
|
||||
@@ -3,12 +3,11 @@ package config
|
||||
import (
|
||||
"testing"
|
||||
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestRegisterInboundConfig(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
initializeConfigCache()
|
||||
|
||||
protocol := "test_protocol"
|
||||
@@ -29,7 +28,7 @@ func TestRegisterInboundConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRegisterOutboundConfig(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
initializeConfigCache()
|
||||
|
||||
protocol := "test_protocol"
|
||||
|
||||
@@ -6,12 +6,11 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestConfigParsing(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
rawJson := `{
|
||||
"method": "aes-128-cfb",
|
||||
|
||||
@@ -5,12 +5,11 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
. "github.com/v2ray/v2ray-core/proxy/shadowsocks"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestNormalChunkReading(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewBuffer().Clear().AppendBytes(
|
||||
0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18)
|
||||
|
||||
@@ -7,13 +7,12 @@ import (
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
. "github.com/v2ray/v2ray-core/proxy/shadowsocks"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
"github.com/v2ray/v2ray-core/transport"
|
||||
)
|
||||
|
||||
func TestNormalRequestParsing(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80)
|
||||
@@ -26,7 +25,7 @@ func TestNormalRequestParsing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEmptyPayload(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
_, err := ReadRequest(buffer, nil, false)
|
||||
@@ -34,7 +33,7 @@ func TestEmptyPayload(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSingleBytePayload(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1)
|
||||
_, err := ReadRequest(buffer, nil, false)
|
||||
@@ -42,7 +41,7 @@ func TestSingleBytePayload(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWrongAddressType(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(5)
|
||||
_, err := ReadRequest(buffer, nil, false)
|
||||
@@ -50,7 +49,7 @@ func TestWrongAddressType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInsufficientAddressRequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1)
|
||||
_, err := ReadRequest(buffer, nil, false)
|
||||
@@ -66,7 +65,7 @@ func TestInsufficientAddressRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInsufficientPortRequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1, 2, 3, 4, 5)
|
||||
_, err := ReadRequest(buffer, nil, false)
|
||||
@@ -74,7 +73,7 @@ func TestInsufficientPortRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOTARequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 239, 115, 52, 212, 178, 172, 26, 6, 168, 0)
|
||||
@@ -89,7 +88,7 @@ func TestOTARequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInvalidOTARequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0, 239, 115, 52, 212, 178, 172, 26, 6, 168, 1)
|
||||
@@ -102,7 +101,7 @@ func TestInvalidOTARequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUDPRequestParsing(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80, 1, 2, 3, 4, 5, 6)
|
||||
@@ -116,7 +115,7 @@ func TestUDPRequestParsing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUDPRequestWithOTA(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
buffer.AppendBytes(
|
||||
|
||||
@@ -7,16 +7,15 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/proxy/internal/config"
|
||||
"github.com/v2ray/v2ray-core/proxy/socks"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestDefaultIPAddress(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
socksConfig, err := config.CreateInboundConfig("socks", []byte(`{
|
||||
"auth": "noauth"
|
||||
}`))
|
||||
assert.Error(err).IsNil()
|
||||
assert.String(socksConfig.(*socks.Config).Address).Equals("127.0.0.1")
|
||||
assert.Address(socksConfig.(*socks.Config).Address).EqualsString("127.0.0.1")
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestSocks4AuthenticationRequestRead(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
rawRequest := []byte{
|
||||
0x04, // version
|
||||
@@ -21,14 +20,14 @@ func TestSocks4AuthenticationRequestRead(t *testing.T) {
|
||||
}
|
||||
_, request4, err := ReadAuthentication(bytes.NewReader(rawRequest))
|
||||
assert.Error(err).Equals(Socks4Downgrade)
|
||||
assert.Byte(request4.Version).Named("Version").Equals(0x04)
|
||||
assert.Byte(request4.Command).Named("Command").Equals(0x01)
|
||||
assert.Port(request4.Port).Named("Port").Equals(v2net.Port(53))
|
||||
assert.Bytes(request4.IP[:]).Named("IP").Equals([]byte{0x72, 0x72, 0x72, 0x72})
|
||||
assert.Byte(request4.Version).Equals(0x04)
|
||||
assert.Byte(request4.Command).Equals(0x01)
|
||||
assert.Port(request4.Port).Equals(v2net.Port(53))
|
||||
assert.Bytes(request4.IP[:]).Equals([]byte{0x72, 0x72, 0x72, 0x72})
|
||||
}
|
||||
|
||||
func TestSocks4AuthenticationResponseToBytes(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
response := NewSocks4AuthenticationResponse(byte(0x10), 443, []byte{1, 2, 3, 4})
|
||||
|
||||
|
||||
@@ -8,13 +8,12 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestHasAuthenticationMethod(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
request := Socks5AuthenticationRequest{
|
||||
version: socksVersion,
|
||||
@@ -29,7 +28,7 @@ func TestHasAuthenticationMethod(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthenticationRequestRead(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewBuffer().Clear().AppendBytes(
|
||||
0x05, // version
|
||||
@@ -38,13 +37,13 @@ func TestAuthenticationRequestRead(t *testing.T) {
|
||||
)
|
||||
request, _, err := ReadAuthentication(buffer)
|
||||
assert.Error(err).IsNil()
|
||||
assert.Byte(request.version).Named("Version").Equals(0x05)
|
||||
assert.Byte(request.nMethods).Named("#Methods").Equals(0x01)
|
||||
assert.Byte(request.authMethods[0]).Named("Auth Method").Equals(0x02)
|
||||
assert.Byte(request.version).Equals(0x05)
|
||||
assert.Byte(request.nMethods).Equals(0x01)
|
||||
assert.Byte(request.authMethods[0]).Equals(0x02)
|
||||
}
|
||||
|
||||
func TestAuthenticationResponseWrite(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
response := NewAuthenticationResponse(byte(0x05))
|
||||
|
||||
@@ -54,7 +53,7 @@ func TestAuthenticationResponseWrite(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRequestRead(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
rawRequest := []byte{
|
||||
0x05, // version
|
||||
@@ -66,15 +65,15 @@ func TestRequestRead(t *testing.T) {
|
||||
}
|
||||
request, err := ReadRequest(bytes.NewReader(rawRequest))
|
||||
assert.Error(err).IsNil()
|
||||
assert.Byte(request.Version).Named("Version").Equals(0x05)
|
||||
assert.Byte(request.Command).Named("Command").Equals(0x01)
|
||||
assert.Byte(request.AddrType).Named("Address Type").Equals(0x01)
|
||||
assert.Bytes(request.IPv4[:]).Named("IPv4").Equals([]byte{0x72, 0x72, 0x72, 0x72})
|
||||
assert.Port(request.Port).Named("Port").Equals(v2net.Port(53))
|
||||
assert.Byte(request.Version).Equals(0x05)
|
||||
assert.Byte(request.Command).Equals(0x01)
|
||||
assert.Byte(request.AddrType).Equals(0x01)
|
||||
assert.Bytes(request.IPv4[:]).Equals([]byte{0x72, 0x72, 0x72, 0x72})
|
||||
assert.Port(request.Port).Equals(v2net.Port(53))
|
||||
}
|
||||
|
||||
func TestResponseWrite(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
response := Socks5Response{
|
||||
socksVersion,
|
||||
@@ -97,11 +96,11 @@ func TestResponseWrite(t *testing.T) {
|
||||
0x72, 0x72, 0x72, 0x72,
|
||||
byte(0x00), byte(0x035),
|
||||
}
|
||||
assert.Bytes(buffer.Value).Named("raw response").Equals(expectedBytes)
|
||||
assert.Bytes(buffer.Value).Equals(expectedBytes)
|
||||
}
|
||||
|
||||
func TestSetIPv6(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
response := NewSocks5Response()
|
||||
response.SetIPv6([]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15})
|
||||
@@ -114,7 +113,7 @@ func TestSetIPv6(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetDomain(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
response := NewSocks5Response()
|
||||
response.SetDomain("v2ray.com")
|
||||
@@ -127,28 +126,28 @@ func TestSetDomain(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEmptyAuthRequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
_, _, err := ReadAuthentication(alloc.NewBuffer().Clear())
|
||||
assert.Error(err).Equals(io.EOF)
|
||||
}
|
||||
|
||||
func TestSingleByteAuthRequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
_, _, err := ReadAuthentication(bytes.NewReader(make([]byte, 1)))
|
||||
assert.Error(err).Equals(transport.ErrorCorruptedPacket)
|
||||
}
|
||||
|
||||
func TestZeroAuthenticationMethod(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(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)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewBuffer().Clear().AppendBytes(6, 1, 0)
|
||||
_, _, err := ReadAuthentication(buffer)
|
||||
@@ -156,14 +155,14 @@ func TestWrongProtocolVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEmptyRequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
_, err := ReadRequest(alloc.NewBuffer().Clear())
|
||||
assert.Error(err).Equals(io.EOF)
|
||||
}
|
||||
|
||||
func TestIPv6Request(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(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()
|
||||
|
||||
@@ -4,13 +4,12 @@ import (
|
||||
"testing"
|
||||
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
"github.com/v2ray/v2ray-core/transport"
|
||||
)
|
||||
|
||||
func TestSingleByteUDPRequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
request, err := ReadUDPRequest(make([]byte, 1))
|
||||
if request != nil {
|
||||
@@ -20,7 +19,7 @@ func TestSingleByteUDPRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDomainAddressRequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
payload := make([]byte, 0, 1024)
|
||||
payload = append(payload, 0, 0, 1, AddrTypeDomain, byte(len("v2ray.com")))
|
||||
@@ -32,7 +31,7 @@ func TestDomainAddressRequest(t *testing.T) {
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
assert.Byte(request.Fragment).Equals(1)
|
||||
assert.String(request.Address).Equals("v2ray.com")
|
||||
assert.Address(request.Address).EqualsString("v2ray.com")
|
||||
assert.Port(request.Port).Equals(v2net.Port(80))
|
||||
assert.Bytes(request.Data.Value).Equals([]byte("Actual payload"))
|
||||
}
|
||||
|
||||
@@ -17,12 +17,11 @@ import (
|
||||
proxytesting "github.com/v2ray/v2ray-core/proxy/testing"
|
||||
proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks"
|
||||
"github.com/v2ray/v2ray-core/shell/point"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestSocksTcpConnect(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
port := v2nettesting.PickPort()
|
||||
|
||||
connInput := []byte("The data to be returned to socks server.")
|
||||
@@ -82,11 +81,11 @@ func TestSocksTcpConnect(t *testing.T) {
|
||||
|
||||
assert.Bytes([]byte(data2Send)).Equals(connOutput.Bytes())
|
||||
assert.Bytes(dataReturned).Equals(connInput)
|
||||
assert.StringLiteral(targetServer).Equals(och.Destination.NetAddr())
|
||||
assert.String(targetServer).Equals(och.Destination.NetAddr())
|
||||
}
|
||||
|
||||
func TestSocksTcpConnectWithUserPass(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
port := v2nettesting.PickPort()
|
||||
|
||||
connInput := []byte("The data to be returned to socks server.")
|
||||
@@ -149,11 +148,11 @@ func TestSocksTcpConnectWithUserPass(t *testing.T) {
|
||||
|
||||
assert.Bytes([]byte(data2Send)).Equals(connOutput.Bytes())
|
||||
assert.Bytes(dataReturned).Equals(connInput)
|
||||
assert.StringLiteral(targetServer).Equals(och.Destination.NetAddr())
|
||||
assert.String(targetServer).Equals(och.Destination.NetAddr())
|
||||
}
|
||||
|
||||
func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
port := v2nettesting.PickPort()
|
||||
|
||||
connInput := []byte("The data to be returned to socks server.")
|
||||
@@ -206,7 +205,7 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
port := v2nettesting.PickPort()
|
||||
|
||||
connInput := []byte("The data to be returned to socks server.")
|
||||
|
||||
@@ -3,7 +3,6 @@ package inbound
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
"github.com/v2ray/v2ray-core/common/protocol"
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
)
|
||||
|
||||
func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader) protocol.ResponseCommand {
|
||||
@@ -23,7 +22,7 @@ func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader
|
||||
return &protocol.CommandSwitchAccount{
|
||||
Port: inboundHandler.Port(),
|
||||
ID: user.ID.UUID(),
|
||||
AlterIds: serial.Uint16Literal(len(user.AlterIDs)),
|
||||
AlterIds: uint16(len(user.AlterIDs)),
|
||||
Level: user.Level,
|
||||
ValidMin: byte(availableMin),
|
||||
}
|
||||
|
||||
@@ -9,12 +9,11 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
. "github.com/v2ray/v2ray-core/proxy/vmess/io"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestAuthenticate(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
buffer := alloc.NewBuffer().Clear()
|
||||
buffer.AppendBytes(1, 2, 3, 4)
|
||||
@@ -27,7 +26,7 @@ func TestAuthenticate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSingleIO(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
content := bytes.NewBuffer(make([]byte, 0, 1024*1024))
|
||||
|
||||
@@ -42,7 +41,7 @@ func TestSingleIO(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLargeIO(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
content := make([]byte, 1024*1024)
|
||||
rand.Read(content)
|
||||
|
||||
@@ -35,5 +35,5 @@ func Authenticate(buffer *alloc.Buffer) {
|
||||
buffer.SliceBack(4)
|
||||
fnvHash.Sum(buffer.Value[:0])
|
||||
|
||||
buffer.Prepend(serial.Uint16Literal(uint16(buffer.Len())).Bytes())
|
||||
buffer.Prepend(serial.Uint16ToBytes(uint16(buffer.Len())))
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
|
||||
primary := protocol.NewID(cmd.ID)
|
||||
alters := protocol.NewAlterIDs(primary, cmd.AlterIds.Value())
|
||||
alters := protocol.NewAlterIDs(primary, cmd.AlterIds)
|
||||
user := protocol.NewUser(primary, alters, cmd.Level, "")
|
||||
dest := v2net.TCPDestination(cmd.Host, cmd.Port)
|
||||
this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin)
|
||||
|
||||
@@ -7,12 +7,11 @@ import (
|
||||
"testing"
|
||||
|
||||
. "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestConfigTargetParsing(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
rawJson := `{
|
||||
"address": "127.0.0.1",
|
||||
@@ -29,7 +28,7 @@ func TestConfigTargetParsing(t *testing.T) {
|
||||
receiver := new(Receiver)
|
||||
err := json.Unmarshal([]byte(rawJson), &receiver)
|
||||
assert.Error(err).IsNil()
|
||||
assert.String(receiver.Destination).Equals("tcp:127.0.0.1:80")
|
||||
assert.Destination(receiver.Destination).EqualsString("tcp:127.0.0.1:80")
|
||||
assert.Int(len(receiver.Accounts)).Equals(1)
|
||||
assert.String(receiver.Accounts[0].ID).Equals("e641f5ad-9397-41e3-bf1a-e8740dfed019")
|
||||
assert.String(receiver.Accounts[0].ID.String()).Equals("e641f5ad-9397-41e3-bf1a-e8740dfed019")
|
||||
}
|
||||
|
||||
@@ -7,12 +7,11 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/protocol"
|
||||
"github.com/v2ray/v2ray-core/common/uuid"
|
||||
. "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestReceiverUser(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
id := protocol.NewID(uuid.New())
|
||||
alters := protocol.NewAlterIDs(id, 100)
|
||||
|
||||
@@ -17,12 +17,11 @@ import (
|
||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
|
||||
"github.com/v2ray/v2ray-core/shell/point"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestVMessInAndOut(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
assert := assert.On(t)
|
||||
|
||||
id, err := uuid.ParseString("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
Reference in New Issue
Block a user