This commit is contained in:
ginuerzh 2018-12-09 12:55:57 +08:00
parent e41c11d943
commit dc88462771
10 changed files with 418 additions and 553 deletions

View File

@ -41,22 +41,19 @@ func TestHTTP2Proxy(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := http2ProxyRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := http2ProxyRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -162,22 +159,19 @@ func TestHTTPOverH2(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverH2Roundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverH2Roundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -283,24 +277,21 @@ func TestSOCKS5OverH2(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverH2Roundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { nil,
err := socks5OverH2Roundtrip(httpSrv.URL, sendData, tc.cliUser,
nil, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -409,22 +400,6 @@ func TestSSOverH2(t *testing.T) {
sendData := make([]byte, 128) sendData := make([]byte, 128)
rand.Read(sendData) rand.Read(sendData)
var ssProxyTests = []struct {
clientCipher *url.Userinfo
serverCipher *url.Userinfo
pass bool
}{
{nil, nil, false},
{&url.Userinfo{}, &url.Userinfo{}, false},
{url.User("abc"), url.User("abc"), false},
{url.UserPassword("abc", "def"), url.UserPassword("abc", "def"), false},
{url.User("aes-128-cfb"), url.User("aes-128-cfb"), false},
{url.User("aes-128-cfb"), url.UserPassword("aes-128-cfb", "123456"), false},
{url.UserPassword("aes-128-cfb", "123456"), url.User("aes-128-cfb"), false},
{url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-cfb", "abc"), false},
{url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-cfb", "123456"), true},
}
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc tc := tc
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) {

View File

@ -158,22 +158,19 @@ func TestHTTPProxy(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpProxyRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpProxyRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }

View File

@ -290,22 +290,19 @@ func TestSSOverKCP(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverKCPRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.clientCipher,
err := ssOverKCPRoundtrip(httpSrv.URL, sendData, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }

View File

@ -2,7 +2,6 @@ package gost
import ( import (
"crypto/rand" "crypto/rand"
"fmt"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"testing" "testing"
@ -42,22 +41,19 @@ func TestHTTPOverQUIC(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverQUICRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverQUICRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -163,23 +159,20 @@ func TestSOCKS5OverQUIC(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverQUICRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.cliUser,
err := socks5OverQUICRoundtrip(httpSrv.URL, sendData, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -290,22 +283,19 @@ func TestSSOverQUIC(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverQUICRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.clientCipher,
err := ssOverQUICRoundtrip(httpSrv.URL, sendData, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }

View File

@ -3,7 +3,6 @@ package gost
import ( import (
"crypto/rand" "crypto/rand"
"crypto/tls" "crypto/tls"
"fmt"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"testing" "testing"
@ -67,23 +66,20 @@ func TestSOCKS5Proxy(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5ProxyRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.cliUser,
err := socks5ProxyRoundtrip(httpSrv.URL, sendData, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }

View File

@ -2,13 +2,12 @@ package gost
import ( import (
"crypto/rand" "crypto/rand"
"fmt"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"testing" "testing"
) )
var ssProxyTests = []struct { var ssTests = []struct {
clientCipher *url.Userinfo clientCipher *url.Userinfo
serverCipher *url.Userinfo serverCipher *url.Userinfo
pass bool pass bool
@ -23,54 +22,18 @@ var ssProxyTests = []struct {
{url.UserPassword("aes-128-cfb", "123456"), url.User("aes-128-cfb"), false}, {url.UserPassword("aes-128-cfb", "123456"), url.User("aes-128-cfb"), false},
{url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-cfb", "abc"), false}, {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-cfb", "abc"), false},
{url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-cfb", "123456"), true}, {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-cfb", "123456"), true},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-192-cfb", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-256-cfb", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-ctr", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-192-ctr", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-256-ctr", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("des-cfb", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("bf-cfb", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("cast5-cfb", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("rc4-md5", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("chacha20", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("chacha20-ietf", "123456"), false},
// {url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("salsa20", "123456"), false},
{url.User("aes-192-cfb"), url.User("aes-192-cfb"), false}, {url.User("aes-192-cfb"), url.User("aes-192-cfb"), false},
{url.User("aes-192-cfb"), url.UserPassword("aes-192-cfb", "123456"), false}, {url.User("aes-192-cfb"), url.UserPassword("aes-192-cfb", "123456"), false},
{url.UserPassword("aes-192-cfb", "123456"), url.User("aes-192-cfb"), false}, {url.UserPassword("aes-192-cfb", "123456"), url.User("aes-192-cfb"), false},
{url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-192-cfb", "abc"), false}, {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-192-cfb", "abc"), false},
{url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-192-cfb", "123456"), true}, {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-192-cfb", "123456"), true},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-128-cfb", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-256-cfb", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-128-ctr", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-192-ctr", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("aes-256-ctr", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("des-cfb", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("bf-cfb", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("cast5-cfb", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("rc4-md5", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("chacha20", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("chacha20-ietf", "123456"), false},
// {url.UserPassword("aes-192-cfb", "123456"), url.UserPassword("salsa20", "123456"), false},
{url.User("aes-256-cfb"), url.User("aes-256-cfb"), false}, {url.User("aes-256-cfb"), url.User("aes-256-cfb"), false},
{url.User("aes-256-cfb"), url.UserPassword("aes-256-cfb", "123456"), false}, {url.User("aes-256-cfb"), url.UserPassword("aes-256-cfb", "123456"), false},
{url.UserPassword("aes-256-cfb", "123456"), url.User("aes-256-cfb"), false}, {url.UserPassword("aes-256-cfb", "123456"), url.User("aes-256-cfb"), false},
{url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-256-cfb", "abc"), false}, {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-256-cfb", "abc"), false},
{url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-256-cfb", "123456"), true}, {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-256-cfb", "123456"), true},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-128-cfb", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-192-cfb", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-128-ctr", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-192-ctr", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("aes-256-ctr", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("des-cfb", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("bf-cfb", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("cast5-cfb", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("rc4-md5", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("chacha20", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("chacha20-ietf", "123456"), false},
// {url.UserPassword("aes-256-cfb", "123456"), url.UserPassword("salsa20", "123456"), false},
{url.User("aes-128-ctr"), url.User("aes-128-ctr"), false}, {url.User("aes-128-ctr"), url.User("aes-128-ctr"), false},
{url.User("aes-128-ctr"), url.UserPassword("aes-128-ctr", "123456"), false}, {url.User("aes-128-ctr"), url.UserPassword("aes-128-ctr", "123456"), false},
@ -133,6 +96,23 @@ var ssProxyTests = []struct {
{url.UserPassword("salsa20", "123456"), url.UserPassword("salsa20", "123456"), true}, {url.UserPassword("salsa20", "123456"), url.UserPassword("salsa20", "123456"), true},
} }
var ssProxyTests = []struct {
clientCipher *url.Userinfo
serverCipher *url.Userinfo
pass bool
}{
{nil, nil, false},
{&url.Userinfo{}, &url.Userinfo{}, false},
{url.User("abc"), url.User("abc"), false},
{url.UserPassword("abc", "def"), url.UserPassword("abc", "def"), false},
{url.User("aes-128-cfb"), url.User("aes-128-cfb"), false},
{url.User("aes-128-cfb"), url.UserPassword("aes-128-cfb", "123456"), false},
{url.UserPassword("aes-128-cfb", "123456"), url.User("aes-128-cfb"), false},
{url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-cfb", "abc"), false},
{url.UserPassword("aes-128-cfb", "123456"), url.UserPassword("aes-128-cfb", "123456"), true},
}
func ssProxyRoundtrip(targetURL string, data []byte, clientInfo *url.Userinfo, serverInfo *url.Userinfo) error { func ssProxyRoundtrip(targetURL string, data []byte, clientInfo *url.Userinfo, serverInfo *url.Userinfo) error {
ln, err := TCPListener("") ln, err := TCPListener("")
if err != nil { if err != nil {
@ -162,24 +142,21 @@ func TestSSProxy(t *testing.T) {
sendData := make([]byte, 128) sendData := make([]byte, 128)
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssTests {
tc := tc err := ssProxyRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.clientCipher,
err := ssProxyRoundtrip(httpSrv.URL, sendData, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }

View File

@ -3,7 +3,6 @@ package gost
import ( import (
"crypto/rand" "crypto/rand"
"crypto/tls" "crypto/tls"
"fmt"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"testing" "testing"
@ -43,22 +42,19 @@ func TestHTTPOverSSHTunnel(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverSSHTunnelRoundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverSSHTunnelRoundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -164,24 +160,21 @@ func TestSOCKS5OverSSHTunnel(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverSSHTunnelRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { nil,
err := socks5OverSSHTunnelRoundtrip(httpSrv.URL, sendData, tc.cliUser,
nil, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -291,23 +284,20 @@ func TestSSOverSSHTunnel(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverSSHTunnelRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { nil,
err := ssOverSSHTunnelRoundtrip(httpSrv.URL, sendData, tc.clientCipher,
nil, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }

View File

@ -3,7 +3,6 @@ package gost
import ( import (
"crypto/rand" "crypto/rand"
"crypto/tls" "crypto/tls"
"fmt"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"testing" "testing"
@ -43,22 +42,19 @@ func TestHTTPOverTLS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverTLSRoundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverTLSRoundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -164,24 +160,21 @@ func TestSOCKS5OverTLS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverTLSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { nil,
err := socks5OverTLSRoundtrip(httpSrv.URL, sendData, tc.cliUser,
nil, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -291,24 +284,21 @@ func TestSSOverTLS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverTLSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { nil,
err := ssOverTLSRoundtrip(httpSrv.URL, sendData, tc.clientCipher,
nil, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -346,22 +336,19 @@ func TestHTTPOverMTLS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverMTLSRoundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverMTLSRoundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -467,24 +454,21 @@ func TestSOCKS5OverMTLS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverMTLSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { nil,
err := socks5OverMTLSRoundtrip(httpSrv.URL, sendData, tc.cliUser,
nil, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -594,23 +578,20 @@ func TestSSOverMTLS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverMTLSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { nil,
err := ssOverMTLSRoundtrip(httpSrv.URL, sendData, tc.clientCipher,
nil, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }

View File

@ -2,7 +2,6 @@ package gost
import ( import (
"crypto/rand" "crypto/rand"
"fmt"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"testing" "testing"
@ -42,22 +41,19 @@ func TestHTTPOverWS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverWSRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverWSRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -163,23 +159,20 @@ func TestSOCKS5OverWS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverWSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.cliUser,
err := socks5OverWSRoundtrip(httpSrv.URL, sendData, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -290,23 +283,20 @@ func TestSSOverWS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverWSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.clientCipher,
err := ssOverWSRoundtrip(httpSrv.URL, sendData, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -344,22 +334,19 @@ func TestHTTPOverMWS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverMWSRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverMWSRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -466,23 +453,20 @@ func TestSOCKS5OverMWS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverMWSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.cliUser,
err := socks5OverMWSRoundtrip(httpSrv.URL, sendData, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -593,22 +577,19 @@ func TestSSOverMWS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverMWSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.clientCipher,
err := ssOverMWSRoundtrip(httpSrv.URL, sendData, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }

View File

@ -3,7 +3,6 @@ package gost
import ( import (
"crypto/rand" "crypto/rand"
"crypto/tls" "crypto/tls"
"fmt"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"testing" "testing"
@ -43,22 +42,19 @@ func TestHTTPOverWSS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverWSSRoundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverWSSRoundtrip(httpSrv.URL, sendData, nil, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -164,23 +160,20 @@ func TestSOCKS5OverWSS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverWSSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.cliUser,
err := socks5OverWSSRoundtrip(httpSrv.URL, sendData, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -291,23 +284,20 @@ func TestSSOverWSS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverWSSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.clientCipher,
err := ssOverWSSRoundtrip(httpSrv.URL, sendData, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -345,22 +335,19 @@ func TestHTTPOverMWSS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range httpProxyTests { for i, tc := range httpProxyTests {
tc := tc err := httpOverMWSSRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers)
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { if err == nil {
err := httpOverMWSSRoundtrip(httpSrv.URL, sendData, tc.cliUser, tc.srvUsers) if tc.errStr != "" {
if err == nil { t.Errorf("#%d should failed with error %s", i, tc.errStr)
if tc.errStr != "" {
t.Errorf("#%d should failed with error %s", i, tc.errStr)
}
} else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
} }
}) } else {
if tc.errStr == "" {
t.Errorf("#%d got error %v", i, err)
}
if err.Error() != tc.errStr {
t.Errorf("#%d got error %v, want %v", i, err, tc.errStr)
}
}
} }
} }
@ -467,23 +454,20 @@ func TestSOCKS5OverMWSS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range socks5ProxyTests { for i, tc := range socks5ProxyTests {
tc := tc err := socks5OverMWSSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.cliUser,
err := socks5OverMWSSRoundtrip(httpSrv.URL, sendData, tc.srvUsers,
tc.cliUser, )
tc.srvUsers, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }
@ -594,22 +578,19 @@ func TestSSOverMWSS(t *testing.T) {
rand.Read(sendData) rand.Read(sendData)
for i, tc := range ssProxyTests { for i, tc := range ssProxyTests {
tc := tc err := ssOverMWSSRoundtrip(httpSrv.URL, sendData,
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) { tc.clientCipher,
err := ssOverMWSSRoundtrip(httpSrv.URL, sendData, tc.serverCipher,
tc.clientCipher, )
tc.serverCipher, if err == nil {
) if !tc.pass {
if err == nil { t.Errorf("#%d should failed", i)
if !tc.pass {
t.Errorf("#%d should failed", i)
}
} else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
} }
}) } else {
// t.Logf("#%d %v", i, err)
if tc.pass {
t.Errorf("#%d got error: %v", i, err)
}
}
} }
} }