MCPcopy Create free account
hub / github.com/google/pprof / TestHTTPSWithServerCertFetch

Function TestHTTPSWithServerCertFetch

internal/driver/fetch_test.go:685–796  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

683}
684
685func TestHTTPSWithServerCertFetch(t *testing.T) {
686 if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
687 t.Skip("test assumes tcp available")
688 }
689 saveHome := os.Getenv(homeEnv())
690 tempdir, err := os.MkdirTemp("", "home")
691 if err != nil {
692 t.Fatal("creating temp dir: ", err)
693 }
694 defer os.RemoveAll(tempdir)
695
696 // pprof writes to $HOME/pprof by default which is not necessarily
697 // writeable (e.g. on a Debian build) so set $HOME to something we
698 // know we can write to for the duration of the test.
699 os.Setenv(homeEnv(), tempdir)
700 defer os.Setenv(homeEnv(), saveHome)
701
702 baseConfig := currentConfig()
703 defer setCurrentConfig(baseConfig)
704
705 cert, certBytes, keyBytes := selfSignedCert(t, "localhost")
706 cas := x509.NewCertPool()
707 cas.AppendCertsFromPEM(certBytes)
708
709 tlsConfig := &tls.Config{
710 RootCAs: cas,
711 Certificates: []tls.Certificate{cert},
712 ClientAuth: tls.RequireAndVerifyClientCert,
713 ClientCAs: cas,
714 }
715
716 l, err := tls.Listen("tcp", "localhost:0", tlsConfig)
717 if err != nil {
718 t.Fatalf("net.Listen: got error %v, want no error", err)
719 }
720
721 donec := make(chan error, 1)
722 go func(donec chan<- error) {
723 donec <- http.Serve(l, nil)
724 }(donec)
725 defer func() {
726 if got, want := <-donec, closedError(); !strings.Contains(got.Error(), want) {
727 t.Fatalf("Serve got error %v, want %q", got, want)
728 }
729 }()
730 defer l.Close()
731
732 outputTempFile, err := os.CreateTemp("", "profile_output")
733 if err != nil {
734 t.Fatalf("Failed to create tempfile: %v", err)
735 }
736 defer os.Remove(outputTempFile.Name())
737 defer outputTempFile.Close()
738
739 // Get port from the address, so request to the server can be made using
740 // the host name specified in certificates.
741 _, portStr, err := net.SplitHostPort(l.Addr().String())
742 if err != nil {

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
homeEnvFunction · 0.85
currentConfigFunction · 0.85
setCurrentConfigFunction · 0.85
selfSignedCertFunction · 0.85
closedErrorFunction · 0.85
fetchProfilesFunction · 0.85
checkProfileHasFunctionFunction · 0.85
WriteMethod · 0.80
CloseMethod · 0.65
NameMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…