Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmalek/a3e14907a1910a49eceee34f930296ad to your computer and use it in GitHub Desktop.
Save pmalek/a3e14907a1910a49eceee34f930296ad to your computer and use it in GitHub Desktop.
func httpClientForCert(t *testing.T, caData, certData, keyData []byte) *http.Client {
cert, err := tls.X509KeyPair(certData, keyData)
require.NoError(t, err)
caCertPool := x509.NewCertPool()
require.True(t, caCertPool.AppendCertsFromPEM(caData))
// Setup HTTPS client
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{
cert,
},
RootCAs: caCertPool,
}
transport := &http.Transport{
TLSClientConfig: tlsConfig,
}
client := &http.Client{
Transport: transport,
}
return client
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment