How to use makeRuntime method of x509 Package

Best K6 code snippet using x509.makeRuntime

x509_test.go

Source:x509_test.go Github

copy

Full Screen

...25 "testing"26 "github.com/runner-mei/gojs"27 "github.com/stretchr/testify/assert"28)29func makeRuntime() *gojs.Runtime {30 rt := gojs.New()31 rt.Bind("x509", New())32 return rt33}34type Material struct {35 dsaCertificate string36 ecdsaCertificate string37 rsaCertificate string38 publicKey string39}40var material = Material{ //nolint:gochecknoglobals41 dsaCertificate: `-----BEGIN CERTIFICATE-----42MIIFnzCCBUSgAwIBAgIJAPOE4rArGHVcMAsGCWCGSAFlAwQDAjCBsTELMAkGA1UE43BhMCWloxGTAXBgNVBAgMEEtvcHVuY2V6aXMgS3JhaXMxETAPBgNVBAcMCEFzaHRp44bm9rMRwwGgYDVQQKDBNFeHVtYnJhbiBDb252ZW50aW9uMRkwFwYDVQQLDBBFeHVt45YnJhbiBDb3VuY2lsMRUwEwYDVQQDDAxleGNvdW5jaWwuenoxJDAiBgkqhkiG9w0B46CQEWFWV4Y291bmNpbEBleGFtcGxlLmNvbTAeFw0xOTA1MTAwNDE2MDZaFw0xOTA247MDkwNDE2MDZaMIGxMQswCQYDVQQGEwJaWjEZMBcGA1UECAwQS29wdW5jZXppcyBL48cmFpczERMA8GA1UEBwwIQXNodGlub2sxHDAaBgNVBAoME0V4dW1icmFuIENvbnZl49bnRpb24xGTAXBgNVBAsMEEV4dW1icmFuIENvdW5jaWwxFTATBgNVBAMMDGV4Y29150bmNpbC56ejEkMCIGCSqGSIb3DQEJARYVZXhjb3VuY2lsQGV4YW1wbGUuY29tMIID51RjCCAjkGByqGSM44BAEwggIsAoIBAQCKv/tJtwgLJGrvas2YQmqgjfoQ5s9uQRO952+9ELCu4Lstn9nsjmER/+CgXCrAQG/jUKdT6tpz9bUVYspcn+gF2YkDugSbMb4Uci53FbWjuFSYD7xIe7APGprgogJZeNO6v9vFWLJak4d35Olej1HLQpVPtz5NdR9unh1a54B9sODuRtnZDJsGWuEYbNN0nbjQReBLwbn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GWh0dHA690Ly9wcmVzcy5leGNvdW5jaWwuenqGJ2h0dHA6Ly9sZWFybmluZy5leGNvdW5jaWwu91enovaW5kZXguaHRtbDAKBggqhkjOPQQDAgNHADBEAiA/X4Y+Zaw4ziqL4grkY+rm92srWfS/JGxLvN49r68cczSwIgWEXFIHMwE+OhKC6z01mIPe2G2CguYHukWyL+BHtT93+20=94-----END CERTIFICATE-----`,95 rsaCertificate: `-----BEGIN CERTIFICATE-----96MIIE6zCCA9OgAwIBAgICBNIwDQYJKoZIhvcNAQELBQAwgdsxCzAJBgNVBAYTAlpa97MRkwFwYDVQQIExBLb3B1bmNlemlzIEtyYWlzMREwDwYDVQQHEwhBc2h0aW5vazEa98MBgGA1UECRMRMjIxQiBCYWtlciBTdHJlZXQxDjAMBgNVBBETBTk5OTk5MRwwGgYD99VQQKExNFeHVtYnJhbiBDb252ZW50aW9uMT0wFwYDVQQLExBFeHVtYnJhbiBDb3Vu100Y2lsMCIGA1UECxMbRXh1bWJyYW4gSmFuaXRvcmlhbCBTZXJ2aWNlMRUwEwYDVQQD101EwxleGNvdW5jaWwuenowHhcNMTkwMTAxMDAwMDAwWhcNMjAwMTAxMDAwMDAwWjCB1022zELMAkGA1UEBhMCWloxGTAXBgNVBAgTEEtvcHVuY2V6aXMgS3JhaXMxETAPBgNV103BAcTCEFzaHRpbm9rMRowGAYDVQQJExEyMjFCIEJha2VyIFN0cmVldDEOMAwGA1UE104ERMFOTk5OTkxHDAaBgNVBAoTE0V4dW1icmFuIENvbnZlbnRpb24xPTAXBgNVBAsT105EEV4dW1icmFuIENvdW5jaWwwIgYDVQQLExtFeHVtYnJhbiBKYW5pdG9yaWFsIFNl106cnZpY2UxFTATBgNVBAMTDGV4Y291bmNpbC56ejCCASIwDQYJKoZIhvcNAQEBBQAD107ggEPADCCAQoCggEBAN/56ke0JBw+VI2xdjUCry2nWZvYZ1Yg2CpcVH23Ztko/4Em108y69i0ZOXavoMe+yHLVBQTP2UjQ0kTC+2OmSZcg2NYAxtfkpEd1gPNGtQdb6j5nga109LIv13rzS7XtTW2Kg2uX0gB8Yi30ZuGy0F5WIL4yoM58jQZYHM4aKvOFpXAlbSIVG110w4NpuL/GsYK/RgYln//0be6AigDJKVdDV6V2BP3RH7EBAXRADhET2QZ1Sxiu7IGG111c/Xiy94RccXXivFjqURN8yR0RY+WPPVLyB7PjYuII324/64aBpQ4/Xz5nvl1A358112WRtg0QDPmOmmUQf9m6VgHUgcrBhoRuXJa8ip3CMCAwEAAaOBtjCBszCBsAYDVR0R113BIGoMIGlghNjb3VuY2lsLmV4dW1icmFuLnp6ghJhYm91dC5leGNvdW5jaWwuenqB114FmlucXVpcmllc0BleGNvdW5jaWwuenqBEnByZXNzQGV4Y291bmNpbC56eocEwAAC115AIcEwAACGYYZaHR0cDovL3ByZXNzLmV4Y291bmNpbC56eoYnaHR0cDovL2xlYXJu116aW5nLmV4Y291bmNpbC56ei9pbmRleC5odG1sMA0GCSqGSIb3DQEBCwUAA4IBAQCI117lVr5wEwAznmV/MxE5vc4gfHppYzszssPPvvGs0QjuDe9AbN26nEuriren2bcGbcS118pVhl25tfIJd5rvgvWKz+nTQCEGVI4BDFio0Jt5+7CADOsSSFGYQIu0BrjA3vCs87119gzg3dNaCY65aH0cJE/dVwiS/F2XTr1zvr+uBPExgrA21+FSIlHM0Dot+VGKdCLEO1206HugOCDBdzKF2hsHeI5LvgXUX5zQ0gnsd93+QuxUmiN7QZZs8tDMD/+efo4OWvp/121xytSVXVn+cECQLg9hVn+Zx3XO2FA0eOzaWEONnUGghT/Ivw06lUxis5tkAoAU93d122ddBqJe0XUeAX8Zr6EJ82123-----END CERTIFICATE-----`,124 publicKey: `-----BEGIN PUBLIC KEY-----125MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXMLr/Y/vUtIFY75jj0YXfp6lQ1267iEIbps3BvRE4isTpxs8fXLnLM8LAuJScxiKyrGnj8EMb7LIHkSMBlz6iVj9atY6127EUEm/VHUnElNquzGyBA50TCfpv6NHPaTvOoB45yQbZ/YB4LO+CsT9eIMDZ4tcU9Z128+xD10ifJhhIwpZUFIQIDAQAB129-----END PUBLIC KEY-----`,130}131func TestParse(t *testing.T) {132 if testing.Short() {133 return134 }135 rt := makeRuntime()136 ctx := context.Background()137 t.Run("DecodeFailure", func(t *testing.T) {138 _, err := rt.RunString(ctx, `139 x509.parse("bad-certificate");`)140 assert.Contains(141 t, err.Error(), "GoError: failed to decode certificate PEM file")142 })143 t.Run("ParseFailure", func(t *testing.T) {144 _, err := rt.RunString(ctx, fmt.Sprintf(`145 var pem = %q;146 x509.parse(pem);`, material.publicKey))147 if assert.Error(t, err) {148 assert.Contains(t,149 err.Error(),150 "GoError: failed to parse certificate",151 )152 }153 })154 t.Run("SignatureAlgorithm", func(t *testing.T) {155 _, err := rt.RunString(ctx, fmt.Sprintf(`156 var pem = %q;157 var cert = x509.parse(pem);158 var value = cert.signatureAlgorithm;159 if (value !== "SHA256-RSA") {160 throw new Error("Bad signature algorithm: " + value);161 }`, material.rsaCertificate))162 assert.NoError(t, err)163 })164 t.Run("Subject", func(t *testing.T) {165 _, err := rt.RunString(ctx, fmt.Sprintf(`166 var pem = %q;167 var cert = x509.parse(pem);168 if (typeof cert.subject !== "object") {169 throw new Error("Bad subject: " + typeof cert.subject);170 }`, material.rsaCertificate))171 assert.NoError(t, err)172 })173 t.Run("SubjectCommonName", func(t *testing.T) {174 _, err := rt.RunString(ctx, fmt.Sprintf(`175 var pem = %q;176 var cert = x509.parse(pem);177 var value = cert.subject ? cert.subject.commonName : null;178 if (value !== "excouncil.zz") {179 throw new Error("Bad subject common name: " + value);180 }`, material.rsaCertificate))181 assert.NoError(t, err)182 })183 t.Run("SubjectCountry", func(t *testing.T) {184 _, err := rt.RunString(ctx, fmt.Sprintf(`185 var pem = %q;186 var cert = x509.parse(pem);187 var value = cert.subject ? cert.subject.country : null;188 if (value !== "ZZ") {189 throw new Error("Bad subject country: " + value);190 }`, material.rsaCertificate))191 assert.NoError(t, err)192 })193 t.Run("SubjectPostalCode", func(t *testing.T) {194 _, err := rt.RunString(ctx, fmt.Sprintf(`195 var pem = %q;196 var cert = x509.parse(pem);197 var value = cert.subject ? cert.subject.postalCode : null;198 if (value !== "99999") {199 throw new Error("Bad subject postal code: " + value);200 }`, material.rsaCertificate))201 assert.NoError(t, err)202 })203 t.Run("SubjectProvince", func(t *testing.T) {204 _, err := rt.RunString(ctx, fmt.Sprintf(`205 var pem = %q;206 var cert = x509.parse(pem);207 var value = cert.subject ? cert.subject.stateOrProvinceName : null;208 if (value !== "Kopuncezis Krais") {209 throw new Error("Bad subject province: " + value);210 }`, material.rsaCertificate))211 assert.NoError(t, err)212 })213 t.Run("SubjectLocality", func(t *testing.T) {214 _, err := rt.RunString(ctx, fmt.Sprintf(`215 var pem = %q;216 var cert = x509.parse(pem);217 var value = cert.subject ? cert.subject.localityName : null;218 if (value !== "Ashtinok") {219 throw new Error("Bad subject locality: " + value);220 }`, material.rsaCertificate))221 assert.NoError(t, err)222 })223 t.Run("SubjectStreetAddress", func(t *testing.T) {224 _, err := rt.RunString(ctx, fmt.Sprintf(`225 var pem = %q;226 var cert = x509.parse(pem);227 var value = cert.subject ? cert.subject.streetAddress : null;228 if (value !== "221B Baker Street") {229 throw new Error("Bad subject street address: " + value);230 }`, material.rsaCertificate))231 assert.NoError(t, err)232 })233 t.Run("SubjectOrganization", func(t *testing.T) {234 _, err := rt.RunString(ctx, fmt.Sprintf(`235 var pem = %q;236 var cert = x509.parse(pem);237 var value = cert.subject ? cert.subject.organizationName : null;238 if (value !== "Exumbran Convention") {239 throw new Error("Bad subject organization: " + value);240 }`, material.rsaCertificate))241 assert.NoError(t, err)242 })243 t.Run("SubjectOrganizationalUnit", func(t *testing.T) {244 _, err := rt.RunString(ctx, fmt.Sprintf(`245 var pem = %q;246 var cert = x509.parse(pem);247 var values =248 cert.subject ? cert.subject.organizationalUnitName : null;249 if (!(250 values.length === 2 &&251 values[0] === "Exumbran Council" &&252 values[1] === "Exumbran Janitorial Service"253 )) {254 throw new Error(255 "Bad subject organizational unit: " + values.join(", ")256 );257 }`, material.rsaCertificate))258 assert.NoError(t, err)259 })260 t.Run("SubjectNames", func(t *testing.T) {261 _, err := rt.RunString(ctx, fmt.Sprintf(`262 var pem = %q;263 var cert = x509.parse(pem);264 var values = cert.subject ? cert.subject.names : null;265 var strings = values266 ? values.map(function(entry) { return entry.type + ": " + entry.value})267 : null;268 Array.prototype.includes =269 function (value) { return this.indexOf(value) !== -1 }270 if (!(271 values &&272 Array.isArray(values) &&273 values.length === 9 &&274 strings.includes("2.5.4.6: ZZ") &&275 strings.includes("2.5.4.8: Kopuncezis Krais") &&276 strings.includes("2.5.4.7: Ashtinok") &&277 strings.includes("2.5.4.9: 221B Baker Street") &&278 strings.includes("2.5.4.17: 99999") &&279 strings.includes("2.5.4.10: Exumbran Convention") &&280 strings.includes("2.5.4.11: Exumbran Council") &&281 strings.includes("2.5.4.11: Exumbran Janitorial Service") &&282 strings.includes("2.5.4.3: excouncil.zz")283 )) {284 throw new Error("Bad subject names");285 }`, material.rsaCertificate))286 assert.NoError(t, err)287 })288 t.Run("Issuer", func(t *testing.T) {289 _, err := rt.RunString(ctx, fmt.Sprintf(`290 var pem = %q;291 var cert = x509.parse(pem);292 if (typeof cert.issuer !== "object") {293 throw new Error("Bad issuer: " + typeof cert.issuer);294 }`, material.rsaCertificate))295 assert.NoError(t, err)296 })297 t.Run("IssuerCommonName", func(t *testing.T) {298 _, err := rt.RunString(ctx, fmt.Sprintf(`299 var pem = %q;300 var cert = x509.parse(pem);301 var value = cert.issuer ? cert.issuer.commonName : null;302 if (value !== "excouncil.zz") {303 throw new Error("Bad issuer common name: " + value);304 }`, material.rsaCertificate))305 assert.NoError(t, err)306 })307 t.Run("IssuerCountry", func(t *testing.T) {308 _, err := rt.RunString(ctx, fmt.Sprintf(`309 var pem = %q;310 var cert = x509.parse(pem);311 var value = cert.issuer ? cert.issuer.country : null;312 if (value !== "ZZ") {313 throw new Error("Bad issuer country: " + value);314 }`, material.rsaCertificate))315 assert.NoError(t, err)316 })317 t.Run("IssuerProvince", func(t *testing.T) {318 _, err := rt.RunString(ctx, fmt.Sprintf(`319 var pem = %q;320 var cert = x509.parse(pem);321 var value = cert.issuer ? cert.issuer.stateOrProvinceName : null;322 if (value !== "Kopuncezis Krais") {323 throw new Error("Bad issuer province: " + value);324 }`, material.rsaCertificate))325 assert.NoError(t, err)326 })327 t.Run("IssuerLocality", func(t *testing.T) {328 _, err := rt.RunString(ctx, fmt.Sprintf(`329 var pem = %q;330 var cert = x509.parse(pem);331 var value = cert.issuer ? cert.issuer.localityName : null;332 if (value !== "Ashtinok") {333 throw new Error("Bad issuer locality: " + value);334 }`, material.rsaCertificate))335 assert.NoError(t, err)336 })337 t.Run("IssuerOrganization", func(t *testing.T) {338 _, err := rt.RunString(ctx, fmt.Sprintf(`339 var pem = %q;340 var cert = x509.parse(pem);341 var value = cert.issuer ? cert.issuer.organizationName : null;342 if (value !== "Exumbran Convention") {343 throw new Error("Bad issuer organization: " + value);344 }`, material.rsaCertificate))345 assert.NoError(t, err)346 })347 t.Run("IssuerNames", func(t *testing.T) {348 _, err := rt.RunString(ctx, fmt.Sprintf(`349 var pem = %q;350 var cert = x509.parse(pem);351 var values = cert.issuer ? cert.issuer.names : null;352 var strings = values353 ? values.map(function(entry) { return entry.type + ": " + entry.value})354 : null;355 Array.prototype.includes =356 function (value) { return this.indexOf(value) !== -1 }357 if (!(358 values &&359 Array.isArray(values) &&360 values.length === 9 &&361 strings.includes("2.5.4.6: ZZ") &&362 strings.includes("2.5.4.8: Kopuncezis Krais") &&363 strings.includes("2.5.4.7: Ashtinok") &&364 strings.includes("2.5.4.9: 221B Baker Street") &&365 strings.includes("2.5.4.17: 99999") &&366 strings.includes("2.5.4.10: Exumbran Convention") &&367 strings.includes("2.5.4.11: Exumbran Council") &&368 strings.includes("2.5.4.11: Exumbran Janitorial Service") &&369 strings.includes("2.5.4.3: excouncil.zz")370 )) {371 throw new Error("Bad subject names");372 }`, material.rsaCertificate))373 assert.NoError(t, err)374 })375 t.Run("NotBefore", func(t *testing.T) {376 _, err := rt.RunString(ctx, fmt.Sprintf(`377 var pem = %q;378 var cert = x509.parse(pem);379 var value = cert.notBefore;380 if (value !== "2019-01-01T00:00:00Z") {381 throw new Error("Bad lower bound: " + value)382 }`, material.rsaCertificate))383 assert.NoError(t, err)384 })385 t.Run("NotAfter", func(t *testing.T) {386 _, err := rt.RunString(ctx, fmt.Sprintf(`387 var pem = %q;388 var cert = x509.parse(pem);389 var value = cert.notAfter;390 if (value !== "2020-01-01T00:00:00Z") {391 throw new Error("Bad upper bound: " + value);392 }`, material.rsaCertificate))393 assert.NoError(t, err)394 })395 t.Run("AltNames", func(t *testing.T) {396 _, err := rt.RunString(ctx, fmt.Sprintf(`397 var pem = %q;398 var cert = x509.parse(pem);399 var values = cert.altNames;400 if (!(401 values.length === 8 &&402 values[0] === "council.exumbran.zz" &&403 values[1] === "about.excouncil.zz" &&404 values[2] === "inquiries@excouncil.zz" &&405 values[3] === "press@excouncil.zz" &&406 values[4] === "192.0.2.0" &&407 values[5] === "192.0.2.25" &&408 values[6] === "http://press.excouncil.zz" &&409 values[7] === "http://learning.excouncil.zz/index.html"410 )) {411 throw new Error("Bad alt names: " + values.join(", "));412 }`, material.rsaCertificate))413 assert.NoError(t, err)414 })415 t.Run("FingerPrint", func(t *testing.T) {416 _, err := rt.RunString(ctx, fmt.Sprintf(`417 var pem = %q;418 var cert = x509.parse(pem);419 var value = cert.fingerPrint;420 var expected = [421 85, 119, 3, 199, 150, 144, 202, 145, 178, 46,422 205, 132, 37, 235, 251, 208, 139, 161, 143, 14423 ]424 if (value.join("") !== expected.join("")) {425 throw new Error("Bad fingerprint: " + value.join(":"));426 }`, material.rsaCertificate))427 assert.NoError(t, err)428 })429 t.Run("PublicKey", func(t *testing.T) {430 _, err := rt.RunString(ctx, fmt.Sprintf(`431 var pem = %q;432 var cert = x509.parse(pem);433 if (typeof cert.publicKey !== "object") {434 throw new Error("Bad public key: " + typeof cert.publicKey);435 }`, material.rsaCertificate))436 assert.NoError(t, err)437 })438 t.Run("RSAPublicKey", func(t *testing.T) {439 _, err := rt.RunString(ctx, fmt.Sprintf(`440 var pem = %q;441 var cert = x509.parse(pem);442 var value = cert.publicKey;443 if (!(444 value &&445 typeof value === "object" &&446 value.algorithm === "RSA" &&447 typeof value.key === "object" &&448 typeof value.key.e === "number" &&449 typeof value.key.n === "object"450 )) {451 throw new Error("Bad RSA public key");452 }`, material.rsaCertificate))453 assert.NoError(t, err)454 })455 t.Run("RSAPublicKeyExponent", func(t *testing.T) {456 _, err := rt.RunString(ctx, fmt.Sprintf(`457 var pem = %q;458 var cert = x509.parse(pem);459 var value = cert.publicKey ? cert.publicKey.key.e : null;460 if (value !== 65537) {461 throw new Error("Bad RSA public key exponent: " + value);462 }`, material.rsaCertificate))463 assert.NoError(t, err)464 })465 t.Run("RSAPublicKeyModulus", func(t *testing.T) {466 _, err := rt.RunString(ctx, fmt.Sprintf(`467 var pem = %q;468 var cert = x509.parse(pem);469 var value = cert.publicKey ? cert.publicKey.key.n.bytes() : null;470 var expected = [471 223, 249, 234, 71, 180, 36, 28, 62, 84, 141, 177, 118, 53, 2, 175,472 45, 167, 89, 155, 216, 103, 86, 32, 216, 42, 92, 84, 125, 183, 102,473 217, 40, 255, 129, 38, 203, 175, 98, 209, 147, 151, 106, 250, 12,474 123, 236, 135, 45, 80, 80, 76, 253, 148, 141, 13, 36, 76, 47, 182,475 58, 100, 153, 114, 13, 141, 96, 12, 109, 126, 74, 68, 119, 88, 15,476 52, 107, 80, 117, 190, 163, 230, 120, 26, 44, 139, 245, 222, 188,477 210, 237, 123, 83, 91, 98, 160, 218, 229, 244, 128, 31, 24, 139,478 125, 25, 184, 108, 180, 23, 149, 136, 47, 140, 168, 51, 159, 35,479 65, 150, 7, 51, 134, 138, 188, 225, 105, 92, 9, 91, 72, 133, 70,480 195, 131, 105, 184, 191, 198, 177, 130, 191, 70, 6, 37, 159, 255,481 244, 109, 238, 128, 138, 0, 201, 41, 87, 67, 87, 165, 118, 4, 253,482 209, 31, 177, 1, 1, 116, 64, 14, 17, 19, 217, 6, 117, 75, 24, 174,483 236, 129, 134, 115, 245, 226, 203, 222, 17, 113, 197, 215, 138,484 241, 99, 169, 68, 77, 243, 36, 116, 69, 143, 150, 60, 245, 75, 200,485 30, 207, 141, 139, 136, 35, 125, 184, 255, 174, 26, 6, 148, 56,486 253, 124, 249, 158, 249, 117, 3, 126, 124, 89, 27, 96, 209, 0, 207,487 152, 233, 166, 81, 7, 253, 155, 165, 96, 29, 72, 28, 172, 24, 104,488 70, 229, 201, 107, 200, 169, 220, 35489 ]490 if (value.join(":") !== expected.join(":")) {491 throw new Error("Bad RSA public key modulus: " + value.join(":"));492 }`, material.rsaCertificate))493 assert.NoError(t, err)494 })495 t.Run("DSAPublicKey", func(t *testing.T) {496 _, err := rt.RunString(ctx, fmt.Sprintf(`497 var pem = %q;498 var cert = x509.parse(pem);499 var value = cert.publicKey;500 if (!(501 value &&502 typeof value === "object" &&503 value.algorithm === "DSA" &&504 typeof value.key.parameters === "object" &&505 typeof value.key.y === "object"506 )) {507 throw new Error("Bad DSA public key");508 }`, material.dsaCertificate))509 assert.NoError(t, err)510 })511 t.Run("ECDSAPublicKey", func(t *testing.T) {512 _, err := rt.RunString(ctx, fmt.Sprintf(`513 var pem = %q;514 var cert = x509.parse(pem);515 var value = cert.publicKey;516 if (!(517 value &&518 typeof value === "object" &&519 value.algorithm === "ECDSA" &&520 typeof value.key.curve === "object" &&521 typeof value.key.x === "object" &&522 typeof value.key.y === "object"523 )) {524 throw new Error("Bad ECDSA public key");525 }`, material.ecdsaCertificate))526 assert.NoError(t, err)527 })528}529func TestGetAltNames(t *testing.T) {530 if testing.Short() {531 return532 }533 rt := makeRuntime()534 ctx := context.Background()535 t.Run("Failure", func(t *testing.T) {536 _, err := rt.RunString(ctx, `537 x509.getAltNames("bad-certificate");`)538 assert.Error(t, err)539 })540 t.Run("Success", func(t *testing.T) {541 _, err := rt.RunString(ctx, fmt.Sprintf(`542 var pem = %q;543 var altNames = x509.getAltNames(pem);544 if (!(545 Array.isArray(altNames) &&546 altNames.length === 8 &&547 altNames[0] === "council.exumbran.zz" &&548 altNames[1] === "about.excouncil.zz" &&549 altNames[2] === "inquiries@excouncil.zz" &&550 altNames[3] === "press@excouncil.zz" &&551 altNames[4] === "192.0.2.0" &&552 altNames[5] === "192.0.2.25" &&553 altNames[6] === "http://press.excouncil.zz" &&554 altNames[7] === "http://learning.excouncil.zz/index.html"555 )) {556 throw new Error("Bad alt names");557 }`, material.rsaCertificate))558 assert.NoError(t, err)559 })560}561func TestGetIssuer(t *testing.T) {562 if testing.Short() {563 return564 }565 rt := makeRuntime()566 ctx := context.Background()567 t.Run("Failure", func(t *testing.T) {568 _, err := rt.RunString(ctx, `569 x509.getIssuer("bad-certificate");`)570 assert.Error(t, err)571 })572 t.Run("Success", func(t *testing.T) {573 _, err := rt.RunString(ctx, fmt.Sprintf(`574 var pem = %q;575 var issuer = x509.getIssuer(pem);576 if (!(577 typeof issuer === "object" &&578 issuer.commonName === "excouncil.zz" &&579 issuer.country === "ZZ" &&580 issuer.stateOrProvinceName === "Kopuncezis Krais" &&581 issuer.localityName === "Ashtinok" &&582 issuer.organizationName === "Exumbran Convention" &&583 Array.isArray(issuer.names) &&584 issuer.names.length === 9585 )) {586 throw new Error("Bad issuer");587 }`, material.rsaCertificate))588 assert.NoError(t, err)589 })590}591func TestGetSubject(t *testing.T) {592 if testing.Short() {593 return594 }595 rt := makeRuntime()596 ctx := context.Background()597 t.Run("Failure", func(t *testing.T) {598 _, err := rt.RunString(ctx, `599 x509.getSubject("bad-certificate");`)600 assert.Error(t, err)601 })602 t.Run("Success", func(t *testing.T) {603 _, err := rt.RunString(ctx, fmt.Sprintf(`604 var pem = %q;605 var subject = x509.getSubject(pem);606 if (!(607 typeof subject === "object" &&608 subject.commonName === "excouncil.zz" &&609 subject.country === "ZZ" &&...

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 priv, _ := rsa.GenerateKey(rand.Reader, 2048)4 notBefore := time.Now()5 notAfter := notBefore.Add(365 * 24 * time.Hour)6 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)7 serialNumber, _ := rand.Int(rand.Reader, serialNumberLimit)8 template := x509.Certificate{9 Subject: pkix.Name{10 Organization: []string{"Acme Co"},11 },12 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},13 }14 derBytes, _ := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)15 fmt.Println(derBytes)16}17import (18func main() {19 certPEMBlock, _ := ioutil.ReadFile(certFile)20 certDERBlock, _ := pem.Decode(certPEMBlock)21 cert, _ := x509.ParseCertificate(certDERBlock.Bytes)22 fmt.Println(cert)23}24import (25func main() {26 priv, _ := rsa.GenerateKey(rand.Reader, 2048)27 notBefore := time.Now()28 notAfter := notBefore.Add(365 * 24 * time.Hour)29 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 certFile, err := ioutil.ReadFile("cert.pem")4 if err != nil {5 fmt.Println(err)6 }7 block, _ := pem.Decode(certFile)8 cert, err := x509.ParseCertificate(block.Bytes)9 if err != nil {10 fmt.Println(err)11 }12 fmt.Println(cert.Subject.CommonName)13 fmt.Println(cert.Subject.Organization)14 fmt.Println(cert.Subject.Country)15 fmt.Println(cert.Subject.Locality)16 fmt.Println(cert.Subject.Province)17 fmt.Println(cert.Subject.StreetAddress)18 fmt.Println(cert.Subject.PostalCode)19 fmt.Println(cert.Subject.SerialNumber)20 fmt.Println(cert.Subject.Names)21 fmt.Println(cert.Subject.ExtraNames)22 fmt.Println(cert.Subject.OrganizationUnits)23 fmt.Println(cert.NotBefore)24 fmt.Println(cert.NotAfter)25 fmt.Println(cert.EmailAddresses)26 fmt.Println(cert.IPAddresses)27 fmt.Println(cert.DNSNames)28 fmt.Println(cert.URIs)29 fmt.Println(cert.ExtraExtensions)30 fmt.Println(cert.BasicConstraintsValid)31 fmt.Println(cert.IsCA)32 fmt.Println(cert.MaxPathLen)33 fmt.Println(cert.MaxPathLenZero)34 fmt.Println(cert.KeyUsage)35 fmt.Println(cert.ExtKeyUsage)36 fmt.Println(cert.UnknownExtKeyUsage)37 fmt.Println(cert.UnknownExtKeyUsage)38 fmt.Println(cert.PermittedDNSDomainsCritical)39 fmt.Println(cert.PermittedDNSDomains)40 fmt.Println(cert.ExcludedDNSDomains)41 fmt.Println(cert.PermittedIPRanges)42 fmt.Println(cert.ExcludedIPRanges)43 fmt.Println(cert.PermittedEmailAddresses)44 fmt.Println(cert.ExcludedEmailAddresses)45 fmt.Println(cert.PermittedURIDomains)46 fmt.Println(cert.ExcludedURIDomains)47 fmt.Println(cert.PolicyIdentifiers)48 fmt.Println(cert.CRLDistributionPoints)49 fmt.Println(cert.PolicyIdentifi

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 x509.CertPool{}4 fmt.Println("Hello, playground")5}6import (7func main() {8 x509.CertPool{}9 fmt.Println("Hello, playground")10}11import (12func main() {13 x509.CertPool{}14 fmt.Println("Hello, playground")15}16import (17func main() {18 x509.CertPool{}19 fmt.Println("Hello, playground")20}21import (22func main() {23 x509.CertPool{}24 fmt.Println("Hello, playground")25}26import (27func main() {28 x509.CertPool{}29 fmt.Println("Hello, playground")30}31import (32func main() {33 x509.CertPool{}34 fmt.Println("Hello, playground")35}36import (37func main() {38 x509.CertPool{}39 fmt.Println("Hello, playground")40}41import (42func main() {43 x509.CertPool{}44 fmt.Println("Hello, playground")45}

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 pemData, err := ioutil.ReadFile("cert.pem")4 if err != nil {5 fmt.Println("Error reading certificate file", err)6 }7 block, _ := pem.Decode(pemData)8 if block == nil {9 fmt.Println("Failed to parse certificate PEM")10 }11 cert, err := x509.ParseCertificate(block.Bytes)12 if err != nil {13 fmt.Println("Failed to parse certificate: " + err.Error())14 }15 pool := x509.NewCertPool()16 pool.AddCert(cert)17 config := &tls.Config{18 Certificates: []tls.Certificate{cert},19 }20 client := &http.Client{Transport: &http.Transport{TLSClientConfig: config}}21}

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cert, _ := x509.ParseCertificate([]byte("pem"))4 fmt.Println(cert)5}6import (7func main() {8 cert, _ := x509.ParseCertificate([]byte("pem"))9 fmt.Println(cert)10}11&{Version:0 SerialNumber:0 SignatureAlgorithm:0 PublicKeyAlgorithm:0 PublicKey:0xc0000b0000 Issuer:[] Subject:[] NotBefore:0001-01-01 00:00:00 +0000 UTC NotAfter:0001-01-01 00:00:00 +0000 UTC KeyUsage:0 ExtKeyUsage:[] UnknownExtKeyUsage:[] BasicConstraintsValid:false IsCA:false MaxPathLen:0 MaxPathLenZero:false SubjectKeyId:[] AuthorityKeyId:[] OCSPServer:[] IssuingCertificateURL:[] DNSNames:[] EmailAddresses:[] IPAddresses:[] URIs:[] PermittedDNSDomainsCritical:false PermittedDNSDomains:[] ExcludedDNSDomains:[] PermittedIPRanges:[] ExcludedIPRanges:[] PermittedEmailAddresses:[] ExcludedEmailAddresses:[] PermittedURIDomains:[] ExcludedURIDomains:[] CRLDistributionPoints:[] PolicyIdentifiers:[] ExtKeyUsageOIDs:[] ExtraEx

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(x509.SystemCertPool())4}5&{map[]}6&{map[lets-encrypt-x3-cross-signed.pem:0xc0000b0c00]}

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 privKey, err := rsa.GenerateKey(rand.Reader, 1024)5 if err != nil {6 fmt.Println("Error generating key")7 }8 cert, err := x509.CreateCertificate(rand.Reader, &x509.Certificate{}, &x509.Certificate{}, &pubKey, privKey)9 if err != nil {10 fmt.Println("Error creating certificate")11 }12 runtimeObj, err := x509.ParseCertificate(cert)13 if err != nil {14 fmt.Println("Error creating runtime object")15 }16 fmt.Println(runtimeObj)17}18&{[48 130 2 208 48 130 2 40 160 3 2 1 2 2 2 0 16 48 13 6 9 42 134 72 134 247 13 1 1 5 5 0 48 81 49 11 48 9 6 3 85 4 6 19 2 85 83 49 11 48 9 6 3 85 4 8 19 2 67 65 49 11 48 9 6 3 85 4 7 19 2 83 70 49 18 48 16 6 3 85 4 10 19 9 71 111 111 103 108 101 32 73 110 49 18 48 16 6 3 85 4 3 19 9 108 111 99 97 108 104 111 115 116 49 24 48 22 6 9 42 134 72 134 247 13 1 9 1 22 11 99 97 64 108 111 99 97 108 104 111 115 116 48 30 23 13 49 54 48 54 49 54

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1import "crypto/x509"2import "fmt"3func main() {4 x509.makeRuntime()5 fmt.Println("Hello World")6}7import "crypto/x509"8import "fmt"9func main() {10 x509.NewCertPool()11 fmt.Println("Hello World")12}

Full Screen

Full Screen

makeRuntime

Using AI Code Generation

copy

Full Screen

1x509.makeRuntime(runtimeName, runtimeDescription, runtimeType, runtimeVersion, runtimeURL, runtimeOrg, runtimeArch, runtimeShasums, runtimeSha256, runtimeExe, runtimeInstaller, runtimeCertPEM, runtimeKeyPEM, runtimeChainPEM, runtimeRootPEM, runtimeClientPEM, runtimeClientKeyPEM, runtimeClientChainPEM, runtimeClientRootPEM, runtimeServerPEM, runtimeServerKeyPEM, runtimeServerChainPEM, runtimeServerRootPEM);2x509.getRuntime(runtimeName, runtimeVersion, runtimeOrg, runtimeArch);3x509.updateRuntime(runtimeName, runtimeDescription, runtimeType, runtimeVersion, runtimeURL, runtimeOrg, runtimeArch, runtimeShasums, runtimeSha256, runtimeExe, runtimeInstaller, runtimeCertPEM, runtimeKeyPEM, runtimeChainPEM, runtimeRootPEM, runtimeClientPEM, runtimeClientKeyPEM, runtimeClientChainPEM, runtimeClientRootPEM, runtimeServerPEM, runtimeServerKeyPEM, runtimeServerChainPEM, runtimeServerRootPEM);4x509.deleteRuntime(runtimeName, runtimeVersion, runtimeOrg, runtimeArch);5x509.getRuntimeList();6x509.makeBusinessPolicy(businessPolicyName, businessPolicyDescription, businessPolicyOrg, businessPolicyArch, businessPolicyVersion, businessPolicyProperties, businessPolicyConstraints);7x509.getBusinessPolicy(businessPolicyName, businessPolicyVersion, businessPolicyOrg, businessPolicyArch);8x509.updateBusinessPolicy(businessPolicyName, businessPolicyDescription, businessPolicyOrg, businessPolicyArch, businessPolicyVersion, businessPolicyProperties, businessPolicyConstraints);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful