MCPcopy
hub / github.com/helm/helm / TestDownloadTLS

Function TestDownloadTLS

pkg/getter/httpgetter_test.go:306–357  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

304}
305
306func 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
359func TestDownloadTLSWithRedirect(t *testing.T) {
360 cd := "../../testdata"

Callers

nothing calls this directly

Calls 12

GetMethod · 0.95
NewTLSConfigFunction · 0.92
WithInsecureSkipVerifyFunction · 0.92
WithCertKeyPairFilesFunction · 0.92
WithCAFileFunction · 0.92
NewHTTPGetterFunction · 0.85
WithURLFunction · 0.85
FatalMethod · 0.80
CloseMethod · 0.80
WithTLSClientConfigFunction · 0.70
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…