Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking InsecureSkipVerify requests #101

Open
retr0h opened this issue Aug 10, 2022 · 1 comment
Open

Mocking InsecureSkipVerify requests #101

retr0h opened this issue Aug 10, 2022 · 1 comment

Comments

@retr0h
Copy link

retr0h commented Aug 10, 2022

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
@retr0h
Copy link
Author

retr0h commented Aug 10, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant