add unit test for https proxy

This commit is contained in:
Philip Hamer 2021-12-06 10:29:48 -05:00
parent 2553869a29
commit d16969baa1
No known key found for this signature in database
GPG Key ID: 1977721B2884BED3
1 changed files with 41 additions and 0 deletions

View File

@ -185,6 +185,47 @@ func TestProxyDial(t *testing.T) {
sendRecv(t, ws)
}
func TestHttpsProxy(t *testing.T) {
sTLS := newTLSServer(t)
defer sTLS.Close()
s := newServer(t)
defer s.Close()
surlTLS, _ := url.Parse(sTLS.Server.URL)
cstDialer := cstDialer // make local copy for modification on next line.
cstDialer.Proxy = http.ProxyURL(surlTLS)
connect := false
origHandler := sTLS.Server.Config.Handler
// Capture the request Host header.
sTLS.Server.Config.Handler = http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if r.Method == "CONNECT" {
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)
})
cstDialer.TLSClientConfig = &tls.Config{RootCAs: rootCAs(t, sTLS.Server)}
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()