MCPcopy
hub / github.com/snyk/cli / helper_getHttpClient

Function helper_getHttpClient

cliv2/internal/proxy/proxy_test.go:29–68  ·  view source on GitHub ↗
(gateway *proxy.WrapperProxy, useProxyAuth bool)

Source from the content-addressed store, hash-verified

27var caData proxy.CaData
28
29func helper_getHttpClient(gateway *proxy.WrapperProxy, useProxyAuth bool) (*http.Client, error) {
30 rootCAs, _ := x509.SystemCertPool()
31 if rootCAs == nil {
32 rootCAs = x509.NewCertPool()
33 }
34
35 proxyCertBytes, err := os.ReadFile(gateway.CertificateLocation)
36 if err != nil {
37 return nil, err
38 }
39
40 ok := rootCAs.AppendCertsFromPEM(proxyCertBytes)
41 if ok == false {
42 return nil, fmt.Errorf("failed to append proxy cert")
43 }
44
45 config := &tls.Config{
46 InsecureSkipVerify: false,
47 RootCAs: rootCAs,
48 }
49
50 var proxyUrl *url.URL
51 proxyInfo := gateway.ProxyInfo()
52 if useProxyAuth {
53 proxyUrl, err = url.Parse(fmt.Sprintf("http://%s:%s@127.0.0.1:%d", proxy.PROXY_USERNAME, proxyInfo.Password, proxyInfo.Port))
54 } else {
55 proxyUrl, err = url.Parse(fmt.Sprintf("http://127.0.0.1:%d", proxyInfo.Port))
56 }
57
58 if err != nil {
59 return nil, err
60 }
61
62 proxiedClient := &http.Client{Transport: &http.Transport{
63 Proxy: http.ProxyURL(proxyUrl),
64 TLSClientConfig: config,
65 }}
66
67 return proxiedClient, nil
68}
69
70func setup(t *testing.T, baseCache string, version string) configuration.Configuration {
71 t.Helper()

Callers 2

Test_canGoThroughProxyFunction · 0.85

Calls 1

ProxyInfoMethod · 0.80

Tested by

no test coverage detected