From 4a0e8afd3b28110885d30efd90c6f38e8f81f631 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Tue, 19 May 2026 12:57:41 +0000 Subject: [PATCH] fix tests --- internal/configuration/settings/settings_test.go | 2 +- internal/socks5/usernamepassword.go | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/internal/configuration/settings/settings_test.go b/internal/configuration/settings/settings_test.go index 999516e3..96ea4358 100644 --- a/internal/configuration/settings/settings_test.go +++ b/internal/configuration/settings/settings_test.go @@ -81,7 +81,7 @@ func Test_Settings_String(t *testing.T) { | | ├── 1.1.1.1 | | └── 8.8.8.8 | └── Restart VPN on healthcheck failure: yes -├── SOCKS5 proxy settings: +├── SOCKS5 proxy server settings: | └── Enabled: no ├── Shadowsocks server settings: | └── Enabled: no diff --git a/internal/socks5/usernamepassword.go b/internal/socks5/usernamepassword.go index 3cc6fcc5..a0671013 100644 --- a/internal/socks5/usernamepassword.go +++ b/internal/socks5/usernamepassword.go @@ -1,17 +1,10 @@ package socks5 import ( - "errors" "fmt" "io" ) -var ( - ErrSubnegotiationVersionNotSupported = errors.New("subnegotiation version not supported") - ErrUsernameNotValid = errors.New("username not valid") - ErrPasswordNotValid = errors.New("password not valid") -) - // See https://datatracker.ietf.org/doc/html/rfc1929#section-2 func usernamePasswordSubnegotiate(conn io.ReadWriter, username, password string) (err error) { status := byte(1) @@ -27,7 +20,7 @@ func usernamePasswordSubnegotiate(conn io.ReadWriter, username, password string) if header[0] != authUsernamePasswordSubNegotiation1 { _, _ = conn.Write([]byte{defaultVersion, status}) - return fmt.Errorf("%w: %d", ErrSubnegotiationVersionNotSupported, header[0]) + return fmt.Errorf("subnegotiation version not supported: %d", header[0]) } version := header[0] @@ -38,7 +31,7 @@ func usernamePasswordSubnegotiate(conn io.ReadWriter, username, password string) return fmt.Errorf("reading username bytes: %w", err) } else if username != string(usernameBytes) { _, _ = conn.Write([]byte{version, status}) - return fmt.Errorf("%w: %s", ErrUsernameNotValid, string(usernameBytes)) + return fmt.Errorf("username not valid: %s", string(usernameBytes)) } const passwordHeaderLength = 1 @@ -56,7 +49,7 @@ func usernamePasswordSubnegotiate(conn io.ReadWriter, username, password string) return fmt.Errorf("reading password bytes: %w", err) } else if password != string(passwordBytes) { _, _ = conn.Write([]byte{version, status}) - return fmt.Errorf("%w: %s", ErrPasswordNotValid, string(passwordBytes)) + return fmt.Errorf("password not valid for username %q", string(usernameBytes)) } status = 0