MCPcopy
hub / github.com/gorilla/websocket / TestProxyAuthorizationDial

Function TestProxyAuthorizationDial

client_server_test.go:189–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

187}
188
189func TestProxyAuthorizationDial(t *testing.T) {
190 s := newServer(t)
191 defer s.Close()
192
193 surl, _ := url.Parse(s.Server.URL)
194 surl.User = url.UserPassword("username", "password")
195
196 cstDialer := cstDialer // make local copy for modification on next line.
197 cstDialer.Proxy = http.ProxyURL(surl)
198
199 connect := false
200 origHandler := s.Server.Config.Handler
201
202 // Capture the request Host header.
203 s.Server.Config.Handler = http.HandlerFunc(
204 func(w http.ResponseWriter, r *http.Request) {
205 proxyAuth := r.Header.Get("Proxy-Authorization")
206 expectedProxyAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password"))
207 if r.Method == http.MethodConnect && proxyAuth == expectedProxyAuth {
208 connect = true
209 w.WriteHeader(http.StatusOK)
210 return
211 }
212
213 if !connect {
214 t.Log("connect with proxy authorization not received")
215 http.Error(w, "connect with proxy authorization not received", http.StatusMethodNotAllowed)
216 return
217 }
218 origHandler.ServeHTTP(w, r)
219 })
220
221 ws, _, err := cstDialer.Dial(s.URL, nil)
222 if err != nil {
223 t.Fatalf("Dial: %v", err)
224 }
225 defer ws.Close()
226 sendRecv(t, ws)
227}
228
229func TestDial(t *testing.T) {
230 s := newServer(t)

Callers

nothing calls this directly

Calls 7

newServerFunction · 0.85
sendRecvFunction · 0.85
ServeHTTPMethod · 0.80
GetMethod · 0.65
DialMethod · 0.65
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected