From 7cc8d90f26c594d18c4d3ca4909d03ddfdf28362 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Tue, 13 Oct 2015 21:55:12 +0200 Subject: [PATCH] test case for wrong auth method --- common/log/access.go | 4 ++-- proxy/socks/socks_test.go | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/common/log/access.go b/common/log/access.go index 6d24ca5b8..10e439608 100644 --- a/common/log/access.go +++ b/common/log/access.go @@ -3,8 +3,8 @@ package log import ( "log" "os" - - "github.com/v2ray/v2ray-core/common/platform" + + "github.com/v2ray/v2ray-core/common/platform" ) // AccessStatus is the status of an access request from clients. diff --git a/proxy/socks/socks_test.go b/proxy/socks/socks_test.go index f38b2087f..3fd27c2b4 100644 --- a/proxy/socks/socks_test.go +++ b/proxy/socks/socks_test.go @@ -171,6 +171,51 @@ func TestSocksTcpConnectWithWrongUserPass(t *testing.T) { assert.Error(err).IsNotNil() } +func TestSocksTcpConnectWithWrongAuthMethod(t *testing.T) { + assert := unit.Assert(t) + port := uint16(38405) + + och := &mocks.OutboundConnectionHandler{ + Data2Send: bytes.NewBuffer(make([]byte, 0, 1024)), + Data2Return: []byte("The data to be returned to socks server."), + } + + core.RegisterOutboundConnectionHandlerFactory("mock_och", och) + + config := mocks.Config{ + PortValue: port, + InboundConfigValue: &mocks.ConnectionConfig{ + ProtocolValue: "socks", + SettingsValue: &json.SocksConfig{ + AuthMethod: "password", + Accounts: []json.SocksAccount{ + json.SocksAccount{ + Username: "userx", + Password: "passy", + }, + }, + }, + }, + OutboundConfigValue: &mocks.ConnectionConfig{ + ProtocolValue: "mock_och", + SettingsValue: nil, + }, + } + + point, err := core.NewPoint(&config) + assert.Error(err).IsNil() + + err = point.Start() + assert.Error(err).IsNil() + + socks5Client, err := proxy.SOCKS5("tcp", "127.0.0.1:38405", nil, proxy.Direct) + assert.Error(err).IsNil() + + targetServer := "1.2.3.4:443" + _, err = socks5Client.Dial("tcp", targetServer) + assert.Error(err).IsNotNil() +} + func TestSocksUdpSend(t *testing.T) { assert := unit.Assert(t) port := uint16(12372)