Add sslpassthrough tests (#9457)
This commit is contained in:
parent
a8f4f29871
commit
fe2bf5cbdf
6 changed files with 231 additions and 28 deletions
|
|
@ -17,8 +17,10 @@ limitations under the License.
|
|||
package httpexpect
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
|
@ -71,6 +73,33 @@ func (h *HTTPRequest) DoRequest(method, rpath string) *HTTPRequest {
|
|||
return h
|
||||
}
|
||||
|
||||
// ForceResolve forces the test resolver to point to a specific endpoint
|
||||
func (h *HTTPRequest) ForceResolve(ip string, port uint16) *HTTPRequest {
|
||||
addr := net.ParseIP(ip)
|
||||
if addr == nil {
|
||||
h.chain.fail(fmt.Sprintf("invalid ip address: %s", ip))
|
||||
return h
|
||||
}
|
||||
dialer := &net.Dialer{
|
||||
Timeout: h.client.Timeout,
|
||||
KeepAlive: h.client.Timeout,
|
||||
DualStack: true,
|
||||
}
|
||||
resolveAddr := fmt.Sprintf("%s:%d", ip, int(port))
|
||||
|
||||
oldTransport, ok := h.client.Transport.(*http.Transport)
|
||||
if !ok {
|
||||
h.chain.fail("invalid old transport address")
|
||||
return h
|
||||
}
|
||||
newTransport := oldTransport.Clone()
|
||||
newTransport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return dialer.DialContext(ctx, network, resolveAddr)
|
||||
}
|
||||
h.client.Transport = newTransport
|
||||
return h
|
||||
}
|
||||
|
||||
// Expect executes the request and returns an HTTP response.
|
||||
func (h *HTTPRequest) Expect() *HTTPResponse {
|
||||
if h.query != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue