(t *testing.T)
| 2080 | } |
| 2081 | |
| 2082 | func TestRequestAndBatchTLS(t *testing.T) { |
| 2083 | t.Parallel() |
| 2084 | |
| 2085 | t.Run("cert_expired", func(t *testing.T) { |
| 2086 | t.Parallel() |
| 2087 | ts := newTestCase(t) |
| 2088 | rt := ts.runtime.VU.Runtime() |
| 2089 | state := ts.runtime.VU.State() |
| 2090 | |
| 2091 | cert, key := GenerateTLSCertificate(t, "expired.localhost", time.Now().Add(-time.Hour), 0) |
| 2092 | s, client := GetTestServerWithCertificate(t, cert, key) |
| 2093 | go func() { |
| 2094 | _ = s.Config.Serve(s.Listener) |
| 2095 | }() |
| 2096 | t.Cleanup(func() { |
| 2097 | require.NoError(t, s.Config.Close()) |
| 2098 | }) |
| 2099 | host, port, err := net.SplitHostPort(s.Listener.Addr().String()) |
| 2100 | require.NoError(t, err) |
| 2101 | ip := net.ParseIP(host) |
| 2102 | mybadsslHostname, err := types.NewHost(ip, port) |
| 2103 | require.NoError(t, err) |
| 2104 | state.Transport = client.Transport |
| 2105 | state.TLSConfig = s.TLS |
| 2106 | state.Dialer = &netext.Dialer{ |
| 2107 | Hosts: func() *types.Hosts { |
| 2108 | hosts, er := types.NewHosts(map[string]types.Host{"expired.localhost": *mybadsslHostname}) |
| 2109 | require.NoError(t, er) |
| 2110 | return hosts |
| 2111 | }(), |
| 2112 | } |
| 2113 | client.Transport.(*http.Transport).DialContext = state.Dialer.DialContext |
| 2114 | _, err = rt.RunString(`throw JSON.stringify(http.get("https://expired.localhost/"));`) |
| 2115 | require.Error(t, err) |
| 2116 | assert.Contains(t, err.Error(), "x509: certificate has expired or is not yet valid") |
| 2117 | }) |
| 2118 | tlsVersionTests := []struct { |
| 2119 | Name, URL, Version string |
| 2120 | }{ |
| 2121 | {Name: "tls10", URL: "tlsv10.localhost", Version: "http.TLS_1_0"}, |
| 2122 | {Name: "tls11", URL: "tlsv11.localhost", Version: "http.TLS_1_1"}, |
| 2123 | {Name: "tls12", URL: "tlsv12.localhost", Version: "http.TLS_1_2"}, |
| 2124 | } |
| 2125 | for _, versionTest := range tlsVersionTests { |
| 2126 | t.Run(versionTest.Name, func(t *testing.T) { |
| 2127 | t.Parallel() |
| 2128 | ts := newTestCase(t) |
| 2129 | samples := ts.samples |
| 2130 | rt := ts.runtime.VU.Runtime() |
| 2131 | state := ts.runtime.VU.State() |
| 2132 | |
| 2133 | cert, key := GenerateTLSCertificate(t, versionTest.URL, time.Now(), time.Hour) |
| 2134 | s, client := GetTestServerWithCertificate(t, cert, key) |
| 2135 | |
| 2136 | switch versionTest.Name { |
| 2137 | case "tls10": |
| 2138 | s.TLS.MaxVersion = tls.VersionTLS10 |
| 2139 | case "tls11": |
nothing calls this directly
no test coverage detected
searching dependent graphs…