mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
remove dependency of assert lib
This commit is contained in:
parent
c9958681f7
commit
28189197b3
@ -5,14 +5,12 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
. "v2ray.com/core/proxy/blackhole"
|
||||
. "v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestHTTPResponse(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
buffer := buf.New()
|
||||
|
||||
httpResponse := new(HTTPResponse)
|
||||
@ -20,6 +18,8 @@ func TestHTTPResponse(t *testing.T) {
|
||||
|
||||
reader := bufio.NewReader(buffer)
|
||||
response, err := http.ReadResponse(reader, nil)
|
||||
assert(err, IsNil)
|
||||
assert(response.StatusCode, Equals, 403)
|
||||
common.Must(err)
|
||||
if response.StatusCode != 403 {
|
||||
t.Error("expected status code 403, but got ", response.StatusCode)
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ import (
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
. "v2ray.com/core/proxy/vmess/encoding"
|
||||
. "v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestFnvAuth(t *testing.T) {
|
||||
assert := With(t)
|
||||
fnvAuth := new(FnvAuthenticator)
|
||||
|
||||
expectedText := make([]byte, 256)
|
||||
@ -20,7 +20,8 @@ func TestFnvAuth(t *testing.T) {
|
||||
buffer := make([]byte, 512)
|
||||
b := fnvAuth.Seal(buffer[:0], nil, expectedText, nil)
|
||||
b, err = fnvAuth.Open(buffer[:0], nil, b, nil)
|
||||
assert(err, IsNil)
|
||||
assert(len(b), Equals, 256)
|
||||
assert(b, Equals, expectedText)
|
||||
common.Must(err)
|
||||
if r := cmp.Diff(b, expectedText); r != "" {
|
||||
t.Error(r)
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
_ "v2ray.com/core/app/proxyman/inbound"
|
||||
_ "v2ray.com/core/app/proxyman/outbound"
|
||||
"v2ray.com/core/app/router"
|
||||
"v2ray.com/core/common"
|
||||
clog "v2ray.com/core/common/log"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
@ -107,13 +108,11 @@ func TestPassiveConnection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProxy(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
tcpServer := tcp.Server{
|
||||
MsgProcessor: xor,
|
||||
}
|
||||
dest, err := tcpServer.Start()
|
||||
assert(err, IsNil)
|
||||
common.Must(err)
|
||||
defer tcpServer.Close()
|
||||
|
||||
serverUserID := protocol.NewID(uuid.New())
|
||||
@ -232,26 +231,12 @@ func TestProxy(t *testing.T) {
|
||||
}
|
||||
|
||||
servers, err := InitializeServerConfigs(serverConfig, proxyConfig, clientConfig)
|
||||
assert(err, IsNil)
|
||||
common.Must(err)
|
||||
defer CloseAllServers(servers)
|
||||
|
||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
||||
IP: []byte{127, 0, 0, 1},
|
||||
Port: int(clientPort),
|
||||
})
|
||||
assert(err, IsNil)
|
||||
|
||||
payload := "dokodemo request."
|
||||
nBytes, err := conn.Write([]byte(payload))
|
||||
assert(err, IsNil)
|
||||
assert(nBytes, Equals, len(payload))
|
||||
|
||||
response := make([]byte, 1024)
|
||||
nBytes, err = conn.Read(response)
|
||||
assert(err, IsNil)
|
||||
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
||||
assert(conn.Close(), IsNil)
|
||||
|
||||
CloseAllServers(servers)
|
||||
if err := testTCPConn(clientPort, 1024, time.Second*5)(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyOverKCP(t *testing.T) {
|
||||
|
@ -12,12 +12,9 @@ import (
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
. "v2ray.com/core/transport/internet/domainsocket"
|
||||
. "v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestListen(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
ctx := context.Background()
|
||||
streamSettings := &internet.MemoryStreamConfig{
|
||||
ProtocolName: "domainsocket",
|
||||
@ -29,25 +26,28 @@ func TestListen(t *testing.T) {
|
||||
defer conn.Close()
|
||||
|
||||
b := buf.New()
|
||||
defer b.Release()
|
||||
common.Must2(b.ReadFrom(conn))
|
||||
assert(b.String(), Equals, "Request")
|
||||
b.WriteString("Response")
|
||||
|
||||
common.Must2(conn.Write([]byte("Response")))
|
||||
common.Must2(conn.Write(b.Bytes()))
|
||||
})
|
||||
assert(err, IsNil)
|
||||
common.Must(err)
|
||||
defer listener.Close()
|
||||
|
||||
conn, err := Dial(ctx, net.Destination{}, streamSettings)
|
||||
assert(err, IsNil)
|
||||
common.Must(err)
|
||||
defer conn.Close()
|
||||
|
||||
_, err = conn.Write([]byte("Request"))
|
||||
assert(err, IsNil)
|
||||
common.Must2(conn.Write([]byte("Request")))
|
||||
|
||||
b := buf.New()
|
||||
defer b.Release()
|
||||
common.Must2(b.ReadFrom(conn))
|
||||
|
||||
assert(b.String(), Equals, "Response")
|
||||
if b.String() != "RequestResponse" {
|
||||
t.Error("expected response as 'RequestResponse' but got ", b.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestListenAbstract(t *testing.T) {
|
||||
@ -55,8 +55,6 @@ func TestListenAbstract(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
assert := With(t)
|
||||
|
||||
ctx := context.Background()
|
||||
streamSettings := &internet.MemoryStreamConfig{
|
||||
ProtocolName: "domainsocket",
|
||||
@ -69,23 +67,26 @@ func TestListenAbstract(t *testing.T) {
|
||||
defer conn.Close()
|
||||
|
||||
b := buf.New()
|
||||
defer b.Release()
|
||||
common.Must2(b.ReadFrom(conn))
|
||||
assert(b.String(), Equals, "Request")
|
||||
b.WriteString("Response")
|
||||
|
||||
common.Must2(conn.Write([]byte("Response")))
|
||||
common.Must2(conn.Write(b.Bytes()))
|
||||
})
|
||||
assert(err, IsNil)
|
||||
common.Must(err)
|
||||
defer listener.Close()
|
||||
|
||||
conn, err := Dial(ctx, net.Destination{}, streamSettings)
|
||||
assert(err, IsNil)
|
||||
common.Must(err)
|
||||
defer conn.Close()
|
||||
|
||||
_, err = conn.Write([]byte("Request"))
|
||||
assert(err, IsNil)
|
||||
common.Must2(conn.Write([]byte("Request")))
|
||||
|
||||
b := buf.New()
|
||||
defer b.Release()
|
||||
common.Must2(b.ReadFrom(conn))
|
||||
|
||||
assert(b.String(), Equals, "Response")
|
||||
if b.String() != "RequestResponse" {
|
||||
t.Error("expected response as 'RequestResponse' but got ", b.String())
|
||||
}
|
||||
}
|
||||
|
@ -3,25 +3,47 @@ package internet_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
. "v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/internet/headers/noop"
|
||||
"v2ray.com/core/transport/internet/headers/srtp"
|
||||
"v2ray.com/core/transport/internet/headers/utp"
|
||||
. "v2ray.com/ext/assert"
|
||||
"v2ray.com/core/transport/internet/headers/wechat"
|
||||
"v2ray.com/core/transport/internet/headers/wireguard"
|
||||
)
|
||||
|
||||
func TestAllHeadersLoadable(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
noopAuth, err := CreatePacketHeader((*noop.Config)(nil))
|
||||
assert(err, IsNil)
|
||||
assert(noopAuth.Size(), Equals, int32(0))
|
||||
|
||||
srtp, err := CreatePacketHeader((*srtp.Config)(nil))
|
||||
assert(err, IsNil)
|
||||
assert(srtp.Size(), Equals, int32(4))
|
||||
|
||||
utp, err := CreatePacketHeader((*utp.Config)(nil))
|
||||
assert(err, IsNil)
|
||||
assert(utp.Size(), Equals, int32(4))
|
||||
testCases := []struct {
|
||||
Input interface{}
|
||||
Size int32
|
||||
}{
|
||||
{
|
||||
Input: new(noop.Config),
|
||||
Size: 0,
|
||||
},
|
||||
{
|
||||
Input: new(srtp.Config),
|
||||
Size: 4,
|
||||
},
|
||||
{
|
||||
Input: new(utp.Config),
|
||||
Size: 4,
|
||||
},
|
||||
{
|
||||
Input: new(wechat.VideoConfig),
|
||||
Size: 13,
|
||||
},
|
||||
{
|
||||
Input: new(wireguard.WireguardConfig),
|
||||
Size: 4,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
header, err := CreatePacketHeader(testCase.Input)
|
||||
common.Must(err)
|
||||
if header.Size() != testCase.Size {
|
||||
t.Error("expected size ", testCase.Size, " but got ", header.Size())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user