1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

socks4 tests

This commit is contained in:
Darien Raymond 2017-01-08 10:23:55 +01:00
parent ed3033e785
commit 5b89c6aada
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 38 additions and 3 deletions

View File

@ -73,12 +73,12 @@ func (s *ServerSession) Handshake(reader io.Reader, writer io.Writer) (*protocol
request.Address = address
request.Port = port
request.Version = socks4Version
if err := writeSocks4Response(writer, socks4RequestGranted, address, port); err != nil {
if err := writeSocks4Response(writer, socks4RequestGranted, v2net.AnyIP, v2net.Port(0)); err != nil {
return nil, err
}
return request, nil
default:
writeSocks4Response(writer, socks4RequestRejected, address, port)
writeSocks4Response(writer, socks4RequestRejected, v2net.AnyIP, v2net.Port(0))
return nil, errors.New("Socks|Server: Unsupported command: ", buffer.Byte(1))
}
}

View File

@ -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()
}