diff --git a/go.mod b/go.mod index 4f79988d9..0840a295a 100644 --- a/go.mod +++ b/go.mod @@ -16,8 +16,8 @@ require ( github.com/txthinking/x v0.0.0-20200330144832-5ad2416896a9 // indirect github.com/xtaci/smux v1.5.14 go.starlark.net v0.0.0-20200619143648-50ca820fafb9 // indirect - golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 - golang.org/x/net v0.0.0-20200625001655-4c5254603344 + golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 + golang.org/x/net v0.0.0-20200707034311-ab3426394381 golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect golang.org/x/text v0.3.3 // indirect golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e diff --git a/go.sum b/go.sum index d511ea701..b3f1e1686 100644 --- a/go.sum +++ b/go.sum @@ -91,6 +91,8 @@ golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg= +golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -101,8 +103,8 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/redirector/redirector_test.go b/redirector/redirector_test.go index e223ad57a..6a4ec378f 100644 --- a/redirector/redirector_test.go +++ b/redirector/redirector_test.go @@ -2,10 +2,15 @@ package redirector import ( "context" + "fmt" "net" + "net/http" + "strings" "testing" + "time" "github.com/p4gefau1t/trojan-go/common" + "github.com/p4gefau1t/trojan-go/test/util" ) func TestRedirector(t *testing.T) { @@ -39,25 +44,23 @@ func TestRedirector(t *testing.T) { common.Must(err) conn2, err := l.Accept() common.Must(err) - // TODO fix timeout - /* - redirAddr, err := net.ResolveTCPAddr("tcp", util.HTTPAddr) - common.Must(err) - redir.Redirect(&Redirection{ - Dial: nil, - RedirectTo: redirAddr, - InboundConn: conn2, - }) - req, err := http.NewRequest("GET", "http://localhost/", nil) - common.Must(err) - req.Write(conn1) - buf := make([]byte, 1024) - conn1.Read(buf) - fmt.Println(string(buf)) - if !strings.HasPrefix(string(buf), "HTTP/1.1 200 OK") { - t.Fail() - } - */ + redirAddr, err := net.ResolveTCPAddr("tcp", util.HTTPAddr) + common.Must(err) + redir.Redirect(&Redirection{ + Dial: nil, + RedirectTo: redirAddr, + InboundConn: conn2, + }) + time.Sleep(time.Second) + req, err := http.NewRequest("GET", "http://localhost/", nil) + common.Must(err) + req.Write(conn1) + buf := make([]byte, 1024) + conn1.Read(buf) + fmt.Println(string(buf)) + if !strings.HasPrefix(string(buf), "HTTP/1.1 200 OK") { + t.Fail() + } cancel() conn1.Close() conn2.Close() diff --git a/test/util/target.go b/test/util/target.go index ed5c86fdc..c7eb08b77 100644 --- a/test/util/target.go +++ b/test/util/target.go @@ -45,7 +45,7 @@ func runHelloHTTPServer() { Handler: mux, } go server.ListenAndServe() - time.Sleep(time.Second * 3) // wait for http server + time.Sleep(time.Second * 1) // wait for http server fmt.Println("http test server listening on", HTTPAddr) wg.Done() } diff --git a/tunnel/websocket/websocket_test.go b/tunnel/websocket/websocket_test.go index cac551b37..01a48e850 100644 --- a/tunnel/websocket/websocket_test.go +++ b/tunnel/websocket/websocket_test.go @@ -7,6 +7,7 @@ import ( "strings" "sync" "testing" + "time" "github.com/p4gefau1t/trojan-go/common" "github.com/p4gefau1t/trojan-go/config" @@ -51,6 +52,7 @@ func TestWebsocket(t *testing.T) { common.Must(err) wg.Done() }() + time.Sleep(time.Second) conn1, err := c.DialConn(nil, nil) common.Must(err) wg.Wait() @@ -101,6 +103,7 @@ func TestRedirect(t *testing.T) { t.Fail() } }() + time.Sleep(time.Second) conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port)) common.Must(err) url := "wss://localhost/wrong-path"