summaryrefslogtreecommitdiff
path: root/tests/wscat.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wscat.go')
-rw-r--r--tests/wscat.go162
1 files changed, 0 insertions, 162 deletions
diff --git a/tests/wscat.go b/tests/wscat.go
index da16f66..6ef1446 100644
--- a/tests/wscat.go
+++ b/tests/wscat.go
@@ -7,8 +7,6 @@ import (
"context"
"crypto/tls"
"crypto/x509"
- "encoding/base64"
- "encoding/binary"
"encoding/json"
"errors"
"fmt"
@@ -171,84 +169,6 @@ func sendRecv(t *testing.T, ws *Conn) {
}
}
-func TestProxyDial(t *testing.T) {
-
- s := newServer(t)
- defer s.Close()
-
- surl, _ := url.Parse(s.Server.URL)
-
- cstDialer := cstDialer // make local copy for modification on next line.
- cstDialer.Proxy = http.ProxyURL(surl)
-
- connect := false
- origHandler := s.Server.Config.Handler
-
- // Capture the request Host header.
- s.Server.Config.Handler = http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- if r.Method == http.MethodConnect {
- connect = true
- w.WriteHeader(http.StatusOK)
- return
- }
-
- if !connect {
- t.Log("connect not received")
- http.Error(w, "connect not received", http.StatusMethodNotAllowed)
- return
- }
- origHandler.ServeHTTP(w, r)
- })
-
- ws, _, err := cstDialer.Dial(s.URL, nil)
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
- sendRecv(t, ws)
-}
-
-func TestProxyAuthorizationDial(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- surl, _ := url.Parse(s.Server.URL)
- surl.User = url.UserPassword("username", "password")
-
- cstDialer := cstDialer // make local copy for modification on next line.
- cstDialer.Proxy = http.ProxyURL(surl)
-
- connect := false
- origHandler := s.Server.Config.Handler
-
- // Capture the request Host header.
- s.Server.Config.Handler = http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- proxyAuth := r.Header.Get("Proxy-Authorization")
- expectedProxyAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password"))
- if r.Method == http.MethodConnect && proxyAuth == expectedProxyAuth {
- connect = true
- w.WriteHeader(http.StatusOK)
- return
- }
-
- if !connect {
- t.Log("connect with proxy authorization not received")
- http.Error(w, "connect with proxy authorization not received", http.StatusMethodNotAllowed)
- return
- }
- origHandler.ServeHTTP(w, r)
- })
-
- ws, _, err := cstDialer.Dial(s.URL, nil)
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
- sendRecv(t, ws)
-}
-
func TestDial(t *testing.T) {
s := newServer(t)
defer s.Close()
@@ -818,85 +738,6 @@ func TestDialCompression(t *testing.T) {
sendRecv(t, ws)
}
-func TestSocksProxyDial(t *testing.T) {
- s := newServer(t)
- defer s.Close()
-
- proxyListener, err := net.Listen("tcp", "127.0.0.1:0")
- if err != nil {
- t.Fatalf("listen failed: %v", err)
- }
- defer proxyListener.Close()
- go func() {
- c1, err := proxyListener.Accept()
- if err != nil {
- t.Errorf("proxy accept failed: %v", err)
- return
- }
- defer c1.Close()
-
- _ = c1.SetDeadline(time.Now().Add(30 * time.Second))
-
- buf := make([]byte, 32)
- if _, err := io.ReadFull(c1, buf[:3]); err != nil {
- t.Errorf("read failed: %v", err)
- return
- }
- if want := []byte{5, 1, 0}; !bytes.Equal(want, buf[:len(want)]) {
- t.Errorf("read %x, want %x", buf[:len(want)], want)
- }
- if _, err := c1.Write([]byte{5, 0}); err != nil {
- t.Errorf("write failed: %v", err)
- return
- }
- if _, err := io.ReadFull(c1, buf[:10]); err != nil {
- t.Errorf("read failed: %v", err)
- return
- }
- if want := []byte{5, 1, 0, 1}; !bytes.Equal(want, buf[:len(want)]) {
- t.Errorf("read %x, want %x", buf[:len(want)], want)
- return
- }
- buf[1] = 0
- if _, err := c1.Write(buf[:10]); err != nil {
- t.Errorf("write failed: %v", err)
- return
- }
-
- ip := net.IP(buf[4:8])
- port := binary.BigEndian.Uint16(buf[8:10])
-
- c2, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: ip, Port: int(port)})
- if err != nil {
- t.Errorf("dial failed; %v", err)
- return
- }
- defer c2.Close()
- done := make(chan struct{})
- go func() {
- _, _ = io.Copy(c1, c2)
- close(done)
- }()
- _, _ = io.Copy(c2, c1)
- <-done
- }()
-
- purl, err := url.Parse("socks5://" + proxyListener.Addr().String())
- if err != nil {
- t.Fatalf("parse failed: %v", err)
- }
-
- cstDialer := cstDialer // make local copy for modification on next line.
- cstDialer.Proxy = http.ProxyURL(purl)
-
- ws, _, err := cstDialer.Dial(s.URL, nil)
- if err != nil {
- t.Fatalf("Dial: %v", err)
- }
- defer ws.Close()
- sendRecv(t, ws)
-}
-
func TestTracingDialWithContext(t *testing.T) {
var headersWrote, requestWrote, getConn, gotConn, connectDone, gotFirstResponseByte bool
@@ -2756,8 +2597,6 @@ func TestParseArgs(t *testing.T) {
func MainTest() {
tests := []testing.InternalTest {
- { "TestProxyDial", TestProxyDial },
- { "TestProxyAuthorizationDial", TestProxyAuthorizationDial },
{ "TestDial", TestDial },
{ "TestDialCookieJar", TestDialCookieJar },
{ "TestDialTLS", TestDialTLS },
@@ -2774,7 +2613,6 @@ func MainTest() {
{ "TestRespOnBadHandshake", TestRespOnBadHandshake },
{ "TestHost", TestHost },
{ "TestDialCompression", TestDialCompression },
- { "TestSocksProxyDial", TestSocksProxyDial },
{ "TestTracingDialWithContext", TestTracingDialWithContext },
{ "TestEmptyTracingDialWithContext", TestEmptyTracingDialWithContext },
{ "TestNetDialConnect", TestNetDialConnect },