mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-03 15:55:20 -05:00
socks4 tests
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
xproxy "golang.org/x/net/proxy"
|
||||
socks4 "h12.me/socks"
|
||||
"v2ray.com/core"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
@@ -203,7 +204,7 @@ func TestSocksBridageUDP(t *testing.T) {
|
||||
CloseAllServers()
|
||||
}
|
||||
|
||||
func TestSocks5conformance(t *testing.T) {
|
||||
func TestSocksConformance(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
tcpServer := tcp.Server{
|
||||
@@ -287,5 +288,39 @@ func TestSocks5conformance(t *testing.T) {
|
||||
assert.Error(conn.Close()).IsNil()
|
||||
}
|
||||
|
||||
{
|
||||
dialer := socks4.DialSocksProxy(socks4.SOCKS4, v2net.TCPDestination(v2net.LocalHostIP, noAuthPort).NetAddr())
|
||||
conn, err := dialer("tcp", dest.NetAddr())
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
payload := "test payload"
|
||||
nBytes, err := conn.Write([]byte(payload))
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(nBytes).Equals(len(payload))
|
||||
|
||||
response := make([]byte, 1024)
|
||||
nBytes, err = conn.Read(response)
|
||||
assert.Error(err).IsNil()
|
||||
assert.Bytes(response[:nBytes]).Equals(xor([]byte(payload)))
|
||||
assert.Error(conn.Close()).IsNil()
|
||||
}
|
||||
|
||||
{
|
||||
dialer := socks4.DialSocksProxy(socks4.SOCKS4A, v2net.TCPDestination(v2net.LocalHostIP, noAuthPort).NetAddr())
|
||||
conn, err := dialer("tcp", v2net.TCPDestination(v2net.LocalHostDomain, tcpServer.Port).NetAddr())
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
payload := "test payload"
|
||||
nBytes, err := conn.Write([]byte(payload))
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(nBytes).Equals(len(payload))
|
||||
|
||||
response := make([]byte, 1024)
|
||||
nBytes, err = conn.Read(response)
|
||||
assert.Error(err).IsNil()
|
||||
assert.Bytes(response[:nBytes]).Equals(xor([]byte(payload)))
|
||||
assert.Error(conn.Close()).IsNil()
|
||||
}
|
||||
|
||||
CloseAllServers()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user