(handler func(w http.ResponseWriter, r *http.Request))
| 138 | } |
| 139 | |
| 140 | func newTestServer(handler func(w http.ResponseWriter, r *http.Request)) (*httptest.Server, error) { |
| 141 | testServer := httptest.NewUnstartedServer(http.HandlerFunc(handler)) |
| 142 | |
| 143 | tlsCAChain, err := os.ReadFile(TLSCAChainPath) |
| 144 | if err != nil { |
| 145 | return nil, fmt.Errorf("Can't read %s", TLSCAChainPath) |
| 146 | } |
| 147 | serverCertificate, err := tls.LoadX509KeyPair(ServerCertificatePath, ServerKeyPath) |
| 148 | if err != nil { |
| 149 | return nil, fmt.Errorf("Can't load X509 key pair %s - %s", ServerCertificatePath, ServerKeyPath) |
| 150 | } |
| 151 | |
| 152 | rootCAs := x509.NewCertPool() |
| 153 | rootCAs.AppendCertsFromPEM(tlsCAChain) |
| 154 | |
| 155 | testServer.TLS = &tls.Config{ |
| 156 | Certificates: make([]tls.Certificate, 1), |
| 157 | RootCAs: rootCAs, |
| 158 | ClientAuth: tls.RequireAndVerifyClientCert, |
| 159 | ClientCAs: rootCAs, |
| 160 | } |
| 161 | testServer.TLS.Certificates[0] = serverCertificate |
| 162 | |
| 163 | testServer.StartTLS() |
| 164 | |
| 165 | return testServer, nil |
| 166 | } |
| 167 | |
| 168 | func TestNewClientFromConfig(t *testing.T) { |
| 169 | newClientValidConfig := []struct { |
no outgoing calls
no test coverage detected