clean up errors

This commit is contained in:
Darien Raymond committed 2016-12-09 00:11:05 +01:00
1 parent 41fcffbfab
commit a3cb770f77
5 files changed
+11 -13

No files matched your search

+3 -2
View File
@@ -8,6 +8,7 @@ import (
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/common/crypto"
)
const (
@@ -70,13 +71,13 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut
auth.nMethods = buffer[1]
if auth.nMethods <= 0 {
log.Warning("Socks: Zero length of authentication methods")
err = proxy.ErrInvalidAuthentication
err = crypto.ErrAuthenticationFailed
return
}
if nBytes-2 != int(auth.nMethods) {
log.Warning("Socks: Unmatching number of auth methods, expecting ", auth.nMethods, ", but got ", nBytes)
err = proxy.ErrInvalidAuthentication
err = crypto.ErrAuthenticationFailed
return
}
copy(auth.authMethods[:], buffer[2:nBytes])
+2 -1
View File
@@ -9,6 +9,7 @@ import (
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/testing/assert"
"v2ray.com/core/common/crypto"
)
func TestHasAuthenticationMethod(t *testing.T) {
@@ -145,7 +146,7 @@ func TestZeroAuthenticationMethod(t *testing.T) {
buffer := alloc.NewBuffer()
buffer.AppendBytes(5, 0)
_, _, err := ReadAuthentication(buffer)
assert.Error(err).Equals(proxy.ErrInvalidAuthentication)
assert.Error(err).Equals(crypto.ErrAuthenticationFailed)
}
func TestWrongProtocolVersion(t *testing.T) {
assert := assert.On(t)