MCPcopy Index your code
hub / github.com/labstack/echo / TestProxyWithConfigWebSocketTLS2NonTLS

Function TestProxyWithConfigWebSocketTLS2NonTLS

middleware/proxy_test.go:1125–1167  ·  view source on GitHub ↗

TestProxyWithConfigWebSocketTLSToNoneTLS tests the proxy with TLS to non-TLS WebSocket connection. (TLS termination)

(t *testing.T)

Source from the content-addressed store, hash-verified

1123
1124// TestProxyWithConfigWebSocketTLSToNoneTLS tests the proxy with TLS to non-TLS WebSocket connection. (TLS termination)
1125func TestProxyWithConfigWebSocketTLS2NonTLS(t *testing.T) {
1126 /*
1127 Arrange
1128 */
1129
1130 // Create a WebSocket test server (non-TLS)
1131 srv := createSimpleWebSocketServer(false)
1132 defer srv.Close()
1133
1134 // create proxy server (TLS to non-TLS)
1135 ts := createSimpleProxyServer(t, srv, true, false)
1136 defer ts.Close()
1137
1138 tsURL, _ := url.Parse(ts.URL)
1139 tsURL.Scheme = "wss"
1140 tsURL.Path = "/"
1141
1142 /*
1143 Act
1144 */
1145 origin, err := url.Parse(ts.URL)
1146 assert.NoError(t, err)
1147 config := &websocket.Config{
1148 Location: tsURL,
1149 Origin: origin,
1150 TlsConfig: &tls.Config{InsecureSkipVerify: true}, // skip verify for testing
1151 Version: websocket.ProtocolVersionHybi13,
1152 }
1153 wsConn, err := websocket.DialConfig(config)
1154 assert.NoError(t, err)
1155 defer wsConn.Close()
1156
1157 // Send message
1158 sendMsg := "Hello, TLS to NoneTLS WebSocket!"
1159 err = websocket.Message.Send(wsConn, sendMsg)
1160 assert.NoError(t, err)
1161
1162 // Read response
1163 var recvMsg string
1164 err = websocket.Message.Receive(wsConn, &recvMsg)
1165 assert.NoError(t, err)
1166 assert.Equal(t, sendMsg, recvMsg)
1167}
1168
1169// TestProxyWebSocketXForwardedFor verifies that for WebSocket Upgrade requests,
1170// the proxy middleware appends c.RealIP() to any existing X-Forwarded-For chain,

Callers

nothing calls this directly

Calls 3

createSimpleProxyServerFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…