(t *testing.T)
| 304 | } |
| 305 | |
| 306 | func TestDownloadTLS(t *testing.T) { |
| 307 | cd := "../../testdata" |
| 308 | ca, pub, priv := filepath.Join(cd, "rootca.crt"), filepath.Join(cd, "crt.pem"), filepath.Join(cd, "key.pem") |
| 309 | insecureSkipTLSVerify := false |
| 310 | |
| 311 | tlsSrv := httptest.NewUnstartedServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})) |
| 312 | tlsConf, err := tlsutil.NewTLSConfig( |
| 313 | tlsutil.WithInsecureSkipVerify(insecureSkipTLSVerify), |
| 314 | tlsutil.WithCertKeyPairFiles(pub, priv), |
| 315 | tlsutil.WithCAFile(ca), |
| 316 | ) |
| 317 | if err != nil { |
| 318 | t.Fatal(fmt.Errorf("can't create TLS config for client: %w", err)) |
| 319 | } |
| 320 | tlsConf.ServerName = "helm.sh" |
| 321 | tlsSrv.TLS = tlsConf |
| 322 | tlsSrv.StartTLS() |
| 323 | defer tlsSrv.Close() |
| 324 | |
| 325 | u, _ := url.ParseRequestURI(tlsSrv.URL) |
| 326 | g, err := NewHTTPGetter( |
| 327 | WithURL(u.String()), |
| 328 | WithTLSClientConfig(pub, priv, ca), |
| 329 | ) |
| 330 | if err != nil { |
| 331 | t.Fatal(err) |
| 332 | } |
| 333 | |
| 334 | if _, err := g.Get(u.String()); err != nil { |
| 335 | t.Error(err) |
| 336 | } |
| 337 | |
| 338 | // now test with TLS config being passed along in .Get (see #6635) |
| 339 | g, err = NewHTTPGetter() |
| 340 | if err != nil { |
| 341 | t.Fatal(err) |
| 342 | } |
| 343 | |
| 344 | if _, err := g.Get(u.String(), WithURL(u.String()), WithTLSClientConfig(pub, priv, ca)); err != nil { |
| 345 | t.Error(err) |
| 346 | } |
| 347 | |
| 348 | // test with only the CA file (see also #6635) |
| 349 | g, err = NewHTTPGetter() |
| 350 | if err != nil { |
| 351 | t.Fatal(err) |
| 352 | } |
| 353 | |
| 354 | if _, err := g.Get(u.String(), WithURL(u.String()), WithTLSClientConfig("", "", ca)); err != nil { |
| 355 | t.Error(err) |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | func TestDownloadTLSWithRedirect(t *testing.T) { |
| 360 | cd := "../../testdata" |
nothing calls this directly
no test coverage detected
searching dependent graphs…