Mocking InsecureSkipVerify requests
retr0h opened this issue · comments
נυαη נυαηѕση commented
If i attempt to mock the following request it does not work. However, if I change client to the following it passes. Any idea what I'm doing wrong?
client := &http.Client{}
gock.New("https://0.0.0.0").
Post("/api/auth/token/login/").
MatchHeader("Content-Type", "application/json; chartset=UTF-8").
JSON(map[string]string{"foo": "bar"}).
Reply(200).
BodyString(`{"foo": "foo"}`)
body := bytes.NewBuffer([]byte(`{"foo":"bar"}`))
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
req, err := http.NewRequest("POST", "https://0.0.0.0/api/auth/token/login/", body)
req.Header.Set("Content-Type", "application/json; chartset=UTF-8")
resp, err := client.Do(req)
if err != nil {
fmt.Printf("error building request: %v", err)
}
Error is:
error building request: Post "https://0.0.0.0/api/auth/token/login/": dial tcp 0.0.0.0:443: connect: connection refused
נυαη נυαηѕση commented
Update, if I explicitly set the intercept client, after defining the client
containing the InsecureSkipVerify
transport, it seems to work. This doesn't seem ideal, any other suggestions?
gock.InterceptClient(client)