diff options
Diffstat (limited to 'vendor/github.com/gorilla/websocket/client_server_test.go')
-rw-r--r-- | vendor/github.com/gorilla/websocket/client_server_test.go | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/vendor/github.com/gorilla/websocket/client_server_test.go b/vendor/github.com/gorilla/websocket/client_server_test.go index 3f7345dde..7d39da681 100644 --- a/vendor/github.com/gorilla/websocket/client_server_test.go +++ b/vendor/github.com/gorilla/websocket/client_server_test.go @@ -10,8 +10,8 @@ import ( "encoding/base64" "io" "io/ioutil" - "net" "net/http" + "net/http/cookiejar" "net/http/httptest" "net/url" "reflect" @@ -21,9 +21,10 @@ import ( ) var cstUpgrader = Upgrader{ - Subprotocols: []string{"p0", "p1"}, - ReadBufferSize: 1024, - WriteBufferSize: 1024, + Subprotocols: []string{"p0", "p1"}, + ReadBufferSize: 1024, + WriteBufferSize: 1024, + EnableCompression: true, Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) { http.Error(w, reason.Error(), status) }, @@ -228,6 +229,54 @@ func TestDial(t *testing.T) { sendRecv(t, ws) } +func TestDialCookieJar(t *testing.T) { + s := newServer(t) + defer s.Close() + + jar, _ := cookiejar.New(nil) + d := cstDialer + d.Jar = jar + + u, _ := parseURL(s.URL) + + switch u.Scheme { + case "ws": + u.Scheme = "http" + case "wss": + u.Scheme = "https" + } + + cookies := []*http.Cookie{&http.Cookie{Name: "gorilla", Value: "ws", Path: "/"}} + d.Jar.SetCookies(u, cookies) + + ws, _, err := d.Dial(s.URL, nil) + if err != nil { + t.Fatalf("Dial: %v", err) + } + defer ws.Close() + + var gorilla string + var sessionID string + for _, c := range d.Jar.Cookies(u) { + if c.Name == "gorilla" { + gorilla = c.Value + } + + if c.Name == "sessionID" { + sessionID = c.Value + } + } + if gorilla != "ws" { + t.Error("Cookie not present in jar.") + } + + if sessionID != "1234" { + t.Error("Set-Cookie not received from the server.") + } + + sendRecv(t, ws) +} + func TestDialTLS(t *testing.T) { s := newTLSServer(t) defer s.Close() @@ -243,11 +292,9 @@ func TestDialTLS(t *testing.T) { } } - u, _ := url.Parse(s.URL) d := cstDialer - d.NetDial = func(network, addr string) (net.Conn, error) { return net.Dial(network, u.Host) } d.TLSClientConfig = &tls.Config{RootCAs: certs} - ws, _, err := d.Dial("wss://example.com"+cstRequestURI, nil) + ws, _, err := d.Dial(s.URL, nil) if err != nil { t.Fatalf("Dial: %v", err) } @@ -267,7 +314,7 @@ func xTestDialTLSBadCert(t *testing.T) { } } -func xTestDialTLSNoVerify(t *testing.T) { +func TestDialTLSNoVerify(t *testing.T) { s := newTLSServer(t) defer s.Close() @@ -449,3 +496,17 @@ func TestHostHeader(t *testing.T) { sendRecv(t, ws) } + +func TestDialCompression(t *testing.T) { + s := newServer(t) + defer s.Close() + + dialer := cstDialer + dialer.EnableCompression = true + ws, _, err := dialer.Dial(s.URL, nil) + if err != nil { + t.Fatalf("Dial: %v", err) + } + defer ws.Close() + sendRecv(t, ws) +} |