How to use kPath method in wpt

Best JavaScript code snippet using wpt

credentials.js

Source:credentials.js Github

copy

Full Screen

1/**2 * Copyright 2017 IBM Corp. All Rights Reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16'use strict';17const {join, parse, resolve, isAbsolute} = require('path');18const {promisify} = require('util');19const {readFile, writeFile, existsSync} = require('fs');20const {homedir} = require('os');21const {cwd} = process;22const untildify = require('untildify');23const NodeRSA = require('node-rsa');24const readFilePromise = promisify(readFile);25const writeFilePromise = promisify(writeFile);26/* All plugins must export this public signature. Initalizes the credentials module.27 * @options is the hash of options the user passes in when creating an instance28 * of the plugin.29 * @imports is a hash of all services this plugin consumes.30 * @register is the callback to be called when the plugin is done initializing.31 */32module.exports = function setup(options, imports, register) {33 const {logging} = imports;34 const logger = logging('credentials');35 logger.methodEntry('setup', options, imports);36 let pathToPrivKey = options.pathPrivKey || join(homedir(), '.ssh', 'id_rsa'); // Private Key Contains the Public Key37 if (!isAbsolute(pathToPrivKey)) {38 logger.debug("The given path %s is not absolute. Resolving", pathToPrivKey);39 pathToPrivKey = untildify(pathToPrivKey);40 }41 const config = {42 pubKPath: pathToPrivKey,43 privKPath: pathToPrivKey,44 encrypted: typeof options.encrypted === 'boolean' ? options.encrypted : true,45 defaultCredPath: options.credsPath || join(cwd(), 'creds.json'),46 readOnly: typeof options.readOnly === 'boolean' ? options.readOnly : true47 };48 logger.debug('Configuration: %o', config);49 if (config.encrypted && (!existsSync(config.pubKPath) || !existsSync(config.privKPath))) {50 throw new Error(`Could not find RSA keys. Check if they exist in the paths: ${config.pubKPath} and ${config.privKPath}.`);51 }52 /**53 * Encrypts a string based on the given public key path.54 * @param {String} toEncrypt The string representation of the object we want to encrypt.55 * @param {String} pubKPath The relative or absolute path to the public RSA key.56 * @return {String} Base64 encoded and encrypted string57 */58 const _encryptStringWithRsaPublicKey = function(toEncrypt, pubKPath) {59 logger.methodEntry('_encryptStringWithRsaPublicKey', '***', pubKPath);60 let buffer = new Buffer(toEncrypt);61 return Promise.resolve(pubKPath)62 .then(resolve)63 .then(absolutePath => readFilePromise(absolutePath, 'utf8'))64 .then(publicKey => new NodeRSA(publicKey).encrypt(toEncrypt, 'base64'))65 .then(value => logger.methodExit('_encryptStringWithRsaPublicKey', value, true));66 };67 /**68 * Decrypts a given string based on the given private key.69 * @param {String} toDecrypt Base64 encoded encrypted string to decrypt70 * @param {String} privKPath The relative or absolute path to the private RSA key.71 * @return {String} The decrypted string utf-8 encoded.72 */73 const _decryptStringWithRsaPrivateKey = function(toDecrypt, privKPath) {74 logger.methodEntry('_decryptStringWithRsaPrivateKey', '***', privKPath);75 let buffer = new Buffer(toDecrypt);76 return Promise.resolve(privKPath)77 .then(resolve)78 .then(absolutePath => readFilePromise(absolutePath, 'utf8'))79 .then(privateKey => new NodeRSA(privateKey).decrypt(toDecrypt, 'utf8'))80 .then(value => logger.methodExit('_decryptStringWithRsaPrivateKey', value, true));81 };82 /**83 * Decrypts a string based on the private key.84 * @param {String} options.credentials Credentials string85 * @param {String} options.privKPath Optional. Absolute or relative path to the private key86 * @return {String} The decrypted string87 */88 const _decryptString = function ({credentials, privKPath}) {89 logger.methodEntry('_decryptString', '***', privKPath);90 const _pathToPrivKey = privKPath || config.privKPath;91 return _decryptStringWithRsaPrivateKey(credentials, _pathToPrivKey)92 .then(value => logger.methodExit('_decryptString', value, true));93 };94 /**95 * Encrypts a string based on the public key.96 * @param {String} options.credentials The string to encrypt97 * @param {String} options.pubKPath Optional. Absolute or relative path to the public key98 * @return {String} The base64 encoded and encrypted string99 */100 const _encryptString = function ({credentials, pubKPath}) {101 logger.methodEntry('_encryptString', '***', pubKPath);102 const _credsStr = typeof credentials !== 'string' ? JSON.stringify(credentials) : credentials;103 const _pubKPath = pubKPath || config.pubKPath;104 return _encryptStringWithRsaPublicKey(_credsStr, _pubKPath)105 .then(value => logger.methodExit('_encryptString', value, true));106 };107 /**108 * Getter method to retrieve the encrypted credentials file. Credentials are stored as an object.109 * @param {String} options.credsPath Absolute or relative path to the credentials file110 * @param {String} options.privKPath Absolute or relative path to the private key111 * @param {Boolean} options.encrypted True if the file is encrypted. Otherwise credentials are stored in clear text.112 * @return {Object} The encrypted credentials object113 */114 const _getCredentials = function ({credsPath, privKPath, encrypted} = {}) {115 logger.methodEntry('_getCredentials', credsPath, privKPath, encrypted);116 let _pathToFile = credsPath || config.defaultCredPath;117 let _pathToPrivKey = privKPath || config.privKPath;118 let _encrypted = encrypted || config.encrypted;119 return Promise.resolve(_pathToFile)120 .then(resolve)121 .then(absolutePath => readFilePromise(absolutePath, 'utf8'))122 .then(fileContent => (_encrypted) ? _decryptString({credentials: fileContent, privKPath: _pathToPrivKey}) : fileContent)123 .then(JSON.parse)124 .then(value => logger.methodExit('_getCredentials', value, true));125 }126 let _storeCredentials;127 let _updateConfig;128 if (!config.readOnly) {129 /**130 * Only availabe if the credentials are modifiable. Encrypts and stores the credentials object.131 * @param {String} options.credsPath Absolute or relative path to the credentials file132 * @param {Object} options.credentials The credentials object we want to store133 * @param {String} options.pubKPath Absolute or relative path to the public key134 */135 _storeCredentials = function ({credsPath, credentials, pubKPath}) {136 logger.methodEntry('_storeCredentials', credsPath, '***', pubKPath);137 let _credsPath = credsPath || config.defaultCredPath;138 if (!config.encrypted) {139 const _credsStr = typeof credentials !== 'string' ? JSON.stringify(credentials) : credentials;140 return writeFilePromise(resolve(_credsPath), _credsStr)141 .then(value => logger.methodExit('_storeCredentials', value));142 }143 else {144 return _encryptString({credentials, pubKPath})145 .then(encrypted => writeFilePromise(resolve(_credsPath), encrypted))146 .then(value => logger.methodExit('_storeCredentials', value, true));147 }148 }149 /**150 * Only availabe if the credentials are modifiable. Makes changes to the config.151 * @param {String} options.pubKPath Path to public key. Normally contained in the private key.152 * @param {String} options.privKPath Path to the private key.153 * @param {Boolean} options.encrypted Identification if the credentials file is locally encrypted.154 * @param {String} options.defaultCredPath Path to the credentials155 */156 _updateConfig = function (updatedConfig) {157 Object.assign(config, updatedConfig);158 if (config.encrypted && (!existsSync(config.pubKPath) || !existsSync(config.privKPath))) {159 throw new Error(`Could not find RSA keys. Check if they exist in the paths: ${config.pubKPath} and ${config.privKPath}.`);160 }161 }162 }163 register(null, {164 credentials: {165 isReadOnly: config.readOnly,166 get: _getCredentials,167 encrypt: _encryptString,168 decrypt: _decryptString,169 store: _storeCredentials,170 updateConfig: _updateConfig171 }172 });173 logger.methodExit('setup');...

Full Screen

Full Screen

Core.js

Source:Core.js Github

copy

Full Screen

1window.Kojak = {};2Kojak.Core = {3 // Enums / constants for non config code4 CLAZZ: 'CLAZZ',5 FUNCTION: 'FUNCTION',6 PAKAGE: 'PAKAGE',7 _REGEX_ALPHA: /^[A-Za-z]+$/,8 // fields9 _uniqueId: 0,10 // Extends obj with {} values. Typically used for creating 'clazzes'11 extend: function(obj) {12 var args, argCount, arg;13 args = Array.prototype.slice.call(arguments, 1);14 for(argCount = 0; argCount < args.length; argCount++){15 arg = args[argCount];16 if(arg){17 for (var prop in arg) {18 obj[prop] = arg[prop];19 }20 }21 }22 return obj;23 },24 // Get a context via a name delimited by periods25 getContext: function(contextPath){26 var contextPathItems, count, currentContextPath, context;27 Kojak.Core.assert(Kojak.Core.isString(contextPath), 'getContext can only be called with a string');28 context = window;29 contextPathItems = contextPath.split('.');30 for(count = 0; count < contextPathItems.length; count++){31 currentContextPath = contextPathItems[count];32 if(typeof(context[currentContextPath]) === 'undefined'){33 return undefined;34 }35 context = context[currentContextPath];36 }37 return context;38 },39 isObject: function(obj) {40 return obj === Object(obj);41 },42 getPropCount: function(obj){43 return Kojak.Core.getKeys(obj).length;44 },45 getKeys: function(obj){46 var keys = [], key;47 Kojak.Core.assert(Kojak.Core.isObject(obj), 'Only use with objects');48 for(key in obj){49 if(obj.hasOwnProperty(key)){50 keys.push(key);51 }52 }53 return keys;54 },55 getValues: function(obj){56 var values = [], key, value;57 Kojak.Core.assert(Kojak.Core.isObject(obj), 'Only use with objects');58 for(key in obj){59 if(obj.hasOwnProperty(key)){60 values.push(obj[key]);61 }62 }63 return values;64 },65 // only tested with array of strings66 unique: function(arr){67 var i, seen = {}, uq = [];68 Kojak.Core.assert(Kojak.Core.isArray(arr), 'Only use unique with arrays');69 for(i = 0; i < arr.length; i++){70 Kojak.Core.assert(Kojak.Core.isString(arr[i]), 'Only use unique with an array of strings');71 if(!seen[arr[i]]){72 uq.push(arr[i]);73 seen[arr[i]] = true;74 }75 }76 return uq;77 },78 // Kojak types - Clazz, Function, Pakage, undefined79 inferKojakType: function(objName, obj){80 var firstChar;81 if(obj && Kojak.Core.isFunction(obj)){82 firstChar = objName.substring(0, 1);83 if(Kojak.Core.isStringOnlyAlphas(firstChar) && firstChar === firstChar.toUpperCase()){84 return Kojak.Core.CLAZZ;85 }86 else {87 return Kojak.Core.FUNCTION;88 }89 }90 else if(obj && obj.constructor && obj.constructor.prototype === Object.prototype){91 return Kojak.Core.PAKAGE;92 }93 else {94 return undefined;95 }96 },97 getPath: function(kPath){98 Kojak.Core.assert(kPath, 'kPath is not defined');99 if(kPath.length < 3 || ! kPath.contains('.')){100 return kPath;101 }102 else{103 return kPath.substring(0, kPath.lastIndexOf('.'));104 }105 },106 getObjName: function(kPath){107 Kojak.Core.assert(kPath, 'kPath is not defined');108 if(kPath.length < 3 || ! kPath.contains('.')){109 return kPath;110 }111 else{112 return kPath.substring(kPath.lastIndexOf('.') + 1);113 }114 },115 // This will only work with kPaths to clazzes. If the function name is part of the path this will fail116 // Use with care117 getPakageName: function(kPath){118 var pathParts;119 Kojak.Core.assert(kPath, 'kPath is not defined');120 pathParts = kPath.split('.');121 if(pathParts.length === 1){122 return kPath;123 }124 else {125 if(pathParts[pathParts.length - 1] === 'prototype'){126 pathParts = pathParts.splice(0, pathParts.length - 1);127 }128 pathParts = pathParts.splice(0, pathParts.length - 1);129 return pathParts.join('.');130 }131 },132 // This will only work with kPaths to clazzes. If the function name is part of the path this will fail133 // Use with care134 getClazzName: function(kPath){135 var pathParts, clazzName = '';136 Kojak.Core.assert(kPath, 'kPath is not defined');137 pathParts = kPath.split('.');138 if(pathParts.length === 1){139 return '';140 }141 else {142 if(pathParts[pathParts.length - 1] === 'prototype'){143 clazzName = '.prototype';144 pathParts = pathParts.splice(0, pathParts.length - 1);145 }146 return pathParts[pathParts.length - 1] + clazzName;147 }148 },149 isStringOnlyAlphas: function(check){150 Kojak.Core.assert(Kojak.Core.isString(check, 'only use with strings'));151 return check.match(Kojak.Core._REGEX_ALPHA);152 },153 isStringArray: function(check){154 var isStringArray = true;155 if(Kojak.Core.isArray(check)){156 check.forEach(function(c){157 if(!Kojak.Core.isString(c)){158 isStringArray = false;159 }160 });161 }162 else {163 isStringArray = false;164 }165 return isStringArray;166 },167 assert: function(test, msg){168 if(!test){169 throw msg;170 }171 },172 uniqueId: function(){173 return ++Kojak.Core._uniqueId;174 }175};176// Add the isXXX type checkers177['Arguments', 'Function', 'String', 'Number', 'Array', 'Date', 'RegExp', 'Boolean'].forEach(function(name) {178 Kojak.Core['is' + name] = function(o) {179 return Object.prototype.toString.call(o) === '[object ' + name + ']';180 };...

Full Screen

Full Screen

ik14.js

Source:ik14.js Github

copy

Full Screen

1/**2 * path module3 */4const iKpath = require('path')5//absolute file path6console.log( __filename )7//absolute directory path8console.log( __dirname )9//base file name10console.log( iKpath.basename(__filename) )11//directory name12console.log( iKpath.dirname(__filename) )13//file extension14console.log( iKpath.extname(__filename) )15//path in object16console.log( iKpath.parse(__filename) )17// concatenate paths18console.log( iKpath.join(__dirname, 'iKanyDirectory', 'iKanyFile.js') )19//resolve20console.log( iKpath.resolve(__dirname, 'file', 'ifhs' ) )21/**22 * 23 * ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3 kPathOptions: {4 userAgent: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.91 Mobile Safari/537.36',5 kpathOptions: {6 userAgent: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.91 Mobile Safari/537.36'7 }8 }9};10wpt.runTest(options, function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2 if (err) return console.error(err);3 console.log('Test status: ' + data.statusText);4});5var wpt = require('wpt');6 if (err) return console.error(err);7 console.log('Test status: ' + data.statusText);8});9var wpt = require('wpt');10 if (err) return console.error(err);11 console.log('Test status: ' + data.statusText);12});13var wpt = require('wpt');14 if (err) return console.error(err);15 console.log('Test status: ' + data.statusText);16});17var wpt = require('wpt');18 if (err) return console.error(err);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var kPath = wpt.kPath;3var wpt = new wpt();4 if (err) {5 console.log(err);6 } else {

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