Best JavaScript code snippet using wpt
extrators-test.js
Source:extrators-test.js
1var extract_jwt = require('../lib/extract_jwt'),2 Request = require('./mock_request');3describe('Token extractor', function() {4 describe('fromHeader', function() {5 var extractor = extract_jwt.fromHeader('test_header');6 it('should return null no when token is present', function() {7 var req = new Request();8 var token = extractor(req);9 expect(token).to.be.null; 10 });11 it('should return the value from the specified header', function() {12 var req = new Request();13 req.headers['test_header'] = 'abcd123'14 var token = extractor(req)15 expect(token).to.equal('abcd123'); 16 });17 });18 describe('fromBodyField', function() {19 var extractor = extract_jwt.fromBodyField('test_field');20 it('should return null when no body is present', function() {21 var req = new Request();22 23 var token = extractor(req);24 expect(token).to.be.null;25 });26 it('should return null when the specified body field is not present', function() {27 var req = new Request();28 req.body = {};29 var token = extractor(req);30 expect(token).to.be.null;31 });32 it('should return the value from the specified body field', function() {33 var req = new Request();34 req.body = {};35 req.body.test_field = 'abcd123';36 var token = extractor(req);37 expect(token).to.equal('abcd123');38 });39 it('should work properly with querystring', function() {40 var req = new Request();41 const querystring = require('querystring');42 req.body = querystring.parse('test_field=abcd123')43 var token = extractor(req);44 expect(token).to.equal('abcd123')45 });46 });47 describe('fromUrlQueryParameter', function() {48 var extractor = extract_jwt.fromUrlQueryParameter('test_param');49 it('should return null when the specified paramter is not present', function() {50 var req = new Request();51 var token = extractor(req);52 expect(token).to.be.null;53 });54 it('should return the value from the specified parameter', function() {55 var req = new Request();56 req.url += '?test_param=abcd123';57 var token = extractor(req);58 expect(token).to.equal('abcd123');59 });60 });61 describe('fromAuthHeaderWithScheme', function() {62 var extractor = extract_jwt.fromAuthHeaderWithScheme('TEST_SCHEME');63 it('should return null when no auth header is present', function() {64 var req = new Request();65 var token = extractor(req);66 expect(token).to.be.null;67 });68 it('should return null when the auth header is present but the auth scheme doesnt match', function() {69 var req = new Request()70 req.headers['authorization'] = "NOT_TEST_SCHEME abcd123";71 var token = extractor(req);72 expect(token).to.be.null;73 });74 it('should return the value from the authorization header with specified auth scheme', function() {75 var req = new Request()76 req.headers['authorization'] = "TEST_SCHEME abcd123";77 var token = extractor(req);78 expect(token).to.equal('abcd123');79 });80 it('should perform a case-insensivite string comparison', function () {81 var req = new Request()82 req.headers['authorization'] = 'test_scheme abcd123';83 var token = extractor(req);84 expect(token).to.equal('abcd123');85 });86 });87 describe('fromAuthHeader', function() {88 89 var extractor = extract_jwt.fromAuthHeaderAsBearerToken();90 it('should return the value from the authorization header with default JWT auth scheme', function() {91 var req = new Request()92 req.headers['authorization'] = "bearer abcd123";93 var token = extractor(req);94 expect(token).to.equal('abcd123');95 });96 });97 98 describe('fromExtractors', function() {99 it('should raise a type error when the extractor is constructed with a non-array argument', function() {100 this_should_throw = function() {101 var extractor = extract_jwt.fromExtractors({})102 }103 expect(this_should_throw).to.throw(TypeError)104 });105 var extractor = extract_jwt.fromExtractors([extract_jwt.fromAuthHeaderAsBearerToken(), extract_jwt.fromHeader('authorization')]);106 it('should return null when no extractor extracts token', function() {107 var req = new Request();108 var token = extractor(req);109 expect(token).to.be.null;110 });111 it('should return token found by least extractor', function() {112 var req = new Request()113 req.headers['authorization'] = "abcd123";114 var token = extractor(req);115 expect(token).to.equal('abcd123');116 });117 it('should return token found by first extractor', function() {118 var req = new Request()119 req.headers['authorization'] = "bearer abcd123";120 var token = extractor(req);121 expect(token).to.equal('abcd123');122 });123 });124 describe('versionOneCompatibility', function () {125 describe('default behavior', function() {126 var extractor = extract_jwt.versionOneCompatibility({});127 it('should return the token in the default "JWT" auth header', function () {128 var req = new Request();129 req.headers['authorization'] = "JWT abcd123";130 var token = extractor(req);131 expect(token).to.equal('abcd123');132 });133 it('should return the token in the default "auth_token" body field', function () {134 var req = new Request();135 req.body = {};136 req.body['auth_token'] = 'xyzabcd';137 var token = extractor(req);138 expect(token).to.equal('xyzabcd');139 });140 it('should return then token in the default "auth_token" query parameter', function () {141 var req = new Request();142 req.url += '?auth_token=abcd123';143 var token = extractor(req);144 expect(token).to.equal('abcd123');145 });146 });147 describe('user supplied parameters', function() {148 it('should return the token in an auth header with a user specified auth scheme', function() {149 var opts = { authScheme: 'MY_CUSTOM_AUTH_SCHEME' };150 var extractor = extract_jwt.versionOneCompatibility(opts);151 var req = new Request();152 req.headers['authorization'] = 'MY_CUSTOM_AUTH_SCHEME deadbeef';153 var token = extractor(req);154 expect(token).to.equal('deadbeef');155 });156 it('should return the token in a user supplied body field', function () {157 var opts = { tokenBodyField: 'CUSTOM_BODY_FIELD' };158 var extractor = extract_jwt.versionOneCompatibility(opts);159 var req = new Request();160 req.body = {};161 req.body['CUSTOM_BODY_FIELD'] = 'badbeef';162 var token = extractor(req);163 expect(token).to.equal('badbeef');164 });165 it('should return the token in a user specified query parameter', function () {166 var opts = { tokenQueryParameterName: 'CustomQueryParam' };167 var extractor = extract_jwt.versionOneCompatibility(opts);168 var req = new Request();169 req.url += '?CustomQueryParam=deadbeef';170 var token = extractor(req);171 expect(token).to.equal('deadbeef');172 });173 });174 });...
helper.ts
Source:helper.ts
1/**2 * @license3 * Copyright 2020 Google LLC4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17import { Endpoint } from '../../../src/api';18import { TEST_HOST, TEST_KEY, TEST_SCHEME } from '../mock_auth';19import { mock, Route } from '../mock_fetch';20export function endpointUrl(endpoint: Endpoint): string {21 return `${TEST_SCHEME}://${TEST_HOST}${endpoint}?key=${TEST_KEY}`;22}23export function mockEndpoint(24 endpoint: Endpoint,25 response: object,26 status = 20027): Route {28 return mock(endpointUrl(endpoint), response, status);...
Using AI Code Generation
1var wptest = require('wptest');2var wptest = require('wptest');3 if (err) {4 console.log(err);5 } else {6 console.log(result);7 }8});9var wptest = require('wptest');10 if (err) {11 console.log(err);12 } else {13 console.log(result);14 }15});16var wptest = require('wptest');17 if (err) {18 console.log(err);19 } else {20 console.log(result);21 }22});23var wptest = require('wptest');24 if (err) {25 console.log(err);26 } else {27 console.log(result);28 }29});30var wptest = require('wptest');31 if (err) {32 console.log(err);33 } else {34 console.log(result);35 }36});37var wptest = require('wptest');38 if (err) {39 console.log(err);40 } else {41 console.log(result);42 }43});44var wptest = require('wptest');45 if (err) {46 console.log(err);47 } else {48 console.log(result);49 }50});
Using AI Code Generation
1var wpt = require('wpt');2wpt.test_scheme(function(err, data) {3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10wpt.test_scheme(function(err, data) {11 if (err) {12 console.log('Error: ' + err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18wpt.test_scheme(function(err, data) {19 if (err) {20 console.log('Error: ' + err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26wpt.test_scheme(function(err, data) {27 if (err) {28 console.log('Error: ' + err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34wpt.test_scheme(function(err, data) {35 if (err) {36 console.log('Error: ' + err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42wpt.test_scheme(function(err, data) {43 if (err) {44 console.log('Error: ' + err);45 } else {46 console.log(data);47 }48});49var wpt = require('wpt');50wpt.test_scheme(function(err, data) {51 if (err) {52 console.log('Error: ' + err);53 } else {54 console.log(data);55 }56});57var wpt = require('wpt');58wpt.test_scheme(function(err, data) {59 if (err) {60 console.log('Error: ' + err);61 } else {62 console.log(data);63 }64});65var wpt = require('wpt');66wpt.test_scheme(function(err, data) {67 if (err) {
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) return console.error(err);5 console.log('Test completed:');6 console.log(' ' + data.data.summary);7 console.log(' ' + data.data.median.firstView.SpeedIndex);8 console.log(' ' + data.data.median.firstView.TTFB);9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12}, function(err, data) {13 if (err) return console.error(err);14 console.log('Test completed:');15 console.log(' ' + data.data.summary);16 console.log(' ' + data.data.median.firstView.SpeedIndex);17 console.log(' ' + data.data.median.firstView.TTFB);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21}, function(err, data) {22 if (err) return console.error(err);23 console.log('Test completed:');24 console.log(' ' + data.data.summary);25 console.log(' ' + data.data.median.firstView.SpeedIndex);26 console.log(' ' +
Using AI Code Generation
1var wpt = require('wpt');2wpt.test_scheme(function(err, result) {3 if (err) {4 console.log(err);5 } else {6 console.log(result);7 }8});9var wpt = require('wpt');10wpt.test_scheme(function(err, result) {11 if (err) {12 console.log(err);13 } else {14 console.log(result);15 }16});17var wpt = require('wpt');18wpt.test_scheme(function(err, result) {19 if (err) {20 console.log(err);21 } else {22 console.log(result);23 }24});25var wpt = require('wpt');26wpt.test_scheme(function(err, result) {27 if (err) {28 console.log(err);29 } else {30 console.log(result);31 }32});33var wpt = require('wpt');34wpt.test_scheme(function(err, result) {35 if (err) {36 console.log(err);37 } else {38 console.log(result);39 }40});41var wpt = require('wpt');42wpt.test_scheme(function(err, result) {43 if (err) {44 console.log(err);45 } else {46 console.log(result);47 }48});49var wpt = require('wpt');50wpt.test_scheme(function(err, result) {51 if (err) {52 console.log(err);53 } else {54 console.log(result);55 }56});57var wpt = require('wpt');58wpt.test_scheme(function(err, result) {59 if (err) {60 console.log(err);61 } else {62 console.log(result);63 }64});65var wpt = require('wpt');66wpt.test_scheme(function(err, result
Using AI Code Generation
1var wptools = require('wptools');2 console.log(err);3 console.log(data);4});5var wptools = require('wptools');6 console.log(err);7 console.log(data);8});9var wptools = require('wptools');10 console.log(err);11 console.log(data);12});13var wptools = require('wptools');14 console.log(err);15 console.log(data);16});17var wptools = require('wptools');18 console.log(err);19 console.log(data);20});21var wptools = require('wptools');22 console.log(err);23 console.log(data);24});25var wptools = require('wptools');26 console.log(err);27 console.log(data);28});29var wptools = require('wptools');30 console.log(err);31 console.log(data);32});
Using AI Code Generation
1var test_scheme = require('wptest').test_scheme;2 if(err) console.log(err);3 else console.log(data);4});5var test_scheme = require('wptest').test_scheme;6 if(err) console.log(err);7 else console.log(data);8});9var test_scheme = require('wptest').test_scheme;10 if(err) console.log(err);11 else console.log(data);12});13var test_scheme = require('wptest').test_scheme;14 if(err) console.log(err);15 else console.log(data);16});17var test_scheme = require('wptest').test_scheme;18 if(err) console.log(err);19 else console.log(data);20});21var test_scheme = require('wptest').test_scheme;22 if(err) console.log(err);23 else console.log(data);24});25var test_scheme = require('wptest').test_scheme;26 if(err) console.log(err);27 else console.log(data);28});29var test_scheme = require('wptest').test_scheme;30 if(err) console.log(err);31 else console.log(data);32});33var test_scheme = require('wptest').test_scheme;
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3console.log(scheme);4console.log(scheme2);5var wptools = require('wptools');6var fs = require('fs');7console.log(scheme);8console.log(scheme2);9var wptools = require('wptools');10var fs = require('fs');11console.log(scheme);12console.log(scheme2);13var wptools = require('wptools');14var fs = require('fs');15console.log(scheme);16console.log(scheme2);17var wptools = require('wptools');18var fs = require('fs');19console.log(scheme);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!