How to use KeySource method in wpt

Best JavaScript code snippet using wpt

index.spec.js

Source:index.spec.js Github

copy

Full Screen

1/*2 * Copyright (c) 2017-2019 Tom Shawver3 */4'use strict'5const _ = require('lodash')6const Cryptex = require('src').Cryptex7const path = require('path')8const originalEnvs = _.clone(process.env)9const fooEnc = 'Q+JfrQS5DtSjqWHu1oO4HqctA2hVw4VhaDQfBCuvO8U='10const key = 'WJcfREHOMttStwb1927PQwpDJgOgRyVoVMODQxx3pK4='11jest.useFakeTimers()12describe('Cryptex Class', () => {13 afterEach(() => {14 process.env = _.clone(originalEnvs)15 })16 describe('Core API', () => {17 it('constructs without options', () => {18 const cryptex = new Cryptex()19 expect(cryptex).toBeDefined()20 expect(cryptex).toBeInstanceOf(Cryptex)21 })22 it('constructs with options', () => {23 const cryptex = new Cryptex({ env: 'foo' })24 expect(cryptex).toBeDefined()25 expect(cryptex).toBeInstanceOf(Cryptex)26 expect(cryptex._opts.env).toEqual('foo')27 })28 it('decrypts secret with hardcoded config', () => {29 const cryptex = new Cryptex({30 config: {31 keySource: 'plaintext',32 keySourceEncoding: 'base64',33 keySourceOpts: { key },34 algorithm: 'aes256',35 secrets: {36 foo: fooEnc37 }38 }39 })40 return expect(cryptex.getSecret('foo')).resolves.toEqual('foo')41 })42 it('decrypts secret with env var config', () => {43 const cryptex = new Cryptex()44 process.env.CRYPTEX_KEYSOURCE = 'plaintext'45 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'46 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key47 process.env.CRYPTEX_ALGORITHM = 'aes256'48 process.env.CRYPTEX_SECRET_FOO = fooEnc49 process.env.CRYPTEX_SECRETENCODING = 'base64'50 cryptex.update()51 return expect(cryptex.getSecret('foo')).resolves.toEqual('foo')52 })53 it('decrypts a base64 string', () => {54 process.env.CRYPTEX_KEYSOURCE = 'plaintext'55 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'56 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key57 const cryptex = new Cryptex()58 return expect(cryptex.decrypt(fooEnc)).resolves.toEqual('foo')59 })60 it('encrypts and decrypts a UTF-8 string', async () => {61 process.env.CRYPTEX_KEYSOURCE = 'plaintext'62 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'63 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key64 const cryptex = new Cryptex()65 const enc = await cryptex.encrypt('foo')66 expect(enc).toMatch(/=$/)67 const dec = await cryptex.decrypt(enc)68 expect(dec).toEqual('foo')69 })70 it('encrypts and decrypts a base64 string', async () => {71 process.env.CRYPTEX_KEYSOURCE = 'plaintext'72 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'73 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key74 const cryptex = new Cryptex()75 const enc = await cryptex.encrypt('Zm9v', 'base64')76 expect(enc).toMatch(/=$/)77 const dec = await cryptex.decrypt(enc)78 expect(dec).toEqual('foo')79 })80 it('loads config from a file', () => {81 const cryptex = new Cryptex({82 file: path.join(__dirname, '../fixtures/cryptex.json')83 })84 return expect(cryptex.getSecret('foo')).resolves.toEqual('bar')85 })86 it('decrypts a secret with mixed configs', () => {87 const cryptex = new Cryptex({88 config: {89 keySource: 'plaintext',90 keySourceEncoding: 'base64',91 keySourceOpts: { key }92 }93 })94 process.env.CRYPTEX_SECRET_FOO = fooEnc95 return expect(cryptex.getSecret('foo')).resolves.toEqual('foo')96 })97 it('retrieves multiple secrets', () => {98 const secrets = {99 foo: 'foo',100 bar: 'bar',101 baz: 'baz'102 }103 const cryptex = new Cryptex({104 config: {105 keySource: 'none',106 algorithm: 'plaintext',107 secretEncoding: 'utf8',108 secrets109 }110 })111 return expect(cryptex.getSecrets(['foo', 'bar', 'baz'])).resolves.toEqual(112 secrets113 )114 })115 it('retrieves multiple secrets with null for any not found', () => {116 const secrets = {117 foo: 'foo',118 bar: 'bar'119 }120 const cryptex = new Cryptex({121 config: {122 keySource: 'none',123 algorithm: 'plaintext',124 secretEncoding: 'utf8',125 secrets126 }127 })128 return expect(129 cryptex.getSecrets(['foo', 'bar', 'baz'], true)130 ).resolves.toEqual({131 foo: 'foo',132 bar: 'bar',133 baz: null134 })135 })136 })137 describe('Failure cases', () => {138 it('prevents module path injections', () => {139 const cryptex = new Cryptex({140 config: {141 keySource: '../encodings/hex'142 }143 })144 process.env.CRYPTEX_SECRET_FOO = fooEnc145 return expect(cryptex.getSecret('foo')).rejects.toThrow()146 })147 it('rejects on missing modules', () => {148 const cryptex = new Cryptex({149 config: {150 keySource: 'foo'151 }152 })153 process.env.CRYPTEX_SECRET_FOO = fooEnc154 return expect(cryptex.getSecret('foo')).rejects.toThrow()155 })156 it('rejects on missing required secrets', () => {157 process.env.CRYPTEX_KEYSOURCE = 'plaintext'158 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'159 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key160 const cryptex = new Cryptex({ config: {} })161 return expect(cryptex.getSecret('foo')).rejects.toThrow()162 })163 it('resolves null on missing optional secrets', () => {164 process.env.CRYPTEX_KEYSOURCE = 'plaintext'165 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'166 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key167 const cryptex = new Cryptex({ config: {} })168 return expect(cryptex.getSecret('foo', true)).resolves.toBeNull()169 })170 it('throws on non-json config', () => {171 process.env.CRYPTEX_FILE = '../somefile.js'172 expect(() => new Cryptex()).toThrow()173 })174 it('falls back to empty config on file not found', () => {175 process.env.CRYPTEX_FILE = 'somefile.json'176 const cryptex = new Cryptex()177 expect(cryptex).toBeDefined()178 })179 it('rejects when no keySource is set', () => {180 const cryptex = new Cryptex({181 config: {182 algorithm: 'plaintext',183 secretEncoding: 'utf8',184 secrets: { foo: 'bar' }185 }186 })187 return expect(cryptex.getSecret('foo')).rejects.toThrow()188 })189 it('retrieves multiple secrets and rejects for any not found', () => {190 const secrets = {191 foo: 'foo',192 bar: 'bar'193 }194 const cryptex = new Cryptex({195 config: {196 keySource: 'none',197 algorithm: 'plaintext',198 secretEncoding: 'utf8',199 secrets200 }201 })202 return expect(cryptex.getSecrets(['foo', 'bar', 'baz'])).rejects.toThrow()203 })204 })205 describe('Key caching', () => {206 it('does not cache when caching is disabled', async () => {207 process.env.CRYPTEX_KEYSOURCE = 'plaintext'208 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'209 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key210 process.env.CRYPTEX_CACHEKEY = 'false'211 const cryptex = new Cryptex()212 await cryptex.decrypt(fooEnc)213 expect(cryptex).not.toHaveProperty('_key')214 })215 it('does not cache when caching is disabled', async () => {216 process.env.CRYPTEX_KEYSOURCE = 'plaintext'217 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'218 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key219 process.env.CRYPTEX_CACHEKEY = 'false'220 const cryptex = new Cryptex()221 await cryptex.decrypt(fooEnc)222 expect(cryptex).not.toHaveProperty('_key')223 })224 it('does not expire cache with timeout=0', async () => {225 process.env.CRYPTEX_KEYSOURCE = 'plaintext'226 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'227 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key228 process.env.CRYPTEX_CACHEKEY = 'true'229 process.env.CRYPTEX_CACHETIMEOUT = '0'230 const cryptex = new Cryptex()231 await cryptex.decrypt(fooEnc)232 jest.advanceTimersByTime(10000)233 expect(cryptex).toHaveProperty('_key')234 })235 it('expires cache after specified timeout', async () => {236 process.env.CRYPTEX_KEYSOURCE = 'plaintext'237 process.env.CRYPTEX_KEYSOURCEENCODING = 'base64'238 process.env.CRYPTEX_KEYSOURCE_PLAINTEXT_KEY = key239 process.env.CRYPTEX_CACHEKEY = 'true'240 process.env.CRYPTEX_CACHETIMEOUT = '2000'241 const cryptex = new Cryptex()242 await cryptex.decrypt(fooEnc)243 jest.advanceTimersByTime(2010)244 expect(cryptex).not.toHaveProperty('_key')245 })246 })...

Full Screen

Full Screen

migration-handler.js

Source:migration-handler.js Github

copy

Full Screen

1/*2 * Migration Handler for updating entities with the latest template3 */4export const migrate = async function() {5 console.log('>> Wc5e: migrating entities');6 //load the models of every entity7 let model = game.system.model;8 //loop through all actors9 for(let actor of game.system.actors) {10 console.log('>> Wc5e: syncing actor '+actor._id);11 var realActor = game.actors.get(actor._id);12 //sync the data structure13 syncObjectStructure('actor', realActor, model.Actor[actor.type], actor.data, 'data');14 }15}16/**17 * This method synchronizes the entity with the original model from template.json18 */19function syncObjectStructure(type, entity, model, entityData, source) {20 addObjectProps(type, entity, model, entityData, source);21 //removeObjectProps(type, entity, model, entityData, source);22}23//FIXME - check fails sometimes and keeps creating keys24function addObjectProps(type, entity, model, entityData, source) {25 //add every missing key or convert it into the new structure26 for(let key in model) {27 var keySource = source+'.'+key;28 //node is an object and has to be processed recursively29 if(Object.prototype.toString.call(model[key]) === '[object Object]') {30 //if the node does not exist - create it31 if(!entityData.hasOwnProperty(key)) {32 console.log('>> Wc5e: adding "'+keySource+'"');33 entity.update({[keySource] : {}});34 entityData[key] = {};35 }36 //If the type of value differs - overwrite it37 else if(typeof(model[key]) !== typeof(entityData[key])) {38 console.log('>> Wc5e: overwriting "'+keySource+'" due to structural changes: "'+typeof(model[key])+'" vs "'+typeof(entityData[key])+'".');39 entity.update({[keySource] : {}});40 entityData[key] = {};41 }42 syncObjectStructure(type, entity, model[key], entityData[key], keySource);43 }44 //node is just a value that will be set45 else if(!entityData.hasOwnProperty(key)) {46 entity.update({[keySource] : model[key]});47 }48 }49}50//FIXME - wrong nodes called - CREATES DEPRECTAED NODES FOR NO REASON51function removeObjectProps(type, entity, model, entityData, source) {52 //remove every obsolete key that is no longer required53 for(let key in entityData) {54 var keySource = source+'.'+key;55 //node is an object and has to be processed recursively56 if(Object.prototype.toString.call(entityData[key]) === '[object Object]') {57 removeObjectProps(type, entity, model[key], entityData[key], source);58 }59 else {60 if(typeof(model) === 'undefined') {61 //console.log('>> WC5e: remove empty node "'+keySource+'"- deprecated');62 entity.update({[keySource] : 'DEPRECATED'});63 }64 else if(typeof(model[key]) === 'undefined' && entityData[key] !== 'DEPRECATED') {65 console.log('>> WC5e: remove "'+keySource+'" - deprecated');66 //console.log(entityData[key]);67 entity.update({[keySource] : 'DEPRECATED'});68 }69 }70 }...

Full Screen

Full Screen

where.js

Source:where.js Github

copy

Full Screen

1//遍历一个对象数组并返回一个包含相匹配的属性-值对的2//所有对象的数组3function where(collection, source) {4 var arr = [];5 // var keySource = Object.getOwnPropertyNames(source);6 var keySource = Object.keys(source);7 // What's in a name?8 //错误的一些方法9 // function hasObj(obj){10 // var key = Object.getOwnPropertyNames(obj); 11 // for(let i = 0;i < key.length;i++){12 // for(let j = 0;j < keySource.length;j++){13 // if()14 // }15 // }16 // }17 // function attributeCount(obj){18 // var count = 0;19 // for(let i in obj){20 // if(obj.hasOwnProperty(i)){21 // count++;22 // }23 // }24 // return count;25 // }26 for(var i in collection){27 var count = 0;28 for(let j = 0;j < keySource.length;j++){ //针对source的属性循环,查找collection元素中是否有指定的source元素29 if(collection[i][keySource[j]]&&source[keySource[j]] == collection[i][keySource[j]]){30 count++;31 }32 }33 if(count == keySource.length){34 arr.push(collection[i]);35 }36 }37 return arr;38}39//测试...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.get(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Albert Einstein');13page.get(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Albert Einstein');18page.get(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Albert Einstein');23page.get(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Albert Einstein');28page.get(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools.page('Albert Einstein');33page.get(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var page = wptools.page('Albert Einstein');38page.get(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var page = wptools.page('Albert Einstein');43page.get(function(err, resp) {44 console.log(resp);45});46var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require("wptoolkit");2var fs = require('fs');3var wpt = new wptoolkit({4 key: fs.readFileSync('key.pem').toString(),5 cert: fs.readFileSync('cert.pem').toString(),6});7 console.log(data);8});9var wptoolkit = require("wptoolkit");10var fs = require('fs');11var wpt = new wptoolkit({12});13 console.log(data);14});15var wptoolkit = require("wptoolkit");16var fs = require('fs');17var wpt = new wptoolkit({

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('President of the United States');3page.get(function(err, response) {4 console.log(response.data);5 console.log(response.infobox);6});7var wptools = require('wptools');8var page = wptools.page('President of the United States');9page.get(function(err, response) {10 console.log(response.data);11 console.log(response.infobox);12});13var wptools = require('wptools');14var page = wptools.page('President of the United States');15page.get(function(err, response) {16 console.log(response.data);17 console.log(response.infobox);18});19var wptools = require('wptools');20var page = wptools.page('President of the United States');21page.get(function(err, response) {22 console.log(response.data);23 console.log(response.infobox);24});25var wptools = require('wptools');26var page = wptools.page('President of the United States');27page.get(function(err, response) {28 console.log(response.data);29 console.log(response.infobox);30});31var wptools = require('wptools');32var page = wptools.page('President of the United States');33page.get(function(err, response) {34 console.log(response.data);35 console.log(response.infobox);36});37var wptools = require('wptools');38var page = wptools.page('President of the United States');39page.get(function(err, response) {40 console.log(response.data);41 console.log(response.infobox);42});43var wptools = require('wptools');44var page = wptools.page('President of the United States');45page.get(function(err, response) {46 console.log(response.data);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./lib/wpt-api');2var fs = require('fs');3var key = fs.readFileSync('./key.txt', 'utf8').trim();4var wpt = new wpt('www.webpagetest.org', key);5 if (err) return console.log(err);6 console.log(data);7});

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