MCPcopy
hub / github.com/grafana/k6 / TestRequestAndBatchTLS

Function TestRequestAndBatchTLS

js/modules/k6/http/request_test.go:2082–2239  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2080}
2081
2082func 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":

Callers

nothing calls this directly

Calls 15

NewHostFunction · 0.92
NewHostsFunction · 0.92
GetBufferedSamplesFunction · 0.92
newTestCaseFunction · 0.85
GenerateTLSCertificateFunction · 0.85
RunMethod · 0.65
RuntimeMethod · 0.65
StateMethod · 0.65
AddMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…