From 3d55b1df5d7bb79aa5e1cc73b69192273bb092ba Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 30 Apr 2020 19:26:14 +0300 Subject: [PATCH] Introduce RunES6String and replace RunString to not support ES6 this should again lower the amount of time test take for close to zero additional scripting. --- js/common/bridge_test.go | 12 +- js/common/util.go | 9 +- js/common/util_test.go | 4 +- js/modules/k6/crypto/crypto_test.go | 128 ++++++------ js/modules/k6/crypto/x509/x509_test.go | 213 ++++++++++---------- js/modules/k6/encoding/encoding_test.go | 48 ++--- js/modules/k6/html/element_test.go | 2 +- js/modules/k6/html/elements_gen_test.go | 4 +- js/modules/k6/html/elements_test.go | 4 +- js/modules/k6/html/html_test.go | 2 +- js/modules/k6/html/serialize_test.go | 2 +- js/modules/k6/http/http_test.go | 2 +- js/modules/k6/http/request_test.go | 250 ++++++++++++------------ js/modules/k6/http/response_test.go | 48 ++--- js/modules/k6/http/tls_test.go | 2 +- js/modules/k6/k6_test.go | 10 +- js/modules/k6/metrics/metrics_test.go | 2 +- js/modules/k6/ws/ws_test.go | 56 +++--- 18 files changed, 399 insertions(+), 399 deletions(-) diff --git a/js/common/bridge_test.go b/js/common/bridge_test.go index be2fef15ff4..4ce64637370 100644 --- a/js/common/bridge_test.go +++ b/js/common/bridge_test.go @@ -324,7 +324,7 @@ func TestBind(t *testing.T) { {"Methods", bridgeTestMethodsType{}, func(t *testing.T, obj interface{}, rt *goja.Runtime) { t.Run("unexportedFn", func(t *testing.T) { _, err := RunString(rt, `obj.unexportedFn()`) - assert.EqualError(t, err, "TypeError: Object has no member 'unexportedFn' at :1:30(3)") + assert.EqualError(t, err, "TypeError: Object has no member 'unexportedFn' at :1:17(3)") }) t.Run("ExportedFn", func(t *testing.T) { _, err := RunString(rt, `obj.exportedFn()`) @@ -332,7 +332,7 @@ func TestBind(t *testing.T) { }) t.Run("unexportedPtrFn", func(t *testing.T) { _, err := RunString(rt, `obj.unexportedPtrFn()`) - assert.EqualError(t, err, "TypeError: Object has no member 'unexportedPtrFn' at :1:33(3)") + assert.EqualError(t, err, "TypeError: Object has no member 'unexportedPtrFn' at :1:20(3)") }) t.Run("ExportedPtrFn", func(t *testing.T) { _, err := RunString(rt, `obj.exportedPtrFn()`) @@ -340,7 +340,7 @@ func TestBind(t *testing.T) { case *bridgeTestMethodsType: assert.NoError(t, err) case bridgeTestMethodsType: - assert.EqualError(t, err, "TypeError: Object has no member 'exportedPtrFn' at :1:31(3)") + assert.EqualError(t, err, "TypeError: Object has no member 'exportedPtrFn' at :1:18(3)") default: assert.Fail(t, "INVALID TYPE") } @@ -527,7 +527,7 @@ func TestBind(t *testing.T) { _, err := RunString(rt, `obj.contextInject()`) switch impl := obj.(type) { case bridgeTestContextInjectType: - assert.EqualError(t, err, "TypeError: Object has no member 'contextInject' at :1:31(3)") + assert.EqualError(t, err, "TypeError: Object has no member 'contextInject' at :1:18(3)") case *bridgeTestContextInjectType: assert.EqualError(t, err, "GoError: contextInject() can only be called from within default()") assert.Equal(t, nil, impl.ctx) @@ -546,7 +546,7 @@ func TestBind(t *testing.T) { _, err := RunString(rt, `obj.contextInjectPtr()`) switch impl := obj.(type) { case bridgeTestContextInjectPtrType: - assert.EqualError(t, err, "TypeError: Object has no member 'contextInjectPtr' at :1:34(3)") + assert.EqualError(t, err, "TypeError: Object has no member 'contextInjectPtr' at :1:21(3)") case *bridgeTestContextInjectPtrType: assert.NoError(t, err) assert.Equal(t, ctxPtr, impl.ctxPtr) @@ -566,7 +566,7 @@ func TestBind(t *testing.T) { } case bridgeTestCounterType: _, err := RunString(rt, `obj.count()`) - assert.EqualError(t, err, "TypeError: Object has no member 'count' at :1:23(3)") + assert.EqualError(t, err, "TypeError: Object has no member 'count' at :1:10(3)") default: assert.Fail(t, "UNKNOWN TYPE") } diff --git a/js/common/util.go b/js/common/util.go index 397633bed45..aa986c0f7e0 100644 --- a/js/common/util.go +++ b/js/common/util.go @@ -25,15 +25,20 @@ import ( "github.com/loadimpact/k6/js/compiler" ) -// Runs an ES6 string in the given runtime. Use this rather than writing ES5 in tests. +// RunString Runs an string in the given runtime. Use this if writing ES5 in tests isn't a problem. func RunString(rt *goja.Runtime, src string) (goja.Value, error) { + return rt.RunString(src) +} + +// RunES6String Runs an ES6 string in the given runtime. Use this rather than writing ES5 in tests. +func RunES6String(rt *goja.Runtime, src string) (goja.Value, error) { var err error c := compiler.New() src, _, err = c.Transform(src, "__string__") if err != nil { return goja.Undefined(), err } - return rt.RunString(src) + return RunString(rt, src) } // Throws a JS error; avoids re-wrapping GoErrors. diff --git a/js/common/util_test.go b/js/common/util_test.go index f99c242ef15..3d35d418f0c 100644 --- a/js/common/util_test.go +++ b/js/common/util_test.go @@ -30,11 +30,11 @@ import ( func TestRunString(t *testing.T) { t.Run("Valid", func(t *testing.T) { - _, err := RunString(goja.New(), `let a = 1;`) + _, err := RunES6String(goja.New(), `let a = 1;`) assert.NoError(t, err) }) t.Run("Invalid", func(t *testing.T) { - _, err := RunString(goja.New(), `let a = #;`) + _, err := RunES6String(goja.New(), `let a = #;`) assert.NotNil(t, err) assert.Contains(t, err.Error(), "SyntaxError: __string__: Unexpected character '#' (1:8)\n> 1 | let a = #;\n") }) diff --git a/js/modules/k6/crypto/crypto_test.go b/js/modules/k6/crypto/crypto_test.go index c6098aeef1f..384f8987dd2 100644 --- a/js/modules/k6/crypto/crypto_test.go +++ b/js/modules/k6/crypto/crypto_test.go @@ -51,7 +51,7 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("RandomBytesSuccess", func(t *testing.T) { _, err := common.RunString(rt, ` - let bytes = crypto.randomBytes(5); + var bytes = crypto.randomBytes(5); if (bytes.length !== 5) { throw new Error("Incorrect size: " + bytes.length); }`) @@ -78,8 +78,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("MD4", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "aa010fbc1d14c795d86ef98c95479d17"; - let hash = crypto.md4("hello world", "hex"); + var correct = "aa010fbc1d14c795d86ef98c95479d17"; + var hash = crypto.md4("hello world", "hex"); if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -88,8 +88,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("MD5", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "5eb63bbbe01eeed093cb22bb8f5acdc3"; - let hash = crypto.md5("hello world", "hex"); + var correct = "5eb63bbbe01eeed093cb22bb8f5acdc3"; + var hash = crypto.md5("hello world", "hex"); if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -99,8 +99,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("SHA1", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"; - let hash = crypto.sha1("hello world", "hex"); + var correct = "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"; + var hash = crypto.sha1("hello world", "hex"); if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -110,8 +110,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("SHA256", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"; - let hash = crypto.sha256("hello world", "hex"); + var correct = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"; + var hash = crypto.sha256("hello world", "hex"); if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -121,8 +121,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("SHA384", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd"; - let hash = crypto.sha384("hello world", "hex"); + var correct = "fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd"; + var hash = crypto.sha384("hello world", "hex"); if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -132,8 +132,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("SHA512", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f"; - let hash = crypto.sha512("hello world", "hex"); + var correct = "309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f"; + var hash = crypto.sha512("hello world", "hex"); if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -143,8 +143,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("SHA512_224", func(t *testing.T) { _, err := common.RunString(rt, ` - let hash = crypto.sha512_224("hello world", "hex"); - const correct = "22e0d52336f64a998085078b05a6e37b26f8120f43bf4db4c43a64ee"; + var hash = crypto.sha512_224("hello world", "hex"); + var correct = "22e0d52336f64a998085078b05a6e37b26f8120f43bf4db4c43a64ee"; if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -154,8 +154,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("SHA512_256", func(t *testing.T) { _, err := common.RunString(rt, ` - let hash = crypto.sha512_256("hello world", "hex"); - const correct = "0ac561fac838104e3f2e4ad107b4bee3e938bf15f2b15f009ccccd61a913f017"; + var hash = crypto.sha512_256("hello world", "hex"); + var correct = "0ac561fac838104e3f2e4ad107b4bee3e938bf15f2b15f009ccccd61a913f017"; if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -165,8 +165,8 @@ func TestCryptoAlgorithms(t *testing.T) { t.Run("RIPEMD160", func(t *testing.T) { _, err := common.RunString(rt, ` - let hash = crypto.ripemd160("hello world", "hex"); - const correct = "98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"; + var hash = crypto.ripemd160("hello world", "hex"); + var correct = "98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"; if (hash !== correct) { throw new Error("Hash mismatch: " + hash); }`) @@ -195,11 +195,11 @@ func TestStreamingApi(t *testing.T) { // Empty strings are still hashable t.Run("Empty", func(t *testing.T) { _, err := common.RunString(rt, ` - const correctHex = "d41d8cd98f00b204e9800998ecf8427e"; + var correctHex = "d41d8cd98f00b204e9800998ecf8427e"; - let hasher = crypto.createHash("md5"); + var hasher = crypto.createHash("md5"); - const resultHex = hasher.digest("hex"); + var resultHex = hasher.digest("hex"); if (resultHex !== correctHex) { throw new Error("Hex encoding mismatch: " + resultHex); }`) @@ -209,12 +209,12 @@ func TestStreamingApi(t *testing.T) { t.Run("UpdateOnce", func(t *testing.T) { _, err := common.RunString(rt, ` - const correctHex = "5eb63bbbe01eeed093cb22bb8f5acdc3"; + var correctHex = "5eb63bbbe01eeed093cb22bb8f5acdc3"; - let hasher = crypto.createHash("md5"); + var hasher = crypto.createHash("md5"); hasher.update("hello world"); - const resultHex = hasher.digest("hex"); + var resultHex = hasher.digest("hex"); if (resultHex !== correctHex) { throw new Error("Hex encoding mismatch: " + resultHex); }`) @@ -224,14 +224,14 @@ func TestStreamingApi(t *testing.T) { t.Run("UpdateMultiple", func(t *testing.T) { _, err := common.RunString(rt, ` - const correctHex = "5eb63bbbe01eeed093cb22bb8f5acdc3"; + var correctHex = "5eb63bbbe01eeed093cb22bb8f5acdc3"; - let hasher = crypto.createHash("md5"); + var hasher = crypto.createHash("md5"); hasher.update("hello"); hasher.update(" "); hasher.update("world"); - const resultHex = hasher.digest("hex"); + var resultHex = hasher.digest("hex"); if (resultHex !== correctHex) { throw new Error("Hex encoding mismatch: " + resultHex); }`) @@ -259,31 +259,31 @@ func TestOutputEncoding(t *testing.T) { t.Run("Valid", func(t *testing.T) { _, err := common.RunString(rt, ` - const correctHex = "5eb63bbbe01eeed093cb22bb8f5acdc3"; - const correctBase64 = "XrY7u+Ae7tCTyyK7j1rNww=="; - const correctBase64URL = "XrY7u-Ae7tCTyyK7j1rNww==" - const correctBase64RawURL = "XrY7u-Ae7tCTyyK7j1rNww"; - const correctBinary = [94,182,59,187,224,30,238,208,147,203,34,187,143,90,205,195]; + var correctHex = "5eb63bbbe01eeed093cb22bb8f5acdc3"; + var correctBase64 = "XrY7u+Ae7tCTyyK7j1rNww=="; + var correctBase64URL = "XrY7u-Ae7tCTyyK7j1rNww==" + var correctBase64RawURL = "XrY7u-Ae7tCTyyK7j1rNww"; + var correctBinary = [94,182,59,187,224,30,238,208,147,203,34,187,143,90,205,195]; - let hasher = crypto.createHash("md5"); + var hasher = crypto.createHash("md5"); hasher.update("hello world"); - const resultHex = hasher.digest("hex"); + var resultHex = hasher.digest("hex"); if (resultHex !== correctHex) { throw new Error("Hex encoding mismatch: " + resultHex); } - const resultBase64 = hasher.digest("base64"); + var resultBase64 = hasher.digest("base64"); if (resultBase64 !== correctBase64) { throw new Error("Base64 encoding mismatch: " + resultBase64); } - const resultBase64URL = hasher.digest("base64url"); + var resultBase64URL = hasher.digest("base64url"); if (resultBase64URL !== correctBase64URL) { throw new Error("Base64 URL encoding mismatch: " + resultBase64URL); } - const resultBase64RawURL = hasher.digest("base64rawurl"); + var resultBase64RawURL = hasher.digest("base64rawurl"); if (resultBase64RawURL !== correctBase64RawURL) { throw new Error("Base64 raw URL encoding mismatch: " + resultBase64RawURL); } @@ -300,7 +300,7 @@ func TestOutputEncoding(t *testing.T) { return true; } - const resultBinary = hasher.digest("binary"); + var resultBinary = hasher.digest("binary"); if (!arraysEqual(resultBinary, correctBinary)) { throw new Error("Binary encoding mismatch: " + JSON.stringify(resultBinary)); } @@ -311,7 +311,7 @@ func TestOutputEncoding(t *testing.T) { t.Run("Invalid", func(t *testing.T) { _, err := common.RunString(rt, ` - let hasher = crypto.createHash("md5"); + var hasher = crypto.createHash("md5"); hasher.update("hello world"); hasher.digest("someInvalidEncoding"); `) @@ -352,10 +352,10 @@ func TestHMac(t *testing.T) { rt.Set("algorithm", rt.ToValue(algorithm)) t.Run(algorithm+" hasher: valid", func(t *testing.T) { _, err := common.RunString(rt, ` - let hasher = crypto.createHMAC(algorithm, "a secret"); + var hasher = crypto.createHMAC(algorithm, "a secret"); hasher.update("some data to hash"); - const resultHex = hasher.digest("hex"); + var resultHex = hasher.digest("hex"); if (resultHex !== correctHex) { throw new Error("Hex encoding mismatch: " + resultHex); }`) @@ -365,7 +365,7 @@ func TestHMac(t *testing.T) { t.Run(algorithm+" wrapper: valid", func(t *testing.T) { _, err := common.RunString(rt, ` - let resultHex = crypto.hmac(algorithm, "a secret", "some data to hash", "hex"); + var resultHex = crypto.hmac(algorithm, "a secret", "some data to hash", "hex"); if (resultHex !== correctHex) { throw new Error("Hex encoding mismatch: " + resultHex); }`) @@ -385,10 +385,10 @@ func TestHMac(t *testing.T) { rt.Set("algorithm", rt.ToValue(algorithm)) t.Run(algorithm+" hasher: invalid", func(t *testing.T) { _, err := common.RunString(rt, ` - let hasher = crypto.createHMAC(algorithm, "a secret"); + var hasher = crypto.createHMAC(algorithm, "a secret"); hasher.update("some data to hash"); - const resultHex = hasher.digest("hex"); + var resultHex = hasher.digest("hex"); if (resultHex !== correctHex) { throw new Error("Hex encoding mismatch: " + resultHex); }`) @@ -398,7 +398,7 @@ func TestHMac(t *testing.T) { t.Run(algorithm+" wrapper: invalid", func(t *testing.T) { _, err := common.RunString(rt, ` - let resultHex = crypto.hmac(algorithm, "a secret", "some data to hash", "hex"); + var resultHex = crypto.hmac(algorithm, "a secret", "some data to hash", "hex"); if (resultHex !== correctHex) { throw new Error("Hex encoding mismatch: " + resultHex); }`) @@ -417,40 +417,40 @@ func TestAWSv4(t *testing.T) { rt.Set("crypto", common.Bind(rt, New(), &ctx)) _, err := common.RunString(rt, ` - let HexEncode = crypto.hexEncode; - let HmacSHA256 = function(data, key) { + var HexEncode = crypto.hexEncode; + var HmacSHA256 = function(data, key) { return crypto.hmac("sha256",key, data, "binary"); }; - let expectedKDate = '969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d' - let expectedKRegion = '69daa0209cd9c5ff5c8ced464a696fd4252e981430b10e3d3fd8e2f197d7a70c' - let expectedKService = 'f72cfd46f26bc4643f06a11eabb6c0ba18780c19a8da0c31ace671265e3c87fa' - let expectedKSigning = 'f4780e2d9f65fa895f9c67b32ce1baf0b0d8a43505a000a1a9e090d414db404d' + var expectedKDate = '969fbb94feb542b71ede6f87fe4d5fa29c789342b0f407474670f0c2489e0a0d' + var expectedKRegion = '69daa0209cd9c5ff5c8ced464a696fd4252e981430b10e3d3fd8e2f197d7a70c' + var expectedKService = 'f72cfd46f26bc4643f06a11eabb6c0ba18780c19a8da0c31ace671265e3c87fa' + var expectedKSigning = 'f4780e2d9f65fa895f9c67b32ce1baf0b0d8a43505a000a1a9e090d414db404d' - let key = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'; - let dateStamp = '20120215'; - let regionName = 'us-east-1'; - let serviceName = 'iam'; + var key = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'; + var dateStamp = '20120215'; + var regionName = 'us-east-1'; + var serviceName = 'iam'; - let kDate = HmacSHA256(dateStamp, "AWS4" + key); - let kRegion = HmacSHA256(regionName, kDate); - let kService = HmacSHA256(serviceName, kRegion); - let kSigning = HmacSHA256("aws4_request", kService); + var kDate = HmacSHA256(dateStamp, "AWS4" + key); + var kRegion = HmacSHA256(regionName, kDate); + var kService = HmacSHA256(serviceName, kRegion); + var kSigning = HmacSHA256("aws4_request", kService); - let hexKDate = HexEncode(kDate); + var hexKDate = HexEncode(kDate); if (expectedKDate != hexKDate) { throw new Error("Wrong kDate: expected '" + expectedKDate + "' got '" + hexKDate + "'"); } - let hexKRegion = HexEncode(kRegion); + var hexKRegion = HexEncode(kRegion); if (expectedKRegion != hexKRegion) { throw new Error("Wrong kRegion: expected '" + expectedKRegion + "' got '" + hexKRegion + "'"); } - let hexKService = HexEncode(kService); + var hexKService = HexEncode(kService); if (expectedKService != hexKService) { throw new Error("Wrong kService: expected '" + expectedKService + "' got '" + hexKService + "'"); } - let hexKSigning = HexEncode(kSigning); + var hexKSigning = HexEncode(kSigning); if (expectedKSigning != hexKSigning) { throw new Error("Wrong kSigning: expected '" + expectedKSigning + "' got '" + hexKSigning + "'"); } diff --git a/js/modules/k6/crypto/x509/x509_test.go b/js/modules/k6/crypto/x509/x509_test.go index d35912f4bf4..18d8712bb31 100644 --- a/js/modules/k6/crypto/x509/x509_test.go +++ b/js/modules/k6/crypto/x509/x509_test.go @@ -24,7 +24,6 @@ import ( "context" gox509 "crypto/x509" "fmt" - "strings" "testing" "github.com/dop251/goja" @@ -49,7 +48,7 @@ type Material struct { } var material = Material{ //nolint:gochecknoglobals - dsaCertificate: template(`-----BEGIN CERTIFICATE----- + dsaCertificate: `-----BEGIN CERTIFICATE----- MIIFnzCCBUSgAwIBAgIJAPOE4rArGHVcMAsGCWCGSAFlAwQDAjCBsTELMAkGA1UE BhMCWloxGTAXBgNVBAgMEEtvcHVuY2V6aXMgS3JhaXMxETAPBgNVBAcMCEFzaHRp bm9rMRwwGgYDVQQKDBNFeHVtYnJhbiBDb252ZW50aW9uMRkwFwYDVQQLDBBFeHVt @@ -81,8 +80,8 @@ JqGGJU+MCQZEoTAfBgNVHSMEGDAWgBSSb364iDHRI6/2JqGGJU+MCQZEoTAPBgNV HRMBAf8EBTADAQH/MAsGCWCGSAFlAwQDAgNIADBFAiEA1nr63IX9aaGUPeOUC0Bh w3Y7mpv5+sVgtoIi8ljxVSICIFCpEl70YjRVIUKL8N/lJwKxisrJ4+Xxg/DIeGP8 L8GA ------END CERTIFICATE-----`), - ecdsaCertificate: template(`-----BEGIN CERTIFICATE----- +-----END CERTIFICATE-----`, + ecdsaCertificate: `-----BEGIN CERTIFICATE----- MIIDXjCCAwWgAwIBAgICBNIwCgYIKoZIzj0EAwIwgdsxCzAJBgNVBAYTAlpaMRkw FwYDVQQIExBLb3B1bmNlemlzIEtyYWlzMREwDwYDVQQHEwhBc2h0aW5vazEaMBgG A1UECRMRMjIxQiBCYWtlciBTdHJlZXQxDjAMBgNVBBETBTk5OTk5MRwwGgYDVQQK @@ -102,8 +101,8 @@ Ly9wcmVzcy5leGNvdW5jaWwuenqGJ2h0dHA6Ly9sZWFybmluZy5leGNvdW5jaWwu enovaW5kZXguaHRtbDAKBggqhkjOPQQDAgNHADBEAiA/X4Y+Zaw4ziqL4grkY+rm srWfS/JGxLvN49r68cczSwIgWEXFIHMwE+OhKC6z01mIPe2G2CguYHukWyL+BHtT +20= ------END CERTIFICATE-----`), - rsaCertificate: template(`-----BEGIN CERTIFICATE----- +-----END CERTIFICATE-----`, + rsaCertificate: `-----BEGIN CERTIFICATE----- MIIE6zCCA9OgAwIBAgICBNIwDQYJKoZIhvcNAQELBQAwgdsxCzAJBgNVBAYTAlpa MRkwFwYDVQQIExBLb3B1bmNlemlzIEtyYWlzMREwDwYDVQQHEwhBc2h0aW5vazEa MBgGA1UECRMRMjIxQiBCYWtlciBTdHJlZXQxDjAMBgNVBBETBTk5OTk5MRwwGgYD @@ -131,17 +130,13 @@ gzg3dNaCY65aH0cJE/dVwiS/F2XTr1zvr+uBPExgrA21+FSIlHM0Dot+VGKdCLEO 6HugOCDBdzKF2hsHeI5LvgXUX5zQ0gnsd93+QuxUmiN7QZZs8tDMD/+efo4OWvp/ xytSVXVn+cECQLg9hVn+Zx3XO2FA0eOzaWEONnUGghT/Ivw06lUxis5tkAoAU93d ddBqJe0XUeAX8Zr6EJ82 ------END CERTIFICATE-----`), - publicKey: template(`-----BEGIN PUBLIC KEY----- +-----END CERTIFICATE-----`, + publicKey: `-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXMLr/Y/vUtIFY75jj0YXfp6lQ 7iEIbps3BvRE4isTpxs8fXLnLM8LAuJScxiKyrGnj8EMb7LIHkSMBlz6iVj9atY6 EUEm/VHUnElNquzGyBA50TCfpv6NHPaTvOoB45yQbZ/YB4LO+CsT9eIMDZ4tcU9Z +xD10ifJhhIwpZUFIQIDAQAB ------END PUBLIC KEY-----`), -} - -func template(value string) string { - return fmt.Sprintf("`%s`", value) +-----END PUBLIC KEY-----`, } func TestParse(t *testing.T) { @@ -159,21 +154,21 @@ func TestParse(t *testing.T) { t.Run("ParseFailure", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; + var pem = %q; x509.parse(pem);`, material.publicKey)) if assert.Error(t, err) { - assert.True(t, strings.HasPrefix( + assert.Contains(t, err.Error(), "GoError: failed to parse certificate", - )) + ) } }) t.Run("SignatureAlgorithm", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.signatureAlgorithm; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.signatureAlgorithm; if (value !== "SHA256-RSA") { throw new Error("Bad signature algorithm: " + value); }`, material.rsaCertificate)) @@ -182,8 +177,8 @@ func TestParse(t *testing.T) { t.Run("Subject", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); + var pem = %q; + var cert = x509.parse(pem); if (typeof cert.subject !== "object") { throw new Error("Bad subject: " + typeof cert.subject); }`, material.rsaCertificate)) @@ -192,9 +187,9 @@ func TestParse(t *testing.T) { t.Run("SubjectCommonName", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.subject ? cert.subject.commonName : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.subject ? cert.subject.commonName : null; if (value !== "excouncil.zz") { throw new Error("Bad subject common name: " + value); }`, material.rsaCertificate)) @@ -203,9 +198,9 @@ func TestParse(t *testing.T) { t.Run("SubjectCountry", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.subject ? cert.subject.country : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.subject ? cert.subject.country : null; if (value !== "ZZ") { throw new Error("Bad subject country: " + value); }`, material.rsaCertificate)) @@ -214,9 +209,9 @@ func TestParse(t *testing.T) { t.Run("SubjectPostalCode", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.subject ? cert.subject.postalCode : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.subject ? cert.subject.postalCode : null; if (value !== "99999") { throw new Error("Bad subject postal code: " + value); }`, material.rsaCertificate)) @@ -225,9 +220,9 @@ func TestParse(t *testing.T) { t.Run("SubjectProvince", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.subject ? cert.subject.stateOrProvinceName : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.subject ? cert.subject.stateOrProvinceName : null; if (value !== "Kopuncezis Krais") { throw new Error("Bad subject province: " + value); }`, material.rsaCertificate)) @@ -236,9 +231,9 @@ func TestParse(t *testing.T) { t.Run("SubjectLocality", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.subject ? cert.subject.localityName : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.subject ? cert.subject.localityName : null; if (value !== "Ashtinok") { throw new Error("Bad subject locality: " + value); }`, material.rsaCertificate)) @@ -247,9 +242,9 @@ func TestParse(t *testing.T) { t.Run("SubjectStreetAddress", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.subject ? cert.subject.streetAddress : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.subject ? cert.subject.streetAddress : null; if (value !== "221B Baker Street") { throw new Error("Bad subject street address: " + value); }`, material.rsaCertificate)) @@ -258,9 +253,9 @@ func TestParse(t *testing.T) { t.Run("SubjectOrganization", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.subject ? cert.subject.organizationName : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.subject ? cert.subject.organizationName : null; if (value !== "Exumbran Convention") { throw new Error("Bad subject organization: " + value); }`, material.rsaCertificate)) @@ -269,9 +264,9 @@ func TestParse(t *testing.T) { t.Run("SubjectOrganizationalUnit", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const values = + var pem = %q; + var cert = x509.parse(pem); + var values = cert.subject ? cert.subject.organizationalUnitName : null; if (!( values.length === 2 && @@ -287,11 +282,11 @@ func TestParse(t *testing.T) { t.Run("SubjectNames", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const values = cert.subject ? cert.subject.names : null; - const strings = values - ? values.map(entry => entry.type + ": " + entry.value) + var pem = %q; + var cert = x509.parse(pem); + var values = cert.subject ? cert.subject.names : null; + var strings = values + ? values.map(function(entry) { return entry.type + ": " + entry.value}) : null; Array.prototype.includes = function (value) { return this.indexOf(value) !== -1 } @@ -316,8 +311,8 @@ func TestParse(t *testing.T) { t.Run("Issuer", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); + var pem = %q; + var cert = x509.parse(pem); if (typeof cert.issuer !== "object") { throw new Error("Bad issuer: " + typeof cert.issuer); }`, material.rsaCertificate)) @@ -326,9 +321,9 @@ func TestParse(t *testing.T) { t.Run("IssuerCommonName", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.issuer ? cert.issuer.commonName : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.issuer ? cert.issuer.commonName : null; if (value !== "excouncil.zz") { throw new Error("Bad issuer common name: " + value); }`, material.rsaCertificate)) @@ -337,9 +332,9 @@ func TestParse(t *testing.T) { t.Run("IssuerCountry", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.issuer ? cert.issuer.country : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.issuer ? cert.issuer.country : null; if (value !== "ZZ") { throw new Error("Bad issuer country: " + value); }`, material.rsaCertificate)) @@ -348,9 +343,9 @@ func TestParse(t *testing.T) { t.Run("IssuerProvince", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.issuer ? cert.issuer.stateOrProvinceName : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.issuer ? cert.issuer.stateOrProvinceName : null; if (value !== "Kopuncezis Krais") { throw new Error("Bad issuer province: " + value); }`, material.rsaCertificate)) @@ -359,9 +354,9 @@ func TestParse(t *testing.T) { t.Run("IssuerLocality", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.issuer ? cert.issuer.localityName : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.issuer ? cert.issuer.localityName : null; if (value !== "Ashtinok") { throw new Error("Bad issuer locality: " + value); }`, material.rsaCertificate)) @@ -370,9 +365,9 @@ func TestParse(t *testing.T) { t.Run("IssuerOrganization", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.issuer ? cert.issuer.organizationName : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.issuer ? cert.issuer.organizationName : null; if (value !== "Exumbran Convention") { throw new Error("Bad issuer organization: " + value); }`, material.rsaCertificate)) @@ -381,11 +376,11 @@ func TestParse(t *testing.T) { t.Run("IssuerNames", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const values = cert.issuer ? cert.issuer.names : null; - const strings = values - ? values.map(entry => entry.type + ": " + entry.value) + var pem = %q; + var cert = x509.parse(pem); + var values = cert.issuer ? cert.issuer.names : null; + var strings = values + ? values.map(function(entry) { return entry.type + ": " + entry.value}) : null; Array.prototype.includes = function (value) { return this.indexOf(value) !== -1 } @@ -410,9 +405,9 @@ func TestParse(t *testing.T) { t.Run("NotBefore", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.notBefore; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.notBefore; if (value !== "2019-01-01T00:00:00Z") { throw new Error("Bad lower bound: " + value) }`, material.rsaCertificate)) @@ -421,9 +416,9 @@ func TestParse(t *testing.T) { t.Run("NotAfter", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.notAfter; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.notAfter; if (value !== "2020-01-01T00:00:00Z") { throw new Error("Bad upper bound: " + value); }`, material.rsaCertificate)) @@ -432,9 +427,9 @@ func TestParse(t *testing.T) { t.Run("AltNames", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const values = cert.altNames; + var pem = %q; + var cert = x509.parse(pem); + var values = cert.altNames; if (!( values.length === 8 && values[0] === "council.exumbran.zz" && @@ -453,10 +448,10 @@ func TestParse(t *testing.T) { t.Run("FingerPrint", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.fingerPrint; - const expected = [ + var pem = %q; + var cert = x509.parse(pem); + var value = cert.fingerPrint; + var expected = [ 85, 119, 3, 199, 150, 144, 202, 145, 178, 46, 205, 132, 37, 235, 251, 208, 139, 161, 143, 14 ] @@ -468,8 +463,8 @@ func TestParse(t *testing.T) { t.Run("PublicKey", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); + var pem = %q; + var cert = x509.parse(pem); if (typeof cert.publicKey !== "object") { throw new Error("Bad public key: " + typeof cert.publicKey); }`, material.rsaCertificate)) @@ -478,9 +473,9 @@ func TestParse(t *testing.T) { t.Run("RSAPublicKey", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.publicKey; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.publicKey; if (!( value && typeof value === "object" && @@ -496,9 +491,9 @@ func TestParse(t *testing.T) { t.Run("RSAPublicKeyExponent", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.publicKey ? cert.publicKey.key.e : null; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.publicKey ? cert.publicKey.key.e : null; if (value !== 65537) { throw new Error("Bad RSA public key exponent: " + value); }`, material.rsaCertificate)) @@ -507,10 +502,10 @@ func TestParse(t *testing.T) { t.Run("RSAPublicKeyModulus", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.publicKey ? cert.publicKey.key.n.bytes() : null; - const expected = [ + var pem = %q; + var cert = x509.parse(pem); + var value = cert.publicKey ? cert.publicKey.key.n.bytes() : null; + var expected = [ 223, 249, 234, 71, 180, 36, 28, 62, 84, 141, 177, 118, 53, 2, 175, 45, 167, 89, 155, 216, 103, 86, 32, 216, 42, 92, 84, 125, 183, 102, 217, 40, 255, 129, 38, 203, 175, 98, 209, 147, 151, 106, 250, 12, @@ -538,9 +533,9 @@ func TestParse(t *testing.T) { t.Run("DSAPublicKey", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.publicKey; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.publicKey; if (!( value && typeof value === "object" && @@ -555,9 +550,9 @@ func TestParse(t *testing.T) { t.Run("ECDSAPublicKey", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const cert = x509.parse(pem); - const value = cert.publicKey; + var pem = %q; + var cert = x509.parse(pem); + var value = cert.publicKey; if (!( value && typeof value === "object" && @@ -586,8 +581,8 @@ func TestGetAltNames(t *testing.T) { t.Run("Success", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const altNames = x509.getAltNames(pem); + var pem = %q; + var altNames = x509.getAltNames(pem); if (!( Array.isArray(altNames) && altNames.length === 8 && @@ -620,8 +615,8 @@ func TestGetIssuer(t *testing.T) { t.Run("Success", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const issuer = x509.getIssuer(pem); + var pem = %q; + var issuer = x509.getIssuer(pem); if (!( typeof issuer === "object" && issuer.commonName === "excouncil.zz" && @@ -652,8 +647,8 @@ func TestGetSubject(t *testing.T) { t.Run("Success", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - const pem = %s; - const subject = x509.getSubject(pem); + var pem = %q; + var subject = x509.getSubject(pem); if (!( typeof subject === "object" && subject.commonName === "excouncil.zz" && diff --git a/js/modules/k6/encoding/encoding_test.go b/js/modules/k6/encoding/encoding_test.go index ac08edcdbf4..fd8b7de18d4 100644 --- a/js/modules/k6/encoding/encoding_test.go +++ b/js/modules/k6/encoding/encoding_test.go @@ -43,8 +43,8 @@ func TestEncodingAlgorithms(t *testing.T) { t.Run("Base64", func(t *testing.T) { t.Run("DefaultEnc", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "aGVsbG8gd29ybGQ="; - let encoded = encoding.b64encode("hello world"); + var correct = "aGVsbG8gd29ybGQ="; + var encoded = encoding.b64encode("hello world"); if (encoded !== correct) { throw new Error("Encoding mismatch: " + encoded); }`) @@ -52,8 +52,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("DefaultDec", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "hello world"; - let decoded = encoding.b64decode("aGVsbG8gd29ybGQ="); + var correct = "hello world"; + var decoded = encoding.b64decode("aGVsbG8gd29ybGQ="); if (decoded !== correct) { throw new Error("Decoding mismatch: " + decoded); }`) @@ -61,8 +61,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("DefaultUnicodeEnc", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "44GT44KT44Gr44Gh44Gv5LiW55WM"; - let encoded = encoding.b64encode("こんにちは世界", "std"); + var correct = "44GT44KT44Gr44Gh44Gv5LiW55WM"; + var encoded = encoding.b64encode("こんにちは世界", "std"); if (encoded !== correct) { throw new Error("Encoding mismatch: " + encoded); }`) @@ -70,8 +70,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("DefaultUnicodeDec", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "こんにちは世界"; - let decoded = encoding.b64decode("44GT44KT44Gr44Gh44Gv5LiW55WM"); + var correct = "こんにちは世界"; + var decoded = encoding.b64decode("44GT44KT44Gr44Gh44Gv5LiW55WM"); if (decoded !== correct) { throw new Error("Decoding mismatch: " + decoded); }`) @@ -79,8 +79,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("StdEnc", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "aGVsbG8gd29ybGQ="; - let encoded = encoding.b64encode("hello world", "std"); + var correct = "aGVsbG8gd29ybGQ="; + var encoded = encoding.b64encode("hello world", "std"); if (encoded !== correct) { throw new Error("Encoding mismatch: " + encoded); }`) @@ -88,8 +88,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("StdDec", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "hello world"; - let decoded = encoding.b64decode("aGVsbG8gd29ybGQ=", "std"); + var correct = "hello world"; + var decoded = encoding.b64decode("aGVsbG8gd29ybGQ=", "std"); if (decoded !== correct) { throw new Error("Decoding mismatch: " + decoded); }`) @@ -97,8 +97,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("RawStdEnc", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "aGVsbG8gd29ybGQ"; - let encoded = encoding.b64encode("hello world", "rawstd"); + var correct = "aGVsbG8gd29ybGQ"; + var encoded = encoding.b64encode("hello world", "rawstd"); if (encoded !== correct) { throw new Error("Encoding mismatch: " + encoded); }`) @@ -106,8 +106,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("RawStdDec", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "hello world"; - let decoded = encoding.b64decode("aGVsbG8gd29ybGQ", "rawstd"); + var correct = "hello world"; + var decoded = encoding.b64decode("aGVsbG8gd29ybGQ", "rawstd"); if (decoded !== correct) { throw new Error("Decoding mismatch: " + decoded); }`) @@ -115,8 +115,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("URLEnc", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "5bCP6aO85by-Li4="; - let encoded = encoding.b64encode("小飼弾..", "url"); + var correct = "5bCP6aO85by-Li4="; + var encoded = encoding.b64encode("小飼弾..", "url"); if (encoded !== correct) { throw new Error("Encoding mismatch: " + encoded); }`) @@ -124,8 +124,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("URLDec", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "小飼弾.."; - let decoded = encoding.b64decode("5bCP6aO85by-Li4=", "url"); + var correct = "小飼弾.."; + var decoded = encoding.b64decode("5bCP6aO85by-Li4=", "url"); if (decoded !== correct) { throw new Error("Decoding mismatch: " + decoded); }`) @@ -133,8 +133,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("RawURLEnc", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "5bCP6aO85by-Li4"; - let encoded = encoding.b64encode("小飼弾..", "rawurl"); + var correct = "5bCP6aO85by-Li4"; + var encoded = encoding.b64encode("小飼弾..", "rawurl"); if (encoded !== correct) { throw new Error("Encoding mismatch: " + encoded); }`) @@ -142,8 +142,8 @@ func TestEncodingAlgorithms(t *testing.T) { }) t.Run("RawURLDec", func(t *testing.T) { _, err := common.RunString(rt, ` - const correct = "小飼弾.."; - let decoded = encoding.b64decode("5bCP6aO85by-Li4", "rawurl"); + var correct = "小飼弾.."; + var decoded = encoding.b64decode("5bCP6aO85by-Li4", "rawurl"); if (decoded !== correct) { throw new Error("Decoding mismatch: " + decoded); }`) diff --git a/js/modules/k6/html/element_test.go b/js/modules/k6/html/element_test.go index 48120e3c581..415fc133666 100644 --- a/js/modules/k6/html/element_test.go +++ b/js/modules/k6/html/element_test.go @@ -62,7 +62,7 @@ func TestElement(t *testing.T) { rt.Set("html", common.Bind(rt, &HTML{}, &ctx)) // compileProtoElem() - _, err := common.RunString(rt, `let doc = html.parseHTML(src)`) + _, err := common.RunString(rt, `var doc = html.parseHTML(src)`) assert.NoError(t, err) assert.IsType(t, Selection{}, rt.Get("doc").Export()) diff --git a/js/modules/k6/html/elements_gen_test.go b/js/modules/k6/html/elements_gen_test.go index 5bc77255a61..a7c79f0508f 100644 --- a/js/modules/k6/html/elements_gen_test.go +++ b/js/modules/k6/html/elements_gen_test.go @@ -298,7 +298,7 @@ var urlTests = []struct { } const testGenElems = ` - + @@ -390,7 +390,7 @@ func TestGenElements(t *testing.T) { rt.Set("src", testGenElems) rt.Set("html", common.Bind(rt, &HTML{}, &ctx)) - _, err := common.RunString(rt, "let doc = html.parseHTML(src)") + _, err := common.RunString(rt, "var doc = html.parseHTML(src)") assert.NoError(t, err) assert.IsType(t, Selection{}, rt.Get("doc").Export()) diff --git a/js/modules/k6/html/elements_test.go b/js/modules/k6/html/elements_test.go index 9c212b577b8..72302831fae 100644 --- a/js/modules/k6/html/elements_test.go +++ b/js/modules/k6/html/elements_test.go @@ -43,7 +43,7 @@ const testHTMLElems = ` 6 - +
@@ -92,7 +92,7 @@ func TestElements(t *testing.T) { rt.Set("src", testHTMLElems) rt.Set("html", common.Bind(rt, &HTML{}, &ctx)) - _, err := common.RunString(rt, `let doc = html.parseHTML(src)`) + _, err := common.RunString(rt, `var doc = html.parseHTML(src)`) assert.NoError(t, err) assert.IsType(t, Selection{}, rt.Get("doc").Export()) diff --git a/js/modules/k6/html/html_test.go b/js/modules/k6/html/html_test.go index 3be99a7b13f..6178230c753 100644 --- a/js/modules/k6/html/html_test.go +++ b/js/modules/k6/html/html_test.go @@ -72,7 +72,7 @@ func TestParseHTML(t *testing.T) { // TODO: I literally cannot think of a snippet that makes goquery error. // I'm not sure if it's even possible without like, an invalid reader or something, which would // be impossible to cause from the JS side. - _, err := common.RunString(rt, `let doc = html.parseHTML(src)`) + _, err := common.RunString(rt, `var doc = html.parseHTML(src)`) assert.NoError(t, err) assert.IsType(t, Selection{}, rt.Get("doc").Export()) diff --git a/js/modules/k6/html/serialize_test.go b/js/modules/k6/html/serialize_test.go index e8f1c77f7b1..db5deb05051 100644 --- a/js/modules/k6/html/serialize_test.go +++ b/js/modules/k6/html/serialize_test.go @@ -74,7 +74,7 @@ func TestSerialize(t *testing.T) { rt.Set("src", testSerializeHTML) rt.Set("html", common.Bind(rt, New(), &ctx)) - _, err := common.RunString(rt, `let doc = html.parseHTML(src)`) + _, err := common.RunString(rt, `var doc = html.parseHTML(src)`) assert.NoError(t, err) assert.IsType(t, Selection{}, rt.Get("doc").Export()) diff --git a/js/modules/k6/http/http_test.go b/js/modules/k6/http/http_test.go index f81c9ff5714..19f895a1fcf 100644 --- a/js/modules/k6/http/http_test.go +++ b/js/modules/k6/http/http_test.go @@ -47,7 +47,7 @@ func TestTagURL(t *testing.T) { t.Run("expr="+expr, func(t *testing.T) { tag, err := httpext.NewURL(data.u, data.n) require.NoError(t, err) - v, err := common.RunString(rt, "http.url`"+expr+"`") + v, err := common.RunES6String(rt, "http.url`"+expr+"`") if assert.NoError(t, err) { assert.Equal(t, tag, v.Export()) } diff --git a/js/modules/k6/http/request_test.go b/js/modules/k6/http/request_test.go index 87564f1ee45..38d0df6cf15 100644 --- a/js/modules/k6/http/request_test.go +++ b/js/modules/k6/http/request_test.go @@ -164,7 +164,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("Redirects", func(t *testing.T) { t.Run("tracing", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/redirect/9"); + var res = http.get("HTTPBIN_URL/redirect/9"); `)) assert.NoError(t, err) bufSamples := stats.GetBufferedSamples(samples) @@ -188,7 +188,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("11", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/redirect/11"); + var res = http.get("HTTPBIN_URL/redirect/11"); if (res.status != 302) { throw new Error("wrong status: " + res.status) } if (res.url != "HTTPBIN_URL/relative-redirect/1") { throw new Error("incorrect URL: " + res.url) } if (res.headers["Location"] != "/get") { throw new Error("incorrect Location header: " + res.headers["Location"]) } @@ -204,7 +204,7 @@ func TestRequestAndBatch(t *testing.T) { state.Options.MaxRedirects = null.NewInt(10, false) _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/redirect/11"); + var res = http.get("HTTPBIN_URL/redirect/11"); if (res.status != 302) { throw new Error("wrong status: " + res.status) } if (res.url != "HTTPBIN_URL/relative-redirect/1") { throw new Error("incorrect URL: " + res.url) } if (res.headers["Location"] != "/get") { throw new Error("incorrect Location header: " + res.headers["Location"]) } @@ -221,7 +221,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("requestScopeRedirects", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/redirect/1", {redirects: 3}); + var res = http.get("HTTPBIN_URL/redirect/1", {redirects: 3}); if (res.status != 200) { throw new Error("wrong status: " + res.status) } if (res.url != "HTTPBIN_URL/get") { throw new Error("incorrect URL: " + res.url) } `)) @@ -229,7 +229,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("requestScopeNoRedirects", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/redirect/1", {redirects: 0}); + var res = http.get("HTTPBIN_URL/redirect/1", {redirects: 0}); if (res.status != 302) { throw new Error("wrong status: " + res.status) } if (res.url != "HTTPBIN_URL/redirect/1") { throw new Error("incorrect URL: " + res.url) } if (res.headers["Location"] != "/get") { throw new Error("incorrect Location header: " + res.headers["Location"]) } @@ -245,7 +245,7 @@ func TestRequestAndBatch(t *testing.T) { http.Redirect(w, r, sr("HTTPBIN_URL/post"), http.StatusPermanentRedirect) })) _, err := common.RunString(rt, sr(` - let res = http.post("HTTPBIN_URL/post-redirect", "pesho", {redirects: 1}); + var res = http.post("HTTPBIN_URL/post-redirect", "pesho", {redirects: 1}); if (res.status != 200) { throw new Error("wrong status: " + res.status) } if (res.url != "HTTPBIN_URL/post") { throw new Error("incorrect URL: " + res.url) } @@ -289,7 +289,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("UserAgent", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/user-agent"); + var res = http.get("HTTPBIN_URL/user-agent"); if (res.json()['user-agent'] != "TestUserAgent") { throw new Error("incorrect user agent: " + res.json()['user-agent']) } @@ -298,7 +298,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("Override", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/user-agent", { + var res = http.get("HTTPBIN_URL/user-agent", { headers: { "User-Agent": "OtherUserAgent" }, }); if (res.json()['user-agent'] != "OtherUserAgent") { @@ -311,7 +311,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("Compression", func(t *testing.T) { t.Run("gzip", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPSBIN_IP_URL/gzip"); + var res = http.get("HTTPSBIN_IP_URL/gzip"); if (res.json()['gzipped'] != true) { throw new Error("unexpected body data: " + res.json()['gzipped']) } @@ -320,7 +320,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("deflate", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/deflate"); + var res = http.get("HTTPBIN_URL/deflate"); if (res.json()['deflated'] != true) { throw new Error("unexpected body data: " + res.json()['deflated']) } @@ -329,7 +329,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("zstd", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPSBIN_IP_URL/zstd"); + var res = http.get("HTTPSBIN_IP_URL/zstd"); if (res.json()['compression'] != 'zstd') { throw new Error("unexpected body data: " + res.json()['compression']) } @@ -338,7 +338,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("brotli", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPSBIN_IP_URL/brotli"); + var res = http.get("HTTPSBIN_IP_URL/brotli"); if (res.json()['compression'] != 'br') { throw new Error("unexpected body data: " + res.json()['compression']) } @@ -347,7 +347,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("zstd-br", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPSBIN_IP_URL/zstd-br"); + var res = http.get("HTTPSBIN_IP_URL/zstd-br"); if (res.json()['compression'] != 'zstd, br') { throw new Error("unexpected compression: " + res.json()['compression']) } @@ -363,7 +363,7 @@ func TestRequestAndBatch(t *testing.T) { })) _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/customcompression"); + var res = http.get("HTTPBIN_URL/customcompression"); if (res.json()["custom"] != true) { throw new Error("unexpected body data: " + res.body) } @@ -374,8 +374,8 @@ func TestRequestAndBatch(t *testing.T) { t.Run("CompressionWithAcceptEncodingHeader", func(t *testing.T) { t.Run("gzip", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let params = { headers: { "Accept-Encoding": "gzip" } }; - let res = http.get("HTTPBIN_URL/gzip", params); + var params = { headers: { "Accept-Encoding": "gzip" } }; + var res = http.get("HTTPBIN_URL/gzip", params); if (res.json()['gzipped'] != true) { throw new Error("unexpected body data: " + res.json()['gzipped']) } @@ -384,8 +384,8 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("deflate", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let params = { headers: { "Accept-Encoding": "deflate" } }; - let res = http.get("HTTPBIN_URL/deflate", params); + var params = { headers: { "Accept-Encoding": "deflate" } }; + var res = http.get("HTTPBIN_URL/deflate", params); if (res.json()['deflated'] != true) { throw new Error("unexpected body data: " + res.json()['deflated']) } @@ -410,7 +410,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("HTTP/2", func(t *testing.T) { stats.GetBufferedSamples(samples) // Clean up buffered samples from previous tests _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTP2BIN_URL/get"); + var res = http.request("GET", "HTTP2BIN_URL/get"); if (res.status != 200) { throw new Error("wrong status: " + res.status) } if (res.proto != "HTTP/2.0") { throw new Error("wrong proto: " + res.proto) } `)) @@ -442,7 +442,7 @@ func TestRequestAndBatch(t *testing.T) { for _, versionTest := range tlsVersionTests { t.Run(versionTest.Name, func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - let res = http.get("%s"); + 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) @@ -458,7 +458,7 @@ func TestRequestAndBatch(t *testing.T) { for _, cipherSuiteTest := range tlsCipherSuiteTests { t.Run(cipherSuiteTest.Name, func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(` - let res = http.get("%s"); + 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) @@ -467,7 +467,7 @@ func TestRequestAndBatch(t *testing.T) { } t.Run("ocsp_stapled_good", func(t *testing.T) { _, err := common.RunString(rt, ` - let res = http.request("GET", "https://www.microsoft.com/"); + var res = http.request("GET", "https://www.microsoft.com/"); if (res.ocsp.status != http.OCSP_STATUS_GOOD) { throw new Error("wrong ocsp stapled response status: " + res.ocsp.status); } `) assert.NoError(t, err) @@ -494,7 +494,7 @@ func TestRequestAndBatch(t *testing.T) { defer hook.Reset() _, err := common.RunString(rt, ` - let res = http.request("", "", { throw: false }); + var res = http.request("", "", { throw: false }); throw new Error(res.error); `) require.Error(t, err) @@ -517,7 +517,7 @@ func TestRequestAndBatch(t *testing.T) { for _, literal := range []string{`undefined`, `null`} { t.Run(literal, func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(sr(` - let res = http.request("GET", "HTTPBIN_URL/headers", null, %s); + var res = http.request("GET", "HTTPBIN_URL/headers", null, %s); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `), literal)) assert.NoError(t, err) @@ -531,11 +531,11 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/cookies/set?key=value", null, { redirects: 0 }); + var res = http.request("GET", "HTTPBIN_URL/cookies/set?key=value", null, { redirects: 0 }); if (res.cookies.key[0].value != "value") { throw new Error("wrong cookie value: " + res.cookies.key[0].value); } - const props = ["name", "value", "domain", "path", "expires", "max_age", "secure", "http_only"]; - let cookie = res.cookies.key[0]; - for (let i = 0; i < props.length; i++) { + var props = ["name", "value", "domain", "path", "expires", "max_age", "secure", "http_only"]; + var cookie = res.cookies.key[0]; + for (var i = 0; i < props.length; i++) { if (cookie[props[i]] === undefined) { throw new Error("cookie property not found: " + props[i]); } @@ -553,12 +553,12 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let jar = http.cookieJar(); + var jar = http.cookieJar(); jar.set("HTTPBIN_URL/cookies", "key", "value"); - let res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key2: "value2" } }); + var res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key2: "value2" } }); if (res.json().key != "value") { throw new Error("wrong cookie value: " + res.json().key); } if (res.json().key2 != "value2") { throw new Error("wrong cookie value: " + res.json().key2); } - let jarCookies = jar.cookiesForURL("HTTPBIN_URL/cookies"); + var jarCookies = jar.cookiesForURL("HTTPBIN_URL/cookies"); if (jarCookies.key[0] != "value") { throw new Error("wrong cookie value in jar"); } if (jarCookies.key2 != undefined) { throw new Error("unexpected cookie in jar"); } `)) @@ -571,10 +571,10 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key: "value" } }); + var res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key: "value" } }); if (res.json().key != "value") { throw new Error("wrong cookie value: " + res.json().key); } - let jar = http.cookieJar(); - let jarCookies = jar.cookiesForURL("HTTPBIN_URL/cookies"); + var jar = http.cookieJar(); + var jarCookies = jar.cookiesForURL("HTTPBIN_URL/cookies"); if (jarCookies.key != undefined) { throw new Error("unexpected cookie in jar"); } `)) assert.NoError(t, err) @@ -586,11 +586,11 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let jar = http.cookieJar(); + var jar = http.cookieJar(); jar.set("HTTPBIN_URL/cookies", "key", "value"); - let res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key: { value: "replaced", replace: true } } }); + var res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key: { value: "replaced", replace: true } } }); if (res.json().key != "replaced") { throw new Error("wrong cookie value: " + res.json().key); } - let jarCookies = jar.cookiesForURL("HTTPBIN_URL/cookies"); + var jarCookies = jar.cookiesForURL("HTTPBIN_URL/cookies"); if (jarCookies.key[0] != "value") { throw new Error("wrong cookie value in jar"); } `)) assert.NoError(t, err) @@ -615,7 +615,7 @@ func TestRequestAndBatch(t *testing.T) { require.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/redirect-to?url=HTTPSBIN_URL/set-cookie-without-redirect"); + var res = http.request("GET", "HTTPBIN_URL/redirect-to?url=HTTPSBIN_URL/set-cookie-without-redirect"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `)) require.NoError(t, err) @@ -641,7 +641,7 @@ func TestRequestAndBatch(t *testing.T) { require.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let res = http.request("GET", "HTTPSBIN_URL/cookies/set?key=value"); + var res = http.request("GET", "HTTPSBIN_URL/cookies/set?key=value"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `)) require.NoError(t, err) @@ -682,7 +682,7 @@ func TestRequestAndBatch(t *testing.T) { })) _, err = common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_IP_URL/redirect-to?url=HTTPSBIN_URL/set-cookie-and-redirect"); + var res = http.request("GET", "HTTPBIN_IP_URL/redirect-to?url=HTTPSBIN_URL/set-cookie-and-redirect"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `)) require.NoError(t, err) @@ -717,9 +717,9 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let jar = http.cookieJar(); + var jar = http.cookieJar(); jar.set("HTTPBIN_URL/cookies", "key", "value", { domain: "HTTPBIN_DOMAIN" }); - let res = http.request("GET", "HTTPBIN_URL/cookies"); + var res = http.request("GET", "HTTPBIN_URL/cookies"); if (res.json().key != "value") { throw new Error("wrong cookie value 1: " + res.json().key); } @@ -741,9 +741,9 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let jar = http.cookieJar(); + var jar = http.cookieJar(); jar.set("HTTPBIN_URL/cookies", "key", "value", { path: "/cookies" }); - let res = http.request("GET", "HTTPBIN_URL/cookies"); + var res = http.request("GET", "HTTPBIN_URL/cookies"); if (res.json().key != "value") { throw new Error("wrong cookie value: " + res.json().key); } @@ -765,9 +765,9 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let jar = http.cookieJar(); + var jar = http.cookieJar(); jar.set("HTTPBIN_URL/cookies", "key", "value", { expires: "Sun, 24 Jul 1983 17:01:02 GMT" }); - let res = http.request("GET", "HTTPBIN_URL/cookies"); + var res = http.request("GET", "HTTPBIN_URL/cookies"); if (res.json().key != undefined) { throw new Error("cookie 'key' unexpectedly found"); } @@ -786,9 +786,9 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let jar = http.cookieJar(); + var jar = http.cookieJar(); jar.set("HTTPSBIN_IP_URL/cookies", "key", "value", { secure: true }); - let res = http.request("GET", "HTTPSBIN_IP_URL/cookies"); + var res = http.request("GET", "HTTPSBIN_IP_URL/cookies"); if (res.json().key != "value") { throw new Error("wrong cookie value: " + res.json().key); } @@ -802,12 +802,12 @@ func TestRequestAndBatch(t *testing.T) { assert.NoError(t, err) state.CookieJar = cookieJar _, err = common.RunString(rt, sr(` - let jar = new http.CookieJar(); + var jar = new http.CookieJar(); jar.set("HTTPBIN_URL/cookies", "key", "value"); - let res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key2: "value2" }, jar: jar }); + var res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key2: "value2" }, jar: jar }); if (res.json().key != "value") { throw new Error("wrong cookie value: " + res.json().key); } if (res.json().key2 != "value2") { throw new Error("wrong cookie value: " + res.json().key2); } - let jarCookies = jar.cookiesForURL("HTTPBIN_URL/cookies"); + var jarCookies = jar.cookiesForURL("HTTPBIN_URL/cookies"); if (jarCookies.key[0] != "value") { throw new Error("wrong cookie value in jar: " + jarCookies.key[0]); } if (jarCookies.key2 != undefined) { throw new Error("unexpected cookie in jar"); } `)) @@ -822,7 +822,7 @@ func TestRequestAndBatch(t *testing.T) { urlExpected := sr("http://****:****@HTTPBIN_IP:HTTPBIN_PORT/basic-auth/bob/pass") _, err := common.RunString(rt, fmt.Sprintf(` - let res = http.request("GET", "%s", null, {}); + var res = http.request("GET", "%s", null, {}); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `, url)) assert.NoError(t, err) @@ -834,7 +834,7 @@ func TestRequestAndBatch(t *testing.T) { urlExpected := sr("http://****:****@HTTPBIN_IP:HTTPBIN_PORT/digest-auth/auth/bob/pass") _, err := common.RunString(rt, fmt.Sprintf(` - let res = http.request("GET", "%s", null, { auth: "digest" }); + var res = http.request("GET", "%s", null, { auth: "digest" }); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.error_code != 0) { throw new Error("wrong error code: " + res.error_code); } `, url)) @@ -850,7 +850,7 @@ func TestRequestAndBatch(t *testing.T) { url := sr("http://bob:pass@HTTPBIN_IP:HTTPBIN_PORT/digest-auth/failure") _, err := common.RunString(rt, fmt.Sprintf(` - let res = http.request("GET", "%s", null, { auth: "digest", timeout: 1, throw: false }); + var res = http.request("GET", "%s", null, { auth: "digest", timeout: 1, throw: false }); `, url)) assert.NoError(t, err) }) @@ -861,7 +861,7 @@ func TestRequestAndBatch(t *testing.T) { for _, literal := range []string{`null`, `undefined`} { t.Run(literal, func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(sr(` - let res = http.request("GET", "HTTPBIN_URL/headers", null, { headers: %s }); + var res = http.request("GET", "HTTPBIN_URL/headers", null, { headers: %s }); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `), literal)) assert.NoError(t, err) @@ -871,7 +871,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("object", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/headers", null, { + var res = http.request("GET", "HTTPBIN_URL/headers", null, { headers: { "X-My-Header": "value" }, }); if (res.status != 200) { throw new Error("wrong status: " + res.status); } @@ -883,7 +883,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("Host", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/headers", null, { + var res = http.request("GET", "HTTPBIN_URL/headers", null, { headers: { "Host": "HTTPBIN_DOMAIN" }, }); if (res.status != 200) { throw new Error("wrong status: " + res.status); } @@ -898,7 +898,7 @@ func TestRequestAndBatch(t *testing.T) { for _, literal := range []string{`null`, `undefined`} { t.Run(literal, func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(sr(` - let res = http.request("GET", "HTTPBIN_URL/headers", null, { tags: %s }); + var res = http.request("GET", "HTTPBIN_URL/headers", null, { tags: %s }); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `), literal)) assert.NoError(t, err) @@ -908,7 +908,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("object", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/headers", null, { tags: { tag: "value" } }); + var res = http.request("GET", "HTTPBIN_URL/headers", null, { tags: { tag: "value" } }); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `)) assert.NoError(t, err) @@ -929,7 +929,7 @@ func TestRequestAndBatch(t *testing.T) { state.Options.RunTags = stats.IntoSampleTags(&map[string]string{"runtag1": "val1", "runtag2": "val2"}) _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/headers", null, { tags: { method: "test", name: "myName", runtag1: "fromreq" } }); + var res = http.request("GET", "HTTPBIN_URL/headers", null, { tags: { method: "test", name: "myName", runtag1: "fromreq" } }); if (res.status != 200) { throw new Error("wrong status: " + res.status); } `)) assert.NoError(t, err) @@ -961,7 +961,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("GET", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.get("HTTPBIN_URL/get?a=1&b=2"); + var res = http.get("HTTPBIN_URL/get?a=1&b=2"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.json().args.a != "1") { throw new Error("wrong ?a: " + res.json().args.a); } if (res.json().args.b != "2") { throw new Error("wrong ?b: " + res.json().args.b); } @@ -970,10 +970,10 @@ func TestRequestAndBatch(t *testing.T) { assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", sr("HTTPBIN_URL/get?a=1&b=2"), "", 200, "") t.Run("Tagged", func(t *testing.T) { - _, err := common.RunString(rt, ` - let a = "1"; - let b = "2"; - let res = http.get(http.url`+"`"+sr(`HTTPBIN_URL/get?a=${a}&b=${b}`)+"`"+`); + _, err := common.RunES6String(rt, ` + var a = "1"; + var b = "2"; + var res = http.get(http.url`+"`"+sr(`HTTPBIN_URL/get?a=${a}&b=${b}`)+"`"+`); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.json().args.a != a) { throw new Error("wrong ?a: " + res.json().args.a); } if (res.json().args.b != b) { throw new Error("wrong ?b: " + res.json().args.b); } @@ -984,7 +984,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("HEAD", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.head("HTTPBIN_URL/get?a=1&b=2"); + var res = http.head("HTTPBIN_URL/get?a=1&b=2"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.body.length != 0) { throw new Error("HEAD responses shouldn't have a body"); } if (!res.headers["Content-Length"]) { throw new Error("Missing or invalid Content-Length header!"); } @@ -995,7 +995,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("OPTIONS", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.options("HTTPBIN_URL/?a=1&b=2"); + var res = http.options("HTTPBIN_URL/?a=1&b=2"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (!res.headers["Access-Control-Allow-Methods"]) { throw new Error("Missing Access-Control-Allow-Methods header!"); } `)) @@ -1009,7 +1009,7 @@ func TestRequestAndBatch(t *testing.T) { // https://tools.ietf.org/html/rfc7231#section-4.3.5 t.Run("DELETE", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.del("HTTPBIN_URL/delete?test=mest"); + var res = http.del("HTTPBIN_URL/delete?test=mest"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.json().args.test != "mest") { throw new Error("wrong args: " + JSON.stringify(res.json().args)); } `)) @@ -1025,7 +1025,7 @@ func TestRequestAndBatch(t *testing.T) { for method, fn := range postMethods { t.Run(method, func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(sr(` - let res = http.%s("HTTPBIN_URL/%s", "data"); + var res = http.%s("HTTPBIN_URL/%s", "data"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.json().data != "data") { throw new Error("wrong data: " + res.json().data); } if (res.json().headers["Content-Type"]) { throw new Error("content type set: " + res.json().headers["Content-Type"]); } @@ -1035,7 +1035,7 @@ func TestRequestAndBatch(t *testing.T) { t.Run("object", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(sr(` - let res = http.%s("HTTPBIN_URL/%s", {a: "a", b: 2}); + var res = http.%s("HTTPBIN_URL/%s", {a: "a", b: 2}); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.json().form.a != "a") { throw new Error("wrong a=: " + res.json().form.a); } if (res.json().form.b != "2") { throw new Error("wrong b=: " + res.json().form.b); } @@ -1045,7 +1045,7 @@ func TestRequestAndBatch(t *testing.T) { assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), method, sr("HTTPBIN_URL/")+strings.ToLower(method), "", 200, "") t.Run("Content-Type", func(t *testing.T) { _, err := common.RunString(rt, fmt.Sprintf(sr(` - let res = http.%s("HTTPBIN_URL/%s", {a: "a", b: 2}, {headers: {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}}); + var res = http.%s("HTTPBIN_URL/%s", {a: "a", b: 2}, {headers: {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}}); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.json().form.a != "a") { throw new Error("wrong a=: " + res.json().form.a); } if (res.json().form.b != "2") { throw new Error("wrong b=: " + res.json().form.b); } @@ -1060,16 +1060,16 @@ func TestRequestAndBatch(t *testing.T) { t.Run("Batch", func(t *testing.T) { t.Run("error", func(t *testing.T) { - _, err := common.RunString(rt, `let res = http.batch("https://somevalidurl.com");`) + _, err := common.RunString(rt, `var res = http.batch("https://somevalidurl.com");`) require.Error(t, err) }) t.Run("GET", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let reqs = [ + var reqs = [ ["GET", "HTTPBIN_URL/"], ["GET", "HTTPBIN_IP_URL/"], ]; - let res = http.batch(reqs); + var res = http.batch(reqs); for (var key in res) { if (res[key].status != 200) { throw new Error("wrong status: " + res[key].status); } if (res[key].url != reqs[key][1]) { throw new Error("wrong url: " + res[key].url); } @@ -1080,7 +1080,7 @@ func TestRequestAndBatch(t *testing.T) { assertRequestMetricsEmitted(t, bufSamples, "GET", sr("HTTPBIN_IP_URL/"), "", 200, "") t.Run("Tagged", func(t *testing.T) { - _, err := common.RunString(rt, sr(` + _, err := common.RunES6String(rt, sr(` let fragment = "get"; let reqs = [ ["GET", http.url`+"`"+`HTTPBIN_URL/${fragment}`+"`"+`], @@ -1099,11 +1099,11 @@ func TestRequestAndBatch(t *testing.T) { t.Run("Shorthand", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let reqs = [ + var reqs = [ "HTTPBIN_URL/", "HTTPBIN_IP_URL/", ]; - let res = http.batch(reqs); + var res = http.batch(reqs); for (var key in res) { if (res[key].status != 200) { throw new Error("wrong status: " + key + ": " + res[key].status); } if (res[key].url != reqs[key]) { throw new Error("wrong url: " + key + ": " + res[key].url); } @@ -1114,7 +1114,7 @@ func TestRequestAndBatch(t *testing.T) { assertRequestMetricsEmitted(t, bufSamples, "GET", sr("HTTPBIN_IP_URL/"), "", 200, "") t.Run("Tagged", func(t *testing.T) { - _, err := common.RunString(rt, sr(` + _, err := common.RunES6String(rt, sr(` let fragment = "get"; let reqs = [ http.url`+"`"+`HTTPBIN_URL/${fragment}`+"`"+`, @@ -1134,11 +1134,11 @@ func TestRequestAndBatch(t *testing.T) { t.Run("ObjectForm", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let reqs = [ + var reqs = [ { method: "GET", url: "HTTPBIN_URL/" }, { url: "HTTPBIN_IP_URL/", method: "GET"}, ]; - let res = http.batch(reqs); + var res = http.batch(reqs); for (var key in res) { if (res[key].status != 200) { throw new Error("wrong status: " + key + ": " + res[key].status); } if (res[key].url != reqs[key].url) { throw new Error("wrong url: " + key + ": " + res[key].url + " != " + reqs[key].url); } @@ -1151,13 +1151,13 @@ func TestRequestAndBatch(t *testing.T) { t.Run("ObjectKeys", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let reqs = { + var reqs = { shorthand: "HTTPBIN_URL/get?r=shorthand", arr: ["GET", "HTTPBIN_URL/get?r=arr", null, {tags: {name: 'arr'}}], obj1: { method: "GET", url: "HTTPBIN_URL/get?r=obj1" }, obj2: { url: "HTTPBIN_URL/get?r=obj2", params: {tags: {name: 'obj2'}}, method: "GET"}, }; - let res = http.batch(reqs); + var res = http.batch(reqs); for (var key in res) { if (res[key].status != 200) { throw new Error("wrong status: " + key + ": " + res[key].status); } if (res[key].json().args.r != key) { throw new Error("wrong request id: " + key); } @@ -1176,7 +1176,7 @@ func TestRequestAndBatch(t *testing.T) { rt.Set("someBinFile", []byte(testStr)) _, err := common.RunString(rt, sr(` - let reqs = [ + var reqs = [ ["POST", "HTTPBIN_URL/post", "testbody"], ["POST", "HTTPBIN_URL/post", someStrFile], ["POST", "HTTPBIN_URL/post", someBinFile], @@ -1202,7 +1202,7 @@ func TestRequestAndBatch(t *testing.T) { }, }, ]; - let res = http.batch(reqs); + var res = http.batch(reqs); for (var key in res) { if (res[key].status != 200) { throw new Error("wrong status: " + key + ": " + res[key].status); } if (res[key].json().data != "testbody" && res[key].json().form.hello != "world!") { throw new Error("wrong response for " + key + ": " + res[key].body); } @@ -1215,7 +1215,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("POST", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.batch([ ["POST", "HTTPBIN_URL/post", { key: "value" }] ]); + var res = http.batch([ ["POST", "HTTPBIN_URL/post", { key: "value" }] ]); for (var key in res) { if (res[key].status != 200) { throw new Error("wrong status: " + key + ": " + res[key].status); } if (res[key].json().form.key != "value") { throw new Error("wrong form: " + key + ": " + JSON.stringify(res[key].json().form)); } @@ -1225,7 +1225,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("PUT", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.batch([ ["PUT", "HTTPBIN_URL/put", { key: "value" }] ]); + var res = http.batch([ ["PUT", "HTTPBIN_URL/put", { key: "value" }] ]); for (var key in res) { if (res[key].status != 200) { throw new Error("wrong status: " + key + ": " + res[key].status); } if (res[key].json().form.key != "value") { throw new Error("wrong form: " + key + ": " + JSON.stringify(res[key].json().form)); } @@ -1238,9 +1238,9 @@ func TestRequestAndBatch(t *testing.T) { t.Run("HTTPRequest", func(t *testing.T) { t.Run("EmptyBody", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let reqUrl = "HTTPBIN_URL/cookies" - let res = http.get(reqUrl); - let jar = new http.CookieJar(); + var reqUrl = "HTTPBIN_URL/cookies" + var res = http.get(reqUrl); + var jar = new http.CookieJar(); jar.set("HTTPBIN_URL/cookies", "key", "value"); res = http.request("GET", "HTTPBIN_URL/cookies", null, { cookies: { key2: "value2" }, jar: jar }); @@ -1260,7 +1260,7 @@ func TestRequestAndBatch(t *testing.T) { }) t.Run("NonEmptyBody", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.post("HTTPBIN_URL/post", {a: "a", b: 2}, {headers: {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}}); + var res = http.post("HTTPBIN_URL/post", {a: "a", b: 2}, {headers: {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}}); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.request["body"] != "a=a&b=2") { throw new Error("http request body was not set properly: " + JSON.stringify(res.request))} `)) @@ -1448,7 +1448,7 @@ func TestRequestCompression(t *testing.T) { } expectedEncoding = strings.Join(algos, ", ") actualEncoding = expectedEncoding - _, err := common.RunString(rt, tb.Replacer.Replace(` + _, err := common.RunES6String(rt, tb.Replacer.Replace(` http.post("HTTPBIN_URL/compressed-text", `+"`"+text+"`"+`, {"compression": "`+testCase.compression+`"}); `)) if testCase.expectedError == "" { @@ -1467,7 +1467,7 @@ func TestRequestCompression(t *testing.T) { logHook.Drain() t.Run("encoding", func(t *testing.T) { - _, err := common.RunString(rt, tb.Replacer.Replace(` + _, err := common.RunES6String(rt, tb.Replacer.Replace(` http.post("HTTPBIN_URL/compressed-text", `+"`"+text+"`"+`, {"compression": "`+actualEncoding+`", "headers": {"Content-Encoding": "`+expectedEncoding+`"} @@ -1479,7 +1479,7 @@ func TestRequestCompression(t *testing.T) { }) t.Run("encoding and length", func(t *testing.T) { - _, err := common.RunString(rt, tb.Replacer.Replace(` + _, err := common.RunES6String(rt, tb.Replacer.Replace(` http.post("HTTPBIN_URL/compressed-text", `+"`"+text+"`"+`, {"compression": "`+actualEncoding+`", "headers": {"Content-Encoding": "`+expectedEncoding+`", @@ -1493,7 +1493,7 @@ func TestRequestCompression(t *testing.T) { expectedEncoding = actualEncoding t.Run("correct encoding", func(t *testing.T) { - _, err := common.RunString(rt, tb.Replacer.Replace(` + _, err := common.RunES6String(rt, tb.Replacer.Replace(` http.post("HTTPBIN_URL/compressed-text", `+"`"+text+"`"+`, {"compression": "`+actualEncoding+`", "headers": {"Content-Encoding": "`+actualEncoding+`"} @@ -1515,7 +1515,7 @@ func TestRequestCompression(t *testing.T) { t.Run("content-length is set", func(t *testing.T) { _, err := common.RunString(rt, tb.Replacer.Replace(` - let resp = http.post("HTTPBIN_URL/post", "0123456789"); + var resp = http.post("HTTPBIN_URL/post", "0123456789"); if (resp.json().headers["Content-Length"][0] != "10") { throw new Error("content-length not set: " + JSON.stringify(resp.json().headers)); } @@ -1571,29 +1571,29 @@ func TestResponseTypes(t *testing.T) { } _, err := common.RunString(rt, replace(` - let expText = "EXP_TEXT"; - let expBinLength = EXP_BIN_LEN; + var expText = "EXP_TEXT"; + var expBinLength = EXP_BIN_LEN; // Check default behaviour with a unicode text - let respTextImplicit = http.get("HTTPBIN_URL/get-text").body; + var respTextImplicit = http.get("HTTPBIN_URL/get-text").body; if (respTextImplicit !== expText) { throw new Error("default response body should be '" + expText + "' but was '" + respTextImplicit + "'"); } http.post("HTTPBIN_URL/compare-text", respTextImplicit); // Check discarding of responses - let respNone = http.get("HTTPBIN_URL/get-text", { responseType: "none" }).body; + var respNone = http.get("HTTPBIN_URL/get-text", { responseType: "none" }).body; if (respNone != null) { throw new Error("none response body should be null but was " + respNone); } // Check binary transmission of the text response as well - let respTextInBin = http.get("HTTPBIN_URL/get-text", { responseType: "binary" }).body; + var respTextInBin = http.get("HTTPBIN_URL/get-text", { responseType: "binary" }).body; // Hack to convert a utf-8 array to a JS string - let strConv = ""; + var strConv = ""; function pad(n) { return n.length < 2 ? "0" + n : n; } - for( let i = 0; i < respTextInBin.length; i++ ) { + for( var i = 0; i < respTextInBin.length; i++ ) { strConv += ( "%" + pad(respTextInBin[i].toString(16))); } strConv = decodeURIComponent(strConv); @@ -1603,11 +1603,11 @@ func TestResponseTypes(t *testing.T) { http.post("HTTPBIN_URL/compare-text", respTextInBin); // Check binary response - let respBin = http.get("HTTPBIN_URL/get-bin", { responseType: "binary" }).body; + var respBin = http.get("HTTPBIN_URL/get-bin", { responseType: "binary" }).body; if (respBin.length !== expBinLength) { throw new Error("response body length should be '" + expBinLength + "' but was '" + respBin.length + "'"); } - for( let i = 0; i < respBin.length; i++ ) { + for( var i = 0; i < respBin.length; i++ ) { if ( respBin[i] !== i%256 ) { throw new Error("expected value " + (i%256) + " to be at position " + i + " but it was " + respBin[i]); } @@ -1620,16 +1620,16 @@ func TestResponseTypes(t *testing.T) { state.Options.DiscardResponseBodies = null.BoolFrom(true) _, err = common.RunString(rt, replace(` - let expText = "EXP_TEXT"; + var expText = "EXP_TEXT"; // Check default behaviour - let respDefault = http.get("HTTPBIN_URL/get-text").body; + var respDefault = http.get("HTTPBIN_URL/get-text").body; if (respDefault !== null) { throw new Error("default response body should be discarded and null but was " + respDefault); } // Check explicit text response - let respTextExplicit = http.get("HTTPBIN_URL/get-text", { responseType: "text" }).body; + var respTextExplicit = http.get("HTTPBIN_URL/get-text", { responseType: "text" }).body; if (respTextExplicit !== expText) { throw new Error("text response body should be '" + expText + "' but was '" + respTextExplicit + "'"); } @@ -1684,46 +1684,46 @@ func TestErrorCodes(t *testing.T) { name: "Unroutable", expectedErrorCode: 1101, expectedErrorMsg: "lookup: no such host", - script: `let res = http.request("GET", "http://sdafsgdhfjg/");`, + script: `var res = http.request("GET", "http://sdafsgdhfjg/");`, }, { name: "404", status: 404, expectedErrorCode: 1404, - script: `let res = http.request("GET", "HTTPBIN_URL/status/404");`, + script: `var res = http.request("GET", "HTTPBIN_URL/status/404");`, }, { name: "Unroutable redirect", expectedErrorCode: 1101, expectedErrorMsg: "lookup: no such host", moreSamples: 1, - script: `let res = http.request("GET", "HTTPBIN_URL/redirect-to?url=http://dafsgdhfjg/");`, + script: `var res = http.request("GET", "HTTPBIN_URL/redirect-to?url=http://dafsgdhfjg/");`, }, { name: "Non location redirect", expectedErrorCode: 1000, expectedErrorMsg: "302 response missing Location header", - script: `let res = http.request("GET", "HTTPBIN_URL/no-location-redirect");`, + script: `var res = http.request("GET", "HTTPBIN_URL/no-location-redirect");`, }, { name: "Bad location redirect", expectedErrorCode: 1000, expectedErrorMsg: "failed to parse Location header \"h\\t:/\": ", - script: `let res = http.request("GET", "HTTPBIN_URL/bad-location-redirect");`, + script: `var res = http.request("GET", "HTTPBIN_URL/bad-location-redirect");`, }, { name: "Missing protocol", expectedErrorCode: 1000, expectedErrorMsg: `unsupported protocol scheme ""`, - script: `let res = http.request("GET", "dafsgdhfjg/");`, + script: `var res = http.request("GET", "dafsgdhfjg/");`, }, { name: "Too many redirects", status: 302, moreSamples: 2, script: ` - let res = http.get("HTTPBIN_URL/relative-redirect/3", {redirects: 2}); + var res = http.get("HTTPBIN_URL/relative-redirect/3", {redirects: 2}); if (res.url != "HTTPBIN_URL/relative-redirect/1") { throw new Error("incorrect URL: " + res.url) }`, }, { @@ -1733,7 +1733,7 @@ func TestErrorCodes(t *testing.T) { expectedErrorMsg: `dial: connection refused`, expectedErrorCode: 1212, script: ` - let res = http.get("HTTPBIN_URL/redirect-to?url=http%3A%2F%2F127.0.0.1%3A1%2Fpesho"); + var res = http.get("HTTPBIN_URL/redirect-to?url=http%3A%2F%2F127.0.0.1%3A1%2Fpesho"); if (res.url != "http://127.0.0.1:1/pesho") { throw new Error("incorrect URL: " + res.url) }`, }, } @@ -1793,7 +1793,7 @@ func TestResponseWaitingAndReceivingTimings(t *testing.T) { })) _, err := common.RunString(rt, tb.Replacer.Replace(` - let resp = http.get("HTTPBIN_URL/slow-response"); + var resp = http.get("HTTPBIN_URL/slow-response"); if (resp.timings.waiting < 1000) { throw new Error("expected waiting time to be over 1000ms but was " + resp.timings.waiting); @@ -1819,7 +1819,7 @@ func TestResponseTimingsWhenTimeout(t *testing.T) { state.Options.Throw = null.BoolFrom(false) _, err := common.RunString(rt, tb.Replacer.Replace(` - let resp = http.get("HTTPBIN_URL/delay/10", { timeout: 2500 }); + var resp = http.get("HTTPBIN_URL/delay/10", { timeout: 2500 }); if (resp.timings.waiting < 2000) { throw new Error("expected waiting time to be over 2000ms but was " + resp.timings.waiting); @@ -1841,18 +1841,18 @@ func TestNoResponseBodyMangling(t *testing.T) { state.Options.Throw = null.BoolFrom(true) _, err := common.RunString(rt, tb.Replacer.Replace(` - const batchSize = 100; + var batchSize = 100; - let requests = []; + var requests = []; - for (let i = 0; i < batchSize; i++) { + for (var i = 0; i < batchSize; i++) { requests.push(["GET", "HTTPBIN_URL/get?req=" + i, null, { responseType: (i % 2 ? "binary" : "text") }]); } - let responses = http.batch(requests); + var responses = http.batch(requests); - for (let i = 0; i < batchSize; i++) { - let reqNumber = parseInt(responses[i].json().args.req[0], 10); + for (var i = 0; i < batchSize; i++) { + var reqNumber = parseInt(responses[i].json().args.req[0], 10); if (i !== reqNumber) { throw new Error("Response " + i + " has " + reqNumber + ", expected " + i) } @@ -1945,7 +1945,7 @@ func TestErrorsWithDecompression(t *testing.T) { _, err := common.RunString(rt, tb.Replacer.Replace(` function handleResponseEncodingError (encoding) { - let resp = http.get("HTTPBIN_URL/broken-archive?encoding=" + encoding); + var resp = http.get("HTTPBIN_URL/broken-archive?encoding=" + encoding); if (resp.error_code != 1701) { throw new Error("Expected error_code 1701 for '" + encoding +"', but got " + resp.error_code); } @@ -1977,7 +1977,7 @@ func TestDigestAuthWithBody(t *testing.T) { ) _, err := common.RunString(rt, fmt.Sprintf(` - let res = http.post(%q, "super secret body", { auth: "digest" }); + var res = http.post(%q, "super secret body", { auth: "digest" }); if (res.status !== 200) { throw new Error("wrong status: " + res.status); } if (res.error_code !== 0) { throw new Error("wrong error code: " + res.error_code); } `, urlWithCreds)) diff --git a/js/modules/k6/http/response_test.go b/js/modules/k6/http/response_test.go index 4c77562df81..79fd82419ae 100644 --- a/js/modules/k6/http/response_test.go +++ b/js/modules/k6/http/response_test.go @@ -80,7 +80,7 @@ const jsonData = `{"glossary": { "GlossSeeAlso": ["GML","XML"]}, "GlossSee": "markup"}}}}}` -const invalidJSONData = `{ +const invalidJSONData = `{ "a":"apple", "t":testing" }` @@ -135,7 +135,7 @@ func TestResponse(t *testing.T) { t.Run("Html", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/html"); + var res = http.request("GET", "HTTPBIN_URL/html"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.body.indexOf("Herman Melville - Moby-Dick") == -1) { throw new Error("wrong body: " + res.body); } `)) @@ -172,7 +172,7 @@ func TestResponse(t *testing.T) { } _, err = common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/html"); + var res = http.request("GET", "HTTPBIN_URL/html"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.body.indexOf("Herman Melville - Moby-Dick") == -1) { throw new Error("wrong body: " + res.body); } `)) @@ -182,7 +182,7 @@ func TestResponse(t *testing.T) { }) t.Run("Json", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/get?a=1&b=2"); + var res = http.request("GET", "HTTPBIN_URL/get?a=1&b=2"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } if (res.json().args.a != "1") { throw new Error("wrong ?a: " + res.json().args.a); } if (res.json().args.b != "2") { throw new Error("wrong ?b: " + res.json().args.b); } @@ -204,7 +204,7 @@ func TestResponse(t *testing.T) { }) t.Run("JsonSelector", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/json"); + var res = http.request("GET", "HTTPBIN_URL/json"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } var value = res.json("glossary.friends.1") @@ -217,7 +217,7 @@ func TestResponse(t *testing.T) { if (value != undefined) { throw new Error("Expected undefined, but got: " + value); } - value = res.json("glossary.null") + value = res.json("glossary.null") if (value != null) { throw new Error("Expected null, but got: " + value); } @@ -233,8 +233,8 @@ func TestResponse(t *testing.T) { if (value != true) { throw new Error("Expected boolean true, but got: " + value); } - value = res.json("glossary.GlossDiv.GlossList.GlossEntry.GlossDef.title") - if (value != "example glossary") + value = res.json("glossary.GlossDiv.GlossList.GlossEntry.GlossDef.title") + if (value != "example glossary") { throw new Error("Expected 'example glossary'', but got: " + value); } value = res.json("glossary.friends.#.first")[0] @@ -248,11 +248,11 @@ func TestResponse(t *testing.T) { t.Run("SubmitForm", func(t *testing.T) { t.Run("withoutArgs", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/forms/post"); + var res = http.request("GET", "HTTPBIN_URL/forms/post"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.submitForm() if (res.status != 200) { throw new Error("wrong status: " + res.status); } - let data = res.json().form + var data = res.json().form if (data.custname[0] !== "" || data.extradata !== undefined || data.comments[0] !== "" || @@ -267,11 +267,11 @@ func TestResponse(t *testing.T) { t.Run("withFields", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/forms/post"); + var res = http.request("GET", "HTTPBIN_URL/forms/post"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.submitForm({ fields: { custname: "test", extradata: "test2" } }) if (res.status != 200) { throw new Error("wrong status: " + res.status); } - let data = res.json().form + var data = res.json().form if (data.custname[0] !== "test" || data.extradata[0] !== "test2" || data.comments[0] !== "" || @@ -286,11 +286,11 @@ func TestResponse(t *testing.T) { t.Run("withRequestParams", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/forms/post"); + var res = http.request("GET", "HTTPBIN_URL/forms/post"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.submitForm({ params: { headers: { "My-Fancy-Header": "SomeValue" } }}) if (res.status != 200) { throw new Error("wrong status: " + res.status); } - let headers = res.json().headers + var headers = res.json().headers if (headers["My-Fancy-Header"][0] !== "SomeValue" ) { throw new Error("incorrect headers: " + JSON.stringify(headers)); } `)) assert.NoError(t, err) @@ -299,11 +299,11 @@ func TestResponse(t *testing.T) { t.Run("withFormSelector", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/forms/post"); + var res = http.request("GET", "HTTPBIN_URL/forms/post"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.submitForm({ formSelector: 'form[method="post"]' }) if (res.status != 200) { throw new Error("wrong status: " + res.status); } - let data = res.json().form + var data = res.json().form if (data.custname[0] !== "" || data.extradata !== undefined || data.comments[0] !== "" || @@ -318,7 +318,7 @@ func TestResponse(t *testing.T) { t.Run("withNonExistentForm", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/forms/post"); + var res = http.request("GET", "HTTPBIN_URL/forms/post"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res.submitForm({ formSelector: "#doesNotExist" }) `)) @@ -327,11 +327,11 @@ func TestResponse(t *testing.T) { t.Run("withGetMethod", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/myforms/get"); + var res = http.request("GET", "HTTPBIN_URL/myforms/get"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.submitForm() if (res.status != 200) { throw new Error("wrong status: " + res.status); } - let data = res.json().query + var data = res.json().query if (data.input_with_value[0] !== "value" || data.input_without_value[0] !== "" || data.select_one[0] !== "yes this option" || @@ -347,7 +347,7 @@ func TestResponse(t *testing.T) { t.Run("ClickLink", func(t *testing.T) { t.Run("withoutArgs", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/links/10/0"); + var res = http.request("GET", "HTTPBIN_URL/links/10/0"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.clickLink() if (res.status != 200) { throw new Error("wrong status: " + res.status); } @@ -358,7 +358,7 @@ func TestResponse(t *testing.T) { t.Run("withSelector", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/links/10/0"); + var res = http.request("GET", "HTTPBIN_URL/links/10/0"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.clickLink({ selector: 'a:nth-child(4)' }) if (res.status != 200) { throw new Error("wrong status: " + res.status); } @@ -369,7 +369,7 @@ func TestResponse(t *testing.T) { t.Run("withNonExistentLink", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL/links/10/0"); + var res = http.request("GET", "HTTPBIN_URL/links/10/0"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.clickLink({ selector: 'a#doesNotExist' }) `)) @@ -378,11 +378,11 @@ func TestResponse(t *testing.T) { t.Run("withRequestParams", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = http.request("GET", "HTTPBIN_URL"); + var res = http.request("GET", "HTTPBIN_URL"); if (res.status != 200) { throw new Error("wrong status: " + res.status); } res = res.clickLink({ selector: 'a[href="/get"]', params: { headers: { "My-Fancy-Header": "SomeValue" } } }) if (res.status != 200) { throw new Error("wrong status: " + res.status); } - let headers = res.json().headers + var headers = res.json().headers if (headers["My-Fancy-Header"][0] !== "SomeValue" ) { throw new Error("incorrect headers: " + JSON.stringify(headers)); } `)) assert.NoError(t, err) diff --git a/js/modules/k6/http/tls_test.go b/js/modules/k6/http/tls_test.go index a23ba69f741..e4416671289 100644 --- a/js/modules/k6/http/tls_test.go +++ b/js/modules/k6/http/tls_test.go @@ -47,7 +47,7 @@ func TestTLS13Support(t *testing.T) { state.Options.Apply(lib.Options{TLSVersion: &lib.TLSVersions{Max: lib.TLSVersion13}}) _, err := common.RunString(rt, tb.Replacer.Replace(` - let resp = http.get("HTTPSBIN_URL/tls-version"); + var resp = http.get("HTTPSBIN_URL/tls-version"); if (resp.body != "tls1.3") { throw new Error("unexpected tls version: " + resp.body); } diff --git a/js/modules/k6/k6_test.go b/js/modules/k6/k6_test.go index 6dbe4c1ef95..49fe8188fe1 100644 --- a/js/modules/k6/k6_test.go +++ b/js/modules/k6/k6_test.go @@ -94,14 +94,14 @@ func TestRandSeed(t *testing.T) { rand := 0.8487305991992138 _, err := common.RunString(rt, fmt.Sprintf(` - let rnd = Math.random(); + var rnd = Math.random(); if (rnd == %.16f) { throw new Error("wrong random: " + rnd); } `, rand)) assert.NoError(t, err) _, err = common.RunString(rt, fmt.Sprintf(` k6.randomSeed(12345) - let rnd = Math.random(); + var rnd = Math.random(); if (rnd != %.16f) { throw new Error("wrong random: " + rnd); } `, rand)) assert.NoError(t, err) @@ -255,7 +255,7 @@ func TestCheck(t *testing.T) { "b": function() { throw new Error("error B") }, }) `) - assert.EqualError(t, err, "Error: error A at a (:3:27(6))") + assert.EqualError(t, err, "Error: error A at :3:28(4)") bufSamples := stats.GetBufferedSamples(samples) if assert.Len(t, bufSamples, 1) { @@ -275,8 +275,8 @@ func TestCheck(t *testing.T) { t.Run("Types", func(t *testing.T) { templates := map[string]string{ "Literal": `k6.check(null,{"check": %s})`, - "Callable": `k6.check(null,{"check": ()=>%s})`, - "Callable/Arg": `k6.check(%s,{"check":(v)=>v})`, + "Callable": `k6.check(null,{"check": function() { return %s; }})`, + "Callable/Arg": `k6.check(%s,{"check": function(v) {return v; }})`, } testdata := map[string]bool{ `0`: false, diff --git a/js/modules/k6/metrics/metrics_test.go b/js/modules/k6/metrics/metrics_test.go index e99b104cbf7..60337c816b6 100644 --- a/js/modules/k6/metrics/metrics_test.go +++ b/js/modules/k6/metrics/metrics_test.go @@ -79,7 +79,7 @@ func TestMetrics(t *testing.T) { isTimeString = `, true` } _, err := common.RunString(rt, - fmt.Sprintf(`let m = new metrics.%s("my_metric"%s)`, fn, isTimeString), + fmt.Sprintf(`var m = new metrics.%s("my_metric"%s)`, fn, isTimeString), ) if !assert.NoError(t, err) { return diff --git a/js/modules/k6/ws/ws_test.go b/js/modules/k6/ws/ws_test.go index f0090a831ba..04363f22dac 100644 --- a/js/modules/k6/ws/ws_test.go +++ b/js/modules/k6/ws/ws_test.go @@ -121,7 +121,7 @@ func TestSession(t *testing.T) { t.Run("connect_ws", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.close() }); if (res.status != 101) { throw new Error("connection failed with status: " + res.status); } @@ -132,7 +132,7 @@ func TestSession(t *testing.T) { t.Run("connect_wss", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = ws.connect("WSSBIN_URL/ws-echo", function(socket){ + var res = ws.connect("WSSBIN_URL/ws-echo", function(socket){ socket.close() }); if (res.status != 101) { throw new Error("TLS connection failed with status: " + res.status); } @@ -143,8 +143,8 @@ func TestSession(t *testing.T) { t.Run("open", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let opened = false; - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var opened = false; + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.on("open", function() { opened = true; socket.close() @@ -158,7 +158,7 @@ func TestSession(t *testing.T) { t.Run("send_receive", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.on("open", function() { socket.send("test") }) @@ -180,8 +180,8 @@ func TestSession(t *testing.T) { t.Run("interval", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let counter = 0; - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var counter = 0; + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.setInterval(function () { counter += 1; if (counter > 2) { socket.close(); } @@ -195,9 +195,9 @@ func TestSession(t *testing.T) { t.Run("timeout", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let start = new Date().getTime(); - let ellapsed = new Date().getTime() - start; - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var start = new Date().getTime(); + var ellapsed = new Date().getTime() - start; + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.setTimeout(function () { ellapsed = new Date().getTime() - start; socket.close(); @@ -213,8 +213,8 @@ func TestSession(t *testing.T) { t.Run("ping", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let pongReceived = false; - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var pongReceived = false; + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.on("open", function(data) { socket.ping(); }); @@ -237,10 +237,10 @@ func TestSession(t *testing.T) { t.Run("multiple_handlers", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let pongReceived = false; - let otherPongReceived = false; + var pongReceived = false; + var otherPongReceived = false; - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.on("open", function(data) { socket.ping(); }); @@ -271,8 +271,8 @@ func TestSession(t *testing.T) { t.Run("client_close", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let closed = false; - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var closed = false; + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.on("open", function() { socket.close() }) @@ -301,8 +301,8 @@ func TestSession(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { _, err := common.RunString(rt, sr(fmt.Sprintf(` - let closed = false; - let res = ws.connect("WSBIN_URL%s", function(socket){ + var closed = false; + var res = ws.connect("WSBIN_URL%s", function(socket){ socket.on("open", function() { socket.send("test"); }) @@ -346,7 +346,7 @@ func TestErrors(t *testing.T) { t.Run("invalid_url", func(t *testing.T) { _, err := common.RunString(rt, ` - let res = ws.connect("INVALID", function(socket){ + var res = ws.connect("INVALID", function(socket){ socket.on("open", function() { socket.close(); }); @@ -358,7 +358,7 @@ func TestErrors(t *testing.T) { t.Run("invalid_url_message_panic", func(t *testing.T) { // Attempting to send a message to a non-existent socket shouldn't panic _, err := common.RunString(rt, ` - let res = ws.connect("INVALID", function(socket){ + var res = ws.connect("INVALID", function(socket){ socket.send("new message"); }); `) @@ -367,7 +367,7 @@ func TestErrors(t *testing.T) { t.Run("error_in_setup", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let res = ws.connect("WSBIN_URL/ws-echo-invalid", function(socket){ + var res = ws.connect("WSBIN_URL/ws-echo-invalid", function(socket){ throw new Error("error in setup"); }); `)) @@ -376,8 +376,8 @@ func TestErrors(t *testing.T) { t.Run("send_after_close", func(t *testing.T) { _, err := common.RunString(rt, sr(` - let hasError = false; - let res = ws.connect("WSBIN_URL/ws-echo-invalid", function(socket){ + var hasError = false; + var res = ws.connect("WSBIN_URL/ws-echo-invalid", function(socket){ socket.on("open", function() { socket.close(); socket.send("test"); @@ -398,7 +398,7 @@ func TestErrors(t *testing.T) { t.Run("error on close", func(t *testing.T) { _, err := common.RunString(rt, sr(` var closed = false; - let res = ws.connect("WSBIN_URL/ws-close", function(socket){ + var res = ws.connect("WSBIN_URL/ws-close", function(socket){ socket.on('open', function open() { socket.setInterval(function timeout() { socket.ping(); @@ -461,7 +461,7 @@ func TestSystemTags(t *testing.T) { t.Run("only "+expectedTag, func(t *testing.T) { state.Options.SystemTags = stats.ToSystemTagSet([]string{expectedTag}) _, err := common.RunString(rt, sr(` - let res = ws.connect("WSBIN_URL/ws-echo", function(socket){ + var res = ws.connect("WSBIN_URL/ws-echo", function(socket){ socket.on("open", function() { socket.send("test") }) @@ -525,7 +525,7 @@ func TestTLSConfig(t *testing.T) { } _, err := common.RunString(rt, sr(` - let res = ws.connect("WSSBIN_URL/ws-close", function(socket){ + var res = ws.connect("WSSBIN_URL/ws-close", function(socket){ socket.close() }); if (res.status != 101) { throw new Error("TLS connection failed with status: " + res.status); } @@ -538,7 +538,7 @@ func TestTLSConfig(t *testing.T) { state.TLSConfig = tb.TLSClientConfig _, err := common.RunString(rt, sr(` - let res = ws.connect("WSSBIN_URL/ws-close", function(socket){ + var res = ws.connect("WSSBIN_URL/ws-close", function(socket){ socket.close() }); if (res.status != 101) {