Skip to content

Commit

Permalink
Enable TestRequestAndBatch on windows (#1855)
Browse files Browse the repository at this point in the history
part of #902
  • Loading branch information
mstoykov committed Feb 15, 2021
1 parent a379c37 commit 1181117
Showing 1 changed file with 59 additions and 52 deletions.
111 changes: 59 additions & 52 deletions js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ func newRuntime(
}

func TestRequestAndBatch(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip()
}
t.Parallel()
tb, state, samples, rt, ctx := newRuntime(t)
defer tb.Cleanup()
Expand Down Expand Up @@ -519,55 +516,6 @@ func TestRequestAndBatch(t *testing.T) {
}
}
})
t.Run("TLS", func(t *testing.T) {
t.Run("cert_expired", func(t *testing.T) {
_, err := rt.RunString(`http.get("https://expired.badssl.com/");`)
require.Error(t, err)
assert.Contains(t, err.Error(), "x509: certificate has expired or is not yet valid")
})
tlsVersionTests := []struct {
Name, URL, Version string
}{
{Name: "tls10", URL: "https://tls-v1-0.badssl.com:1010/", Version: "http.TLS_1_0"},
{Name: "tls11", URL: "https://tls-v1-1.badssl.com:1011/", Version: "http.TLS_1_1"},
{Name: "tls12", URL: "https://badssl.com/", Version: "http.TLS_1_2"},
}
for _, versionTest := range tlsVersionTests {
t.Run(versionTest.Name, func(t *testing.T) {
_, err := rt.RunString(fmt.Sprintf(`
var res = http.get("%s");
if (res.tls_version != %s) { throw new Error("wrong TLS version: " + res.tls_version); }
`, versionTest.URL, versionTest.Version))
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", versionTest.URL, "", 200, "")
})
}
tlsCipherSuiteTests := []struct {
Name, URL, CipherSuite string
}{
{Name: "cipher_suite_cbc", URL: "https://cbc.badssl.com/", CipherSuite: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"},
{Name: "cipher_suite_ecc384", URL: "https://ecc384.badssl.com/", CipherSuite: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
}
for _, cipherSuiteTest := range tlsCipherSuiteTests {
t.Run(cipherSuiteTest.Name, func(t *testing.T) {
_, err := rt.RunString(fmt.Sprintf(`
var res = http.get("%s");
if (res.tls_cipher_suite != "%s") { throw new Error("wrong TLS cipher suite: " + res.tls_cipher_suite); }
`, cipherSuiteTest.URL, cipherSuiteTest.CipherSuite))
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", cipherSuiteTest.URL, "", 200, "")
})
}
t.Run("ocsp_stapled_good", func(t *testing.T) {
website := "https://www.wikipedia.org/"
_, err := rt.RunString(fmt.Sprintf(`
var res = http.request("GET", "%s");
if (res.ocsp.status != http.OCSP_STATUS_GOOD) { throw new Error("wrong ocsp stapled response status: " + res.ocsp.status); }
`, website))
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", website, "", 200, "")
})
})
t.Run("Invalid", func(t *testing.T) {
hook := logtest.NewLocal(state.Logger)
defer hook.Reset()
Expand Down Expand Up @@ -2117,6 +2065,65 @@ func TestErrorsWithDecompression(t *testing.T) {
assert.NoError(t, err)
}

func TestRequestAndBatchTLS(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip()
}
t.Parallel()
tb, _, samples, rt, _ := newRuntime(t)
defer tb.Cleanup()

t.Run("cert_expired", func(t *testing.T) {
_, err := rt.RunString(`http.get("https://expired.badssl.com/");`)
require.Error(t, err)
assert.Contains(t, err.Error(), "x509: certificate has expired or is not yet valid")
})
tlsVersionTests := []struct {
Name, URL, Version string
}{
{Name: "tls10", URL: "https://tls-v1-0.badssl.com:1010/", Version: "http.TLS_1_0"},
{Name: "tls11", URL: "https://tls-v1-1.badssl.com:1011/", Version: "http.TLS_1_1"},
{Name: "tls12", URL: "https://badssl.com/", Version: "http.TLS_1_2"},
}
for _, versionTest := range tlsVersionTests {
versionTest := versionTest
t.Run(versionTest.Name, func(t *testing.T) {
_, err := rt.RunString(fmt.Sprintf(`
var res = http.get("%s");
if (res.tls_version != %s) { throw new Error("wrong TLS version: " + res.tls_version); }
`, versionTest.URL, versionTest.Version))
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", versionTest.URL, "", 200, "")
})
}
tlsCipherSuiteTests := []struct {
Name, URL, CipherSuite string
}{
{Name: "cipher_suite_cbc", URL: "https://cbc.badssl.com/", CipherSuite: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"},
{Name: "cipher_suite_ecc384", URL: "https://ecc384.badssl.com/", CipherSuite: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
}
for _, cipherSuiteTest := range tlsCipherSuiteTests {
cipherSuiteTest := cipherSuiteTest
t.Run(cipherSuiteTest.Name, func(t *testing.T) {
_, err := rt.RunString(fmt.Sprintf(`
var res = http.get("%s");
if (res.tls_cipher_suite != "%s") { throw new Error("wrong TLS cipher suite: " + res.tls_cipher_suite); }
`, cipherSuiteTest.URL, cipherSuiteTest.CipherSuite))
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", cipherSuiteTest.URL, "", 200, "")
})
}
t.Run("ocsp_stapled_good", func(t *testing.T) {
website := "https://www.wikipedia.org/"
_, err := rt.RunString(fmt.Sprintf(`
var res = http.request("GET", "%s");
if (res.ocsp.status != http.OCSP_STATUS_GOOD) { throw new Error("wrong ocsp stapled response status: " + res.ocsp.status); }
`, website))
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", website, "", 200, "")
})
}

func TestDigestAuthWithBody(t *testing.T) {
t.Parallel()
tb, state, samples, rt, _ := newRuntime(t)
Expand Down

0 comments on commit 1181117

Please sign in to comment.