Skip to content

Commit e9fd5d3

Browse files
committed
feat: mtls to test client
1 parent 43b1b8b commit e9fd5d3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package gokhttp
22

33
import (
4+
"crypto/tls"
5+
"crypto/x509"
6+
"fmt"
47
"github.com/BRUHItsABunny/gOkHttp/client"
58
"net/http"
69
"os"
@@ -17,6 +20,18 @@ func TestHTTPClient(options ...gokhttp_client.Option) (*http.Client, error) {
1720
if os.Getenv("USE_PROXY") == "true" {
1821
opts = append(opts, gokhttp_client.NewProxyOption(os.Getenv("PROXY_URL")))
1922
}
23+
if os.Getenv("USE_MTLS") == "true" {
24+
opt := gokhttp_client.NewMTLSOption(x509.NewCertPool(), []tls.Certificate{})
25+
err := opt.AddCAFromFile(os.Getenv("CA_CERT"))
26+
if err != nil {
27+
return nil, fmt.Errorf("opt.AddCAFromFile: %w", err)
28+
}
29+
err = opt.AddClientCertFromFile(os.Getenv("CLIENT_CERT"), os.Getenv("CLIENT_KEY"))
30+
if err != nil {
31+
return nil, fmt.Errorf("opt.AddClientCertFromFile: %w", err)
32+
}
33+
opts = append(opts, opt)
34+
}
2035

2136
opts = append(opts, options...)
2237

0 commit comments

Comments
 (0)