Documentation
¶
Overview ¶
Package proxytest is an HTTP proxy that answers CONNECT and nothing else, so a test can show that a client reaches a server only through a proxy, and how the client takes a proxy that refuses it. The Go tests run it in the test process, and the mock control plane runs it for the e2e suites.
The package imports neither testing nor internal/api: the mock is a program, and the tests of internal/api import this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
TLS *tls.Config // non-nil: the listener speaks TLS
Username string // with Password: the Basic credentials a CONNECT must carry
Password string
Target string // non-empty: the only host:port a CONNECT may name
Upstream string // non-empty: the address every admitted tunnel connects to, in place of the CONNECT target
}
Options says what a Proxy asks of a client and where its tunnels lead. The zero value is a plain proxy that tunnels to any target.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is a CONNECT proxy. Listen makes one, and it answers once Serve runs.
func Listen ¶
Listen binds addr, a host:port as net.Listen takes it, and returns the proxy that Serve runs on it. A TLS listener offers no ALPN protocol, whatever opts.TLS names, because the proxy speaks HTTP/1.1 only.
func (*Proxy) Addr ¶
Addr returns the address the proxy is bound to, with the port the kernel chose when Listen was given port 0.
func (*Proxy) Serve ¶
Serve accepts connections until ctx ends and returns nil then, or the error of a listener that failed before. Either way it has closed the listener and every tunnel, and waited for their goroutines, when it returns.
DECISION: Serve reads the requests itself instead of running an http.Server. A tunnel needs the connection hijacked, and http.Server.Close neither closes a hijacked connection nor waits for its handler.
type Stats ¶
type Stats struct {
Tunnels int `json:"tunnels"` // CONNECTs answered 200
RefusedAuth int `json:"refused_auth"` // answered 407
RefusedTarget int `json:"refused_target"` // answered 403
OtherRequests int `json:"other_requests"` // not a CONNECT, answered 405
Targets []string `json:"targets"` // distinct host:port of admitted CONNECTs, sorted
}
Stats counts the answers a Proxy gave. A CONNECT whose upstream could not be dialed, answered 502, is counted nowhere. Each answer is counted before it is sent, so a client that has read one finds it here.