mirror of https://github.com/v2ray/v2ray-core
				
				
				
			socks4 tests
							parent
							
								
									ed3033e785
								
							
						
					
					
						commit
						5b89c6aada
					
				| 
						 | 
				
			
			@ -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))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue