"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/server/service/proxy_websocket_test.go" between
traefik-v2.3.2.src.tar.gz and traefik-v2.3.3.src.tar.gz

About: Traefik is a cloud native edge router, a reverse proxy and load balancer for HTTP and TCP-based applications.

proxy_websocket_test.go  (traefik-v2.3.2.src):proxy_websocket_test.go  (traefik-v2.3.3.src)
package service package service
import ( import (
"bufio" "bufio"
"crypto/tls" "crypto/tls"
"errors"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"testing" "testing"
"time" "time"
gorillawebsocket "github.com/gorilla/websocket" gorillawebsocket "github.com/gorilla/websocket"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
skipping to change at line 52 skipping to change at line 53
defer srv.Close() defer srv.Close()
proxy := createProxyWithForwarder(t, f, srv.URL) proxy := createProxyWithForwarder(t, f, srv.URL)
proxyAddr := proxy.Listener.Addr().String() proxyAddr := proxy.Listener.Addr().String()
_, conn, err := newWebsocketRequest( _, conn, err := newWebsocketRequest(
withServer(proxyAddr), withServer(proxyAddr),
withPath("/ws"), withPath("/ws"),
).open() ).open()
require.NoError(t, err) require.NoError(t, err)
conn.Close() conn.Close()
serverErr := <-errChan serverErr := <-errChan
wsErr, ok := serverErr.(*gorillawebsocket.CloseError) var wsErr *gorillawebsocket.CloseError
assert.Equal(t, true, ok) require.True(t, errors.As(serverErr, &wsErr))
assert.Equal(t, 1006, wsErr.Code) assert.Equal(t, 1006, wsErr.Code)
} }
func TestWebSocketPingPong(t *testing.T) { func TestWebSocketPingPong(t *testing.T) {
f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil)
require.NoError(t, err) require.NoError(t, err)
upgrader := gorillawebsocket.Upgrader{ upgrader := gorillawebsocket.Upgrader{
HandshakeTimeout: 10 * time.Second, HandshakeTimeout: 10 * time.Second,
skipping to change at line 122 skipping to change at line 124
return goodErr return goodErr
} }
return badErr return badErr
}) })
err = conn.WriteControl(gorillawebsocket.PingMessage, []byte("Ping"), tim e.Now().Add(time.Second)) err = conn.WriteControl(gorillawebsocket.PingMessage, []byte("Ping"), tim e.Now().Add(time.Second))
require.NoError(t, err) require.NoError(t, err)
_, _, err = conn.ReadMessage() _, _, err = conn.ReadMessage()
if err != goodErr { if !errors.Is(err, goodErr) {
require.NoError(t, err) require.NoError(t, err)
} }
} }
func TestWebSocketEcho(t *testing.T) { func TestWebSocketEcho(t *testing.T) {
f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil)
require.NoError(t, err) require.NoError(t, err)
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/ws", websocket.Handler(func(conn *websocket.Conn) { mux.Handle("/ws", websocket.Handler(func(conn *websocket.Conn) {
 End of changes. 4 change blocks. 
3 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)