How to use invalidUsages method in wpt

Best JavaScript code snippet using wpt

test-webcrypto-keygen.js

Source:test-webcrypto-keygen.js Github

copy

Full Screen

1'use strict';2const common = require('../common');3if (!common.hasCrypto)4 common.skip('missing crypto');5const assert = require('assert');6const { subtle, CryptoKey } = require('crypto').webcrypto;7const allUsages = [8 'encrypt',9 'decrypt',10 'sign',11 'verify',12 'deriveBits',13 'deriveKey',14 'wrapKey',15 'unwrapKey',16];17const vectors = {18 'AES-CTR': {19 algorithm: { length: 256 },20 usages: [21 'encrypt',22 'decrypt',23 'wrapKey',24 'unwrapKey',25 ],26 mandatoryUsages: []27 },28 'AES-CBC': {29 algorithm: { length: 256 },30 usages: [31 'encrypt',32 'decrypt',33 'wrapKey',34 'unwrapKey',35 ],36 mandatoryUsages: []37 },38 'AES-GCM': {39 algorithm: { length: 256 },40 usages: [41 'encrypt',42 'decrypt',43 'wrapKey',44 'unwrapKey',45 ],46 mandatoryUsages: []47 },48 'AES-KW': {49 algorithm: { length: 256 },50 usages: [51 'wrapKey',52 'unwrapKey',53 ],54 mandatoryUsages: []55 },56 'HMAC': {57 algorithm: { length: 256, hash: 'SHA-256' },58 usages: [59 'sign',60 'verify',61 ],62 mandatoryUsages: []63 },64 'RSASSA-PKCS1-v1_5': {65 algorithm: {66 modulusLength: 1024,67 publicExponent: new Uint8Array([1, 0, 1]),68 hash: 'SHA-256'69 },70 usages: [71 'sign',72 'verify',73 ],74 mandatoryUsages: ['sign'],75 },76 'RSA-PSS': {77 algorithm: {78 modulusLength: 1024,79 publicExponent: new Uint8Array([1, 0, 1]),80 hash: 'SHA-256'81 },82 usages: [83 'sign',84 'verify',85 ],86 mandatoryUsages: ['sign']87 },88 'RSA-OAEP': {89 algorithm: {90 modulusLength: 1024,91 publicExponent: new Uint8Array([1, 0, 1]),92 hash: 'SHA-256'93 },94 usages: [95 'encrypt',96 'decrypt',97 'wrapKey',98 'unwrapKey',99 ],100 mandatoryUsages: [101 'decrypt',102 'unwrapKey',103 ]104 },105 'ECDSA': {106 algorithm: { namedCurve: 'P-521' },107 usages: [108 'sign',109 'verify',110 ],111 mandatoryUsages: ['sign']112 },113 'ECDH': {114 algorithm: { namedCurve: 'P-521' },115 usages: [116 'deriveKey',117 'deriveBits',118 ],119 mandatoryUsages: [120 'deriveKey',121 'deriveBits',122 ]123 },124 'NODE-DSA': {125 algorithm: { modulusLength: 1024, hash: 'SHA-256' },126 usages: [127 'sign',128 'verify',129 ],130 mandatoryUsages: [131 'sign',132 'verify',133 ]134 }135};136// Test invalid algorithms137{138 async function test(algorithm) {139 return assert.rejects(140 // The extractable and usages values are invalid here also,141 // but the unrecognized algorithm name should be caught first.142 subtle.generateKey(algorithm, 7, ['zebra']), {143 message: /Unrecognized name/144 });145 }146 const tests = [147 'AES',148 { name: 'AES' },149 { name: 'AES-CMAC' },150 { name: 'AES-CFB' },151 { name: 'HMAC', hash: 'MD5' },152 {153 name: 'RSA',154 hash: 'SHA-256',155 modulusLength: 2048,156 publicExponent: new Uint8Array([1, 0, 1])157 },158 {159 name: 'RSA-PSS',160 hash: 'SHA',161 modulusLength: 2048,162 publicExponent: new Uint8Array([1, 0, 1])163 },164 {165 name: 'EC',166 namedCurve: 'P521'167 },168 ].map(async (algorithm) => test(algorithm));169 Promise.all(tests).then(common.mustCall());170}171// Test bad usages172{173 async function test(name) {174 const invalidUsages = [];175 allUsages.forEach((usage) => {176 if (!vectors[name].usages.includes(usage))177 invalidUsages.push(usage);178 });179 return assert.rejects(180 subtle.generateKey(181 {182 name, ...vectors[name].algorithm183 },184 true,185 invalidUsages),186 { message: /Unsupported key usage/ });187 }188 const tests = Object.keys(vectors).map(test);189 Promise.all(tests).then(common.mustCall());190}191// Test RSA key generation192{193 async function test(194 name,195 modulusLength,196 publicExponent,197 hash,198 privateUsages,199 publicUsages = privateUsages) {200 let usages = privateUsages;201 if (publicUsages !== privateUsages)202 usages = usages.concat(publicUsages);203 const { publicKey, privateKey } = await subtle.generateKey({204 name,205 modulusLength,206 publicExponent,207 hash208 }, true, usages);209 assert(publicKey);210 assert(privateKey);211 assert(publicKey instanceof CryptoKey);212 assert(privateKey instanceof CryptoKey);213 assert.strictEqual(publicKey.type, 'public');214 assert.strictEqual(privateKey.type, 'private');215 assert.strictEqual(publicKey.extractable, true);216 assert.strictEqual(privateKey.extractable, true);217 assert.deepStrictEqual(publicKey.usages, publicUsages);218 assert.deepStrictEqual(privateKey.usages, privateUsages);219 assert.strictEqual(publicKey.algorithm.name, name);220 assert.strictEqual(publicKey.algorithm.modulusLength, modulusLength);221 assert.deepStrictEqual(publicKey.algorithm.publicExponent, publicExponent);222 assert.strictEqual(publicKey.algorithm.hash.name, hash);223 assert.strictEqual(privateKey.algorithm.name, name);224 assert.strictEqual(privateKey.algorithm.modulusLength, modulusLength);225 assert.deepStrictEqual(privateKey.algorithm.publicExponent, publicExponent);226 assert.strictEqual(privateKey.algorithm.hash.name, hash);227 // Missing parameters228 await assert.rejects(229 subtle.generateKey({ name, publicExponent, hash }, true, usages), {230 code: 'ERR_INVALID_ARG_TYPE'231 });232 await assert.rejects(233 subtle.generateKey({ name, modulusLength, hash }, true, usages), {234 code: 'ERR_INVALID_ARG_TYPE'235 });236 await assert.rejects(237 subtle.generateKey({ name, modulusLength }, true, usages), {238 code: 'ERR_MISSING_OPTION'239 });240 await Promise.all(['', true, {}].map((modulusLength) => {241 return assert.rejects(subtle.generateKey({242 name,243 modulusLength,244 publicExponent,245 hash246 }, true, usages), {247 code: 'ERR_INVALID_ARG_TYPE'248 });249 }));250 await Promise.all(251 [252 '',253 true,254 {},255 1,256 [],257 new Uint32Array(2),258 ].map((publicExponent) => {259 return assert.rejects(260 subtle.generateKey(261 { name, modulusLength, publicExponent, hash }, true, usages),262 { code: 'ERR_INVALID_ARG_TYPE' });263 }));264 await Promise.all([true, {}, 1, []].map((hash) => {265 return assert.rejects(subtle.generateKey({266 name,267 modulusLength,268 publicExponent,269 hash270 }, true, usages), {271 message: /Unrecognized name/272 });273 }));274 await Promise.all(['', {}, 1, []].map((extractable) => {275 return assert.rejects(subtle.generateKey({276 name,277 modulusLength,278 publicExponent,279 hash280 }, extractable, usages), {281 code: 'ERR_INVALID_ARG_TYPE'282 });283 }));284 await Promise.all(['', {}, 1, false].map((usages) => {285 return assert.rejects(subtle.generateKey({286 name,287 modulusLength,288 publicExponent,289 hash290 }, true, usages), {291 code: 'ERR_INVALID_ARG_TYPE'292 });293 }));294 }295 const kTests = [296 [297 'RSASSA-PKCS1-v1_5',298 1024,299 Buffer.from([1, 0, 1]),300 'SHA-256',301 ['sign'],302 ['verify'],303 ],304 [305 'RSA-PSS',306 2048,307 Buffer.from([1, 0, 1]),308 'SHA-512',309 ['sign'],310 ['verify'],311 ],312 [313 'RSA-OAEP',314 1024,315 Buffer.from([3]),316 'SHA-384',317 ['decrypt', 'unwrapKey'],318 ['encrypt', 'wrapKey'],319 ],320 ];321 const tests = kTests.map((args) => test(...args));322 Promise.all(tests).then(common.mustCall());323}324// Test EC Key Generation325{326 async function test(327 name,328 namedCurve,329 privateUsages,330 publicUsages = privateUsages) {331 let usages = privateUsages;332 if (publicUsages !== privateUsages)333 usages = usages.concat(publicUsages);334 const { publicKey, privateKey } = await subtle.generateKey({335 name,336 namedCurve337 }, true, usages);338 assert(publicKey);339 assert(privateKey);340 assert.strictEqual(publicKey.type, 'public');341 assert.strictEqual(privateKey.type, 'private');342 assert.strictEqual(publicKey.extractable, true);343 assert.strictEqual(privateKey.extractable, true);344 assert.deepStrictEqual(publicKey.usages, publicUsages);345 assert.deepStrictEqual(privateKey.usages, privateUsages);346 assert.strictEqual(publicKey.algorithm.name, name);347 assert.strictEqual(privateKey.algorithm.name, name);348 assert.strictEqual(publicKey.algorithm.namedCurve, namedCurve);349 assert.strictEqual(privateKey.algorithm.namedCurve, namedCurve);350 // Invalid parameters351 [1, true, {}, [], undefined, null].forEach(async (namedCurve) => {352 await assert.rejects(353 subtle.generateKey({ name, namedCurve }, true, privateUsages), {354 code: 'ERR_INVALID_ARG_TYPE'355 });356 });357 }358 const kTests = [359 [360 'ECDSA',361 'P-384',362 ['sign'],363 ['verify'],364 ],365 [366 'ECDSA',367 'P-521',368 ['sign'],369 ['verify'],370 ],371 [372 'ECDH',373 'P-384',374 ['deriveKey', 'deriveBits'],375 [],376 ],377 [378 'ECDH',379 'P-521',380 ['deriveKey', 'deriveBits'],381 [],382 ],383 ];384 const tests = kTests.map((args) => test(...args));385 // Test bad parameters386 Promise.all(tests).then(common.mustCall());387}388// Test AES Key Generation389{390 async function test(name, length, usages) {391 const key = await subtle.generateKey({392 name,393 length394 }, true, usages);395 assert(key);396 assert.strictEqual(key.type, 'secret');397 assert.strictEqual(key.extractable, true);398 assert.deepStrictEqual(key.usages, usages);399 assert.strictEqual(key.algorithm.name, name);400 assert.strictEqual(key.algorithm.length, length);401 // Invalid parameters402 [1, 100, 257].forEach(async (length) => {403 await assert.rejects(404 subtle.generateKey({ name, length }, true, usages), {405 code: 'ERR_INVALID_ARG_VALUE'406 });407 });408 ['', {}, [], false, null, undefined].forEach(async (length) => {409 await assert.rejects(410 subtle.generateKey({ name, length }, true, usages), {411 code: 'ERR_INVALID_ARG_TYPE'412 });413 });414 }415 const kTests = [416 [ 'AES-CTR', 128, ['encrypt', 'decrypt', 'wrapKey']],417 [ 'AES-CTR', 256, ['encrypt', 'decrypt', 'unwrapKey']],418 [ 'AES-CBC', 128, ['encrypt', 'decrypt']],419 [ 'AES-CBC', 256, ['encrypt', 'decrypt']],420 [ 'AES-GCM', 128, ['encrypt', 'decrypt']],421 [ 'AES-GCM', 256, ['encrypt', 'decrypt']],422 [ 'AES-KW', 128, ['wrapKey', 'unwrapKey']],423 [ 'AES-KW', 256, ['wrapKey', 'unwrapKey']],424 ];425 const tests = Promise.all(kTests.map((args) => test(...args)));426 tests.then(common.mustCall());427}428// Test HMAC Key Generation429{430 async function test(length, hash, usages) {431 const key = await subtle.generateKey({432 name: 'HMAC',433 length,434 hash435 }, true, usages);436 if (length === undefined) {437 switch (hash) {438 case 'SHA-1': length = 160; break;439 case 'SHA-256': length = 256; break;440 case 'SHA-384': length = 384; break;441 case 'SHA-512': length = 512; break;442 }443 }444 assert(key);445 assert.strictEqual(key.type, 'secret');446 assert.strictEqual(key.extractable, true);447 assert.deepStrictEqual(key.usages, usages);448 assert.strictEqual(key.algorithm.name, 'HMAC');449 assert.strictEqual(key.algorithm.length, length);450 assert.strictEqual(key.algorithm.hash.name, hash);451 ['', {}, [], false, null].forEach(async (length) => {452 await assert.rejects(453 subtle.generateKey({ name: 'HMAC', length, hash }, true, usages), {454 code: 'ERR_INVALID_ARG_TYPE'455 });456 });457 [1, {}, [], false, null].forEach(async (hash) => {458 await assert.rejects(459 subtle.generateKey({ name: 'HMAC', length, hash }, true, usages), {460 message: /Unrecognized name/461 });462 });463 }464 const kTests = [465 [ undefined, 'SHA-1', ['sign', 'verify']],466 [ undefined, 'SHA-256', ['sign', 'verify']],467 [ undefined, 'SHA-384', ['sign', 'verify']],468 [ undefined, 'SHA-512', ['sign', 'verify']],469 [ 128, 'SHA-256', ['sign', 'verify']],470 [ 1024, 'SHA-512', ['sign', 'verify']],471 ];472 const tests = Promise.all(kTests.map((args) => test(...args)));473 tests.then(common.mustCall());474}475// Test NODE-DSA key generation476{477 async function test(478 name,479 modulusLength,480 hash,481 privateUsages,482 publicUsages = privateUsages) {483 let usages = privateUsages;484 if (publicUsages !== privateUsages)485 usages = usages.concat(publicUsages);486 const { publicKey, privateKey } = await subtle.generateKey({487 name,488 modulusLength,489 hash490 }, true, usages);491 assert(publicKey);492 assert(privateKey);493 assert.strictEqual(publicKey.type, 'public');494 assert.strictEqual(privateKey.type, 'private');495 assert.strictEqual(publicKey.extractable, true);496 assert.strictEqual(privateKey.extractable, true);497 assert.deepStrictEqual(publicKey.usages, publicUsages);498 assert.deepStrictEqual(privateKey.usages, privateUsages);499 assert.strictEqual(publicKey.algorithm.name, name);500 assert.strictEqual(publicKey.algorithm.modulusLength, modulusLength);501 assert.strictEqual(publicKey.algorithm.hash.name, hash);502 assert.strictEqual(privateKey.algorithm.name, name);503 assert.strictEqual(privateKey.algorithm.modulusLength, modulusLength);504 assert.strictEqual(privateKey.algorithm.hash.name, hash);505 // Missing parameters506 await assert.rejects(507 subtle.generateKey({ name, hash }, true, usages), {508 code: 'ERR_INVALID_ARG_TYPE'509 });510 await assert.rejects(511 subtle.generateKey({ name, modulusLength }, true, usages), {512 code: 'ERR_MISSING_OPTION'513 });514 await Promise.all(['', true, {}].map((modulusLength) => {515 return assert.rejects(subtle.generateKey({516 name,517 modulusLength,518 hash519 }, true, usages), {520 code: 'ERR_INVALID_ARG_TYPE'521 });522 }));523 await Promise.all([true, {}, 1, []].map((hash) => {524 return assert.rejects(subtle.generateKey({525 name,526 modulusLength,527 hash528 }, true, usages), {529 message: /Unrecognized name/530 });531 }));532 await Promise.all(['', {}, 1, []].map((extractable) => {533 return assert.rejects(subtle.generateKey({534 name,535 modulusLength,536 hash537 }, extractable, usages), {538 code: 'ERR_INVALID_ARG_TYPE'539 });540 }));541 await Promise.all(['', {}, 1, false].map((usages) => {542 return assert.rejects(subtle.generateKey({543 name,544 modulusLength,545 hash546 }, true, usages), {547 code: 'ERR_INVALID_ARG_TYPE'548 });549 }));550 }551 const kTests = [552 [553 'NODE-DSA',554 1024,555 'SHA-256',556 ['sign'],557 ['verify'],558 ],559 ];560 const tests = kTests.map((args) => test(...args));561 Promise.all(tests).then(common.mustCall());562}563// Test NODE-DH key generation564(async function() {565 const { publicKey, privateKey } =566 await subtle.generateKey({567 name: 'NODE-DH',568 group: 'modp15'569 }, true, ['deriveKey']);570 assert(publicKey);571 assert(privateKey);572 assert.strictEqual(publicKey.type, 'public');573 assert.strictEqual(privateKey.type, 'private');574 assert.strictEqual(publicKey.algorithm.name, 'NODE-DH');575 assert.strictEqual(privateKey.algorithm.name, 'NODE-DH');576 assert.strictEqual(publicKey.algorithm.group, 'modp15');577 assert.strictEqual(privateKey.algorithm.group, 'modp15');578})().then(common.mustCall());579// End user code cannot create CryptoKey directly580assert.throws(() => new CryptoKey(), {581 code: 'ERR_OPERATION_FAILED'...

Full Screen

Full Screen

failures.js

Source:failures.js Github

copy

Full Screen

...90 // because there would usually be nearly 2**8 of them,91 // way too many to test. Instead, create every singleton92 // of an illegal usage, and "poison" every valid usage93 // with an illegal one.94 function invalidUsages(validUsages, mandatoryUsages) {95 var results = [];96 var illegalUsages = [];97 ["encrypt", "decrypt", "sign", "verify", "wrapKey", "unwrapKey", "deriveKey", "deriveBits"].forEach(function(usage) {98 if (!validUsages.includes(usage)) {99 illegalUsages.push(usage);100 }101 });102 var goodUsageCombinations = allValidUsages(validUsages, false, mandatoryUsages);103 illegalUsages.forEach(function(illegalUsage) {104 results.push([illegalUsage]);105 goodUsageCombinations.forEach(function(usageCombination) {106 results.push(usageCombination.concat([illegalUsage]));107 });108 });109 return results;110 }111// Now test for properly handling errors112// - Unsupported algorithm113// - Bad usages for algorithm114// - Bad key lengths115 // Algorithm normalization should fail with "Not supported"116 var badAlgorithmNames = [117 "AES",118 {name: "AES"},119 {name: "AES", length: 128},120 {name: "AES-CMAC", length: 128}, // Removed after CR121 {name: "AES-CFB", length: 128}, // Removed after CR122 {name: "HMAC", hash: "MD5"},123 {name: "RSA", hash: "SHA-256", modulusLength: 2048, publicExponent: new Uint8Array([1,0,1])},124 {name: "RSA-PSS", hash: "SHA", modulusLength: 2048, publicExponent: new Uint8Array([1,0,1])},125 {name: "EC", namedCurve: "P521"}126 ];127 // Algorithm normalization failures should be found first128 // - all other parameters can be good or bad, should fail129 // due to NotSupportedError.130 badAlgorithmNames.forEach(function(algorithm) {131 allValidUsages(["decrypt", "sign", "deriveBits"], true, []) // Small search space, shouldn't matter because should fail before used132 .forEach(function(usages) {133 [false, true, "RED", 7].forEach(function(extractable){134 testError(algorithm, extractable, usages, "NotSupportedError", "Bad algorithm");135 });136 });137 });138 // Algorithms normalize okay, but usages bad (though not empty).139 // It shouldn't matter what other extractable is. Should fail140 // due to SyntaxError141 testVectors.forEach(function(vector) {142 var name = vector.name;143 allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {144 invalidUsages(vector.usages, vector.mandatoryUsages).forEach(function(usages) {145 [true].forEach(function(extractable) {146 testError(algorithm, extractable, usages, "SyntaxError", "Bad usages");147 });148 });149 });150 });151 // Other algorithm properties should be checked next, so try good152 // algorithm names and usages, but bad algorithm properties next.153 // - Special case: normally bad usage [] isn't checked until after properties,154 // so it's included in this test case. It should NOT cause an error.155 testVectors.forEach(function(vector) {156 var name = vector.name;157 badAlgorithmPropertySpecifiersFor(name).forEach(function(algorithm) {158 allValidUsages(vector.usages, true, vector.mandatoryUsages)...

Full Screen

Full Screen

aflprep_failures.js

Source:aflprep_failures.js Github

copy

Full Screen

...61 });62 }63 return results;64 }65 function invalidUsages(validUsages, mandatoryUsages) {66 var results = [];67 var illegalUsages = [];68 ["encrypt", "decrypt", "sign", "verify", "wrapKey", "unwrapKey", "deriveKey", "deriveBits"].forEach(function(usage) {69 if (!validUsages.includes(usage)) {70 illegalUsages.push(usage);71 }72 });73 var goodUsageCombinations = allValidUsages(validUsages, false, mandatoryUsages);74 illegalUsages.forEach(function(illegalUsage) {75 results.push([illegalUsage]);76 goodUsageCombinations.forEach(function(usageCombination) {77 results.push(usageCombination.concat([illegalUsage]));78 });79 });80 return results;81 }82 var badAlgorithmNames = [83 "AES",84 {name: "AES"},85 {name: "AES", length: 128},86 {name: "HMAC", hash: "MD5"},87 {name: "RSA", hash: "SHA-256", modulusLength: 2048, publicExponent: new Uint8Array([1,0,1])},88 {name: "RSA-PSS", hash: "SHA", modulusLength: 2048, publicExponent: new Uint8Array([1,0,1])},89 {name: "EC", namedCurve: "P521"}90 ];91 badAlgorithmNames.forEach(function(algorithm) {92 .forEach(function(usages) {93 [false, true, "RED", 7].forEach(function(extractable){94 testError(algorithm, extractable, usages, "NotSupportedError", "Bad algorithm");95 });96 });97 });98 testVectors.forEach(function(vector) {99 var name = vector.name;100 allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {101 invalidUsages(vector.usages, vector.mandatoryUsages).forEach(function(usages) {102 [true].forEach(function(extractable) {103 testError(algorithm, extractable, usages, "SyntaxError", "Bad usages");104 });105 });106 });107 });108 testVectors.forEach(function(vector) {109 var name = vector.name;110 badAlgorithmPropertySpecifiersFor(name).forEach(function(algorithm) {111 allValidUsages(vector.usages, true, vector.mandatoryUsages)112 .forEach(function(usages) {113 [false, true].forEach(function(extractable) {114 if (name.substring(0,2) === "EC") {115 testError(algorithm, extractable, usages, "NotSupportedError", "Bad algorithm property");...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.invalidUsages('www.google.com', function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10{11 {12 },13 {14 }15}16wpt.invalidUsages('www.google.com', {17}, function(err, data) {18 if (err) {19 console.log('Error: ' + err);20 } else {21 console.log(data);22 }23});24{25 {26 },27 {28 }29}30var wpt = require('webpagetest');31var wpt = new WebPageTest('www.webpagetest.org');32wpt.testStatus('131212_9P_3F6', function(err, data) {33 if (err) {34 console.log('Error: ' + err);35 } else {36 console.log(data);37 }38});39{40 "data": {41 "data": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.getLocations(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getLocations(function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('wpt');29var wpt = new WebPageTest('www.webpagetest.org');30wpt.getLocations(function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wpt = require('wpt');38var wpt = new WebPageTest('www.webpagetest.org');39wpt.getLocations(function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wpt = require('wpt');47var wpt = new WebPageTest('www.webpagetest.org');48wpt.getLocations(function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wpt = require('wpt');56var wpt = new WebPageTest('www.webpagetest.org');57wpt.getLocations(function(err, data) {58 if (err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./lib/webpagetest');2var util = require('util');3var wpt = new WebPageTest('www.webpagetest.org', 'A.1b1d2c3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9u0v1w2x3y4z5');4}, function(err, data) {5 if (err) {6 return console.error(err);7 }8 console.log('Test started: ' + data.data.testId);9 console.log('View your test at: ' + data.data.userUrl);10 wpt.getTestResults(data.data.testId, function(err, data) {11 if (err) {12 return console.error(err);13 }14 console.log(util.inspect(data.data, false, null));15 });16});17var request = require('request');18var util = require('util');19var WebPageTest = function(host, key) {20 this.host = host;21 this.key = key;22 this.invalidUsages = function() {23 return 'Invalid Usages';24 };25};26WebPageTest.prototype.runTest = function(url, options, callback) {27 var self = this;28 var testUrl = self.apiRoot + 'k=' + self.key + '&f=json&url=' + url;29 if (options) {30 for (var key in options) {31 testUrl += '&' + key + '=' + options[key];32 }33 }34 request(testUrl, function(err, res, body) {35 if (err) {36 return callback(err);37 }38 if (res.statusCode !== 200) {39 return callback(new Error('Bad status code: ' + res.statusCode));40 }41 try {42 var data = JSON.parse(body);43 } catch (e) {44 return callback(e);45 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const test = wpt('API_KEY');3test.invalidUsages(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10const wpt = require('webpagetest');11const test = wpt('API_KEY');12test.getLocations(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19const wpt = require('webpagetest');20const test = wpt('API_KEY');21test.getTesters(function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});

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.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful