Best JavaScript code snippet using fast-check-monorepo
configService.js
Source:configService.js
1/*2 * Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U3 *4 * This file is part of iotagent-ul5 *6 * iotagent-ul is free software: you can redistribute it and/or7 * modify it under the terms of the GNU Affero General Public License as8 * published by the Free Software Foundation, either version 3 of the License,9 * or (at your option) any later version.10 *11 * iotagent-ul is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.14 * See the GNU Affero General Public License for more details.15 *16 * You should have received a copy of the GNU Affero General Public17 * License along with iotagent-ul.18 * If not, seehttp://www.gnu.org/licenses/.19 *20 * For those usages not covered by the GNU Affero General Public License21 * please contact with::[iot_support@tid.es]22 */23let config = {};24const fs = require('fs');25let logger = require('logops');26const iotAgentLib = require('iotagent-node-lib');27function anyIsSet(variableSet) {28 for (let i = 0; i < variableSet.length; i++) {29 if (process.env[variableSet[i]]) {30 return true;31 }32 }33 return false;34}35/**36 * For a parameter pointing to a file, check the file exists37 *38 * @param {string} path Path to the file39 */40function fileExists(path) {41 try {42 fs.statSync(path);43 logger.debug(path + ' - File exists.');44 } catch (e) {45 logger.fatal(path + ' - File does not exist.');46 throw Error(path + ' - File does not exist.');47 }48}49function processEnvironmentVariables() {50 const environmentVariables = [51 'IOTA_MQTT_PROTOCOL',52 'IOTA_MQTT_HOST',53 'IOTA_MQTT_PORT',54 'IOTA_MQTT_CA',55 'IOTA_MQTT_CERT',56 'IOTA_MQTT_KEY',57 'IOTA_MQTT_REJECT_UNAUTHORIZED',58 'IOTA_MQTT_USERNAME',59 'IOTA_MQTT_PASSWORD',60 'IOTA_MQTT_QOS',61 'IOTA_MQTT_RETAIN',62 'IOTA_MQTT_RETRIES',63 'IOTA_MQTT_RETRY_TIME',64 'IOTA_MQTT_KEEPALIVE',65 'IOTA_MQTT_AVOID_LEADING_SLASHES',66 'IOTA_MQTT_CLEAN',67 'IOTA_MQTT_CLIENT_ID',68 'IOTA_AMQP_HOST',69 'IOTA_AMQP_PORT',70 'IOTA_AMQP_USERNAME',71 'IOTA_AMQP_PASSWORD',72 'IOTA_AMQP_EXCHANGE',73 'IOTA_AMQP_QUEUE',74 'IOTA_AMQP_DURABLE',75 'IOTA_AMQP_RETRIES',76 'IOTA_AMQP_RETRY_TIME',77 'IOTA_HTTP_HOST',78 'IOTA_HTTP_PORT',79 'IOTA_HTTP_TIMEOUT',80 'IOTA_HTTP_KEY',81 'IOTA_HTTP_CERT'82 ];83 const mqttVariables = [84 'IOTA_MQTT_PROTOCOL',85 'IOTA_MQTT_HOST',86 'IOTA_MQTT_PORT',87 'IOTA_MQTT_CA',88 'IOTA_MQTT_CERT',89 'IOTA_MQTT_KEY',90 'IOTA_MQTT_REJECT_UNAUTHORIZED',91 'IOTA_MQTT_USERNAME',92 'IOTA_MQTT_PASSWORD',93 'IOTA_MQTT_QOS',94 'IOTA_MQTT_RETAIN',95 'IOTA_MQTT_RETRIES',96 'IOTA_MQTT_RETRY_TIME',97 'IOTA_MQTT_KEEPALIVE',98 'IOTA_MQTT_AVOID_LEADING_SLASH',99 'IOTA_MQTT_CLEAN',100 'IOTA_MQTT_CLIENT_ID'101 ];102 const amqpVariables = [103 'IOTA_AMQP_HOST',104 'IOTA_AMQP_PORT',105 'IOTA_AMQP_USERNAME',106 'IOTA_AMQP_PASSWORD',107 'IOTA_AMQP_EXCHANGE',108 'IOTA_AMQP_QUEUE',109 'IOTA_AMQP_DURABLE',110 'IOTA_AMQP_RETRIES',111 'IOTA_AMQP_RETRY_TIME'112 ];113 const httpVariables = ['IOTA_HTTP_HOST', 'IOTA_HTTP_PORT', 'IOTA_HTTP_TIMEOUT', 'IOTA_HTTP_KEY', 'IOTA_HTTP_CERT'];114 const protectedVariables = [115 'IOTA_MQTT_KEY',116 'IOTA_MQTT_USERNAME',117 'IOTA_MQTT_PASSWORD',118 'IOTA_AMQP_USERNAME',119 'IOTA_AMQP_PASSWORD'120 ];121 // Substitute Docker Secret Variables where set.122 protectedVariables.forEach((key) => {123 iotAgentLib.configModule.getSecretData(key);124 });125 environmentVariables.forEach((key) => {126 let value = process.env[key];127 if (value) {128 if (key.endsWith('USERNAME') || key.endsWith('PASSWORD') || key.endsWith('KEY')) {129 value = '********';130 }131 logger.info('Setting %s to environment value: %s', key, value);132 }133 });134 if (process.env.IOTA_CONFIG_RETRIEVAL) {135 config.configRetrieval = process.env.IOTA_CONFIG_RETRIEVAL;136 }137 if (process.env.IOTA_DEFAULT_KEY) {138 config.defaultKey = process.env.IOTA_DEFAULT_KEY;139 }140 if (process.env.IOTA_DEFAULT_TRANSPORT) {141 config.defaultTransport = process.env.IOTA_DEFAULT_TRANSPORT;142 }143 if (anyIsSet(mqttVariables)) {144 config.mqtt = {};145 }146 if (process.env.IOTA_MQTT_PROTOCOL) {147 config.mqtt.protocol = process.env.IOTA_MQTT_PROTOCOL;148 }149 if (process.env.IOTA_MQTT_HOST) {150 config.mqtt.host = process.env.IOTA_MQTT_HOST;151 }152 if (process.env.IOTA_MQTT_PORT) {153 config.mqtt.port = process.env.IOTA_MQTT_PORT;154 }155 if (process.env.IOTA_MQTT_CA) {156 fileExists(process.env.IOTA_MQTT_CA);157 config.mqtt.ca = process.env.IOTA_MQTT_CA;158 }159 if (process.env.IOTA_MQTT_CERT) {160 fileExists(process.env.IOTA_MQTT_CERT);161 config.mqtt.cert = process.env.IOTA_MQTT_CERT;162 }163 if (process.env.IOTA_MQTT_KEY) {164 fileExists(process.env.IOTA_MQTT_KEY);165 config.mqtt.key = process.env.IOTA_MQTT_KEY;166 }167 // Since default is true, need to be able accept "false" as168 // a valid Environment variable169 if (process.env.IOTA_MQTT_REJECT_UNAUTHORIZED !== undefined) {170 config.mqtt.rejectUnauthorized = process.env.IOTA_MQTT_REJECT_UNAUTHORIZED.trim().toLowerCase() === 'true';171 }172 if (process.env.IOTA_MQTT_USERNAME) {173 config.mqtt.username = process.env.IOTA_MQTT_USERNAME;174 }175 if (process.env.IOTA_MQTT_PASSWORD) {176 config.mqtt.password = process.env.IOTA_MQTT_PASSWORD;177 }178 if (process.env.IOTA_MQTT_QOS) {179 config.mqtt.qos = process.env.IOTA_MQTT_QOS;180 }181 if (process.env.IOTA_MQTT_RETAIN) {182 config.mqtt.retain = process.env.IOTA_MQTT_RETAIN.trim().toLowerCase() === 'true';183 }184 if (process.env.IOTA_MQTT_RETRIES) {185 config.mqtt.retries = process.env.IOTA_MQTT_RETRIES;186 }187 if (process.env.IOTA_MQTT_RETRY_TIME) {188 config.mqtt.retryTime = process.env.IOTA_MQTT_RETRY_TIME;189 }190 if (process.env.IOTA_MQTT_KEEPALIVE) {191 config.mqtt.keepalive = process.env.IOTA_MQTT_KEEPALIVE;192 }193 if (process.env.IOTA_MQTT_AVOID_LEADING_SLASH) {194 config.mqtt.avoidLeadingSlashes = process.env.IOTA_MQTT_AVOID_LEADING_SLASH;195 }196 if (process.env.IOTA_MQTT_CLEAN) {197 config.mqtt.clean = process.env.IOTA_MQTT_CLEAN.trim().toLowerCase() === 'true';198 }199 if (process.env.IOTA_MQTT_CLIENT_ID) {200 config.mqtt.clientId = process.env.IOTA_MQTT_CLIENT_ID;201 }202 if (anyIsSet(amqpVariables)) {203 config.amqp = {};204 }205 if (process.env.IOTA_AMQP_HOST) {206 config.amqp.host = process.env.IOTA_AMQP_HOST;207 }208 if (process.env.IOTA_AMQP_PORT) {209 config.amqp.port = process.env.IOTA_AMQP_PORT;210 }211 if (process.env.IOTA_AMQP_USERNAME) {212 config.amqp.username = process.env.IOTA_AMQP_USERNAME;213 }214 if (process.env.IOTA_AMQP_PASSWORD) {215 config.amqp.password = process.env.IOTA_AMQP_PASSWORD;216 }217 if (process.env.IOTA_AMQP_EXCHANGE) {218 config.amqp.exchange = process.env.IOTA_AMQP_EXCHANGE;219 }220 if (process.env.IOTA_AMQP_QUEUE) {221 config.amqp.queue = process.env.IOTA_AMQP_QUEUE;222 }223 if (process.env.IOTA_AMQP_DURABLE) {224 config.amqp.options = {};225 config.amqp.options.durable = process.env.IOTA_AMQP_DURABLE.trim().toLowerCase() === 'true';226 }227 if (process.env.IOTA_AMQP_RETRIES) {228 config.amqp.retries = process.env.IOTA_AMQP_RETRIES;229 }230 if (process.env.IOTA_AMQP_RETRY_TIME) {231 config.amqp.retryTime = process.env.IOTA_AMQP_RETRY_TIME;232 }233 if (anyIsSet(httpVariables)) {234 config.http = {};235 }236 if (process.env.IOTA_HTTP_HOST) {237 config.http.host = process.env.IOTA_HTTP_HOST;238 }239 if (process.env.IOTA_HTTP_PORT) {240 config.http.port = process.env.IOTA_HTTP_PORT;241 }242 if (process.env.IOTA_HTTP_TIMEOUT) {243 config.http.timeout = process.env.IOTA_HTTP_TIMEOUT;244 }245 if (process.env.IOTA_HTTP_KEY) {246 fileExists(process.env.IOTA_HTTP_KEY);247 config.http.key = process.env.IOTA_HTTP_KEY;248 }249 if (process.env.IOTA_HTTP_CERT) {250 fileExists(process.env.IOTA_HTTP_CERT);251 config.http.cert = process.env.IOTA_HTTP_CERT;252 }253}254function setConfig(newConfig) {255 config = newConfig;256 processEnvironmentVariables();257}258function getConfig() {259 return config;260}261function setLogger(newLogger) {262 logger = newLogger;263}264function getLogger() {265 return logger;266}267exports.setConfig = setConfig;268exports.getConfig = getConfig;269exports.setLogger = setLogger;...
iotauth-spec.ts
Source:iotauth-spec.ts
1import { IotAuth } from '../src/index';2beforeAll(() => {3 jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;4});5afterEach(() => {6 jest.resetModules();7});8test('Should create an Iota Client with sanbox node by default', () => {9 const iotaAuth = new IotAuth();10 expect(iotaAuth.iotaClient).toBeDefined();11});12// test('Should generate a new seed if one is not provided', async () => {13// const iotaAuth = new IotAuth();14// let seed = await iotaAuth.getSeed();15// expect(iotaAuth.iotaClient.valid.isTrytes(seed, 81)).toBe(true);16// });17// test('Should generate a verification code', async () => {18// const iotaAuth = new IotAuth();19// let code = await iotaAuth.generateValidationCode();20// expect(iotaAuth.iotaClient.valid.isTrytes(code, 6)).toBe(true);21// });22test('Should set the seed if provided', async () => {23 const seed =24 'PBGRWJXOALEOBXNUPCFUNWXSEXMYC9BVLLK9HMUDXNOETYJHSKBHDR9SWAWJIKVPFSBWNCNSQQJUFUPJM';25 const iotaAuth = new IotAuth(seed);26 let mySeed = await iotaAuth.getSeed();27 expect(mySeed).toEqual(seed);28});29test('isTransactionValid should return true for valid authentication if the transaction code is sent from the expected address', async () => {30 const seed =31 'PBGRWJXOALEOBXNUPCFUNWXSEXMYC9BVLLK9HMUDXNOETYJHSKBHDR9SWAWJIKVPFSBWNCNSQQJUFUPJM';32 const getAccountData = jest.fn().mockImplementation(function(seed, callback) {33 callback(null, require('./accountdata.json'));34 });35 const getNewAddress = jest36 .fn()37 .mockImplementation(function(seed, options, callback) {38 callback(39 null,40 [41 'QEL99XNPRACLRNEHKQXKNJXPKCPYNUYQIVNELMVFUQPQMVLIJTUGJL9XPDNKJFANOAJB9FCKKAMFEERSW',42 'YWNET9JHIIGBECEMCRULUOEYLDIRRPKRNJNUNXBBBWJWITEAYMSRGAPDGBLNUCYRLWPHTEKPSRZICEVYB',43 ],44 []45 );46 });47 const iotaAuth = new IotAuth(seed);48 iotaAuth.iotaClient.api.getAccountData = getAccountData.bind(49 iotaAuth.iotaClient.api50 );51 iotaAuth.iotaClient.api.getNewAddress = getNewAddress.bind(52 iotaAuth.iotaClient.api53 );54 let code = 'LMNOPQ';55 let isValid = await iotaAuth.isTransactionValid(code);56 expect(isValid).toBe(true);57});58test('isTransactionValid should return false for valid authentication if the transaction code is sent from the expected address but has expired based on duration', async () => {59 const seed =60 'PBGRWJXOALEOBXNUPCFUNWXSEXMYC9BVLLK9HMUDXNOETYJHSKBHDR9SWAWJIKVPFSBWNCNSQQJUFUPJM';61 const getAccountData = jest.fn().mockImplementation(function(seed, callback) {62 callback(null, require('./accountdata.json'));63 });64 const getNewAddress = jest65 .fn()66 .mockImplementation(function(seed, options, callback) {67 callback(68 null,69 [70 'QEL99XNPRACLRNEHKQXKNJXPKCPYNUYQIVNELMVFUQPQMVLIJTUGJL9XPDNKJFANOAJB9FCKKAMFEERSW',71 'YWNET9JHIIGBECEMCRULUOEYLDIRRPKRNJNUNXBBBWJWITEAYMSRGAPDGBLNUCYRLWPHTEKPSRZICEVYB',72 ],73 []74 );75 });76 const iotaAuth = new IotAuth(seed, 6);77 iotaAuth.iotaClient.api.getAccountData = getAccountData.bind(78 iotaAuth.iotaClient.api79 );80 iotaAuth.iotaClient.api.getNewAddress = getNewAddress.bind(81 iotaAuth.iotaClient.api82 );83 let code = 'LMNOPQ';84 let isValid = await iotaAuth.isTransactionValid(code);85 expect(isValid).toBe(false);86});87test('isTransactionValid should return false for valid authentication if the transaction code is incorrect', async () => {88 const seed =89 'PBGRWJXOALEOBXNUPCFUNWXSEXMYC9BVLLK9HMUDXNOETYJHSKBHDR9SWAWJIKVPFSBWNCNSQQJUFUPJM';90 const getAccountData = jest.fn().mockImplementation(function(seed, callback) {91 callback(null, require('./accountdata.json'));92 });93 const getNewAddress = jest94 .fn()95 .mockImplementation(function(seed, options, callback) {96 callback(97 null,98 [99 'QEL99XNPRACLRNEHKQXKNJXPKCPYNUYQIVNELMVFUQPQMVLIJTUGJL9XPDNKJFANOAJB9FCKKAMFEERSW',100 'YWNET9JHIIGBECEMCRULUOEYLDIRRPKRNJNUNXBBBWJWITEAYMSRGAPDGBLNUCYRLWPHTEKPSRZICEVYB',101 ],102 []103 );104 });105 const iotaAuth = new IotAuth(seed);106 iotaAuth.iotaClient.api.getAccountData = getAccountData.bind(107 iotaAuth.iotaClient.api108 );109 iotaAuth.iotaClient.api.getNewAddress = getNewAddress.bind(110 iotaAuth.iotaClient.api111 );112 let code = 'ABCDEF';113 let isValid = await iotaAuth.isTransactionValid(code);114 expect(isValid).toBe(false);115});116test('isTransactionValid should return false when an error is thrown', async () => {117 const seed =118 'PBGRWJXOALEOBXNUPCFUNWXSEXMYC9BVLLK9HMUDXNOETYJHSKBHDR9SWAWJIKVPFSBWNCNSQQJUFUPJM';119 const getAccountData = jest.fn().mockImplementation(function(seed, callback) {120 callback(null, null);121 });122 const getNewAddress = jest123 .fn()124 .mockImplementation(function(seed, options, callback) {125 callback(126 null,127 [128 'QEL99XNPRACLRNEHKQXKNJXPKCPYNUYQIVNELMVFUQPQMVLIJTUGJL9XPDNKJFANOAJB9FCKKAMFEERSW',129 'YWNET9JHIIGBECEMCRULUOEYLDIRRPKRNJNUNXBBBWJWITEAYMSRGAPDGBLNUCYRLWPHTEKPSRZICEVYB',130 ],131 []132 );133 });134 const iotaAuth = new IotAuth(seed);135 iotaAuth.iotaClient.api.getAccountData = getAccountData.bind(136 iotaAuth.iotaClient.api137 );138 iotaAuth.iotaClient.api.getNewAddress = getNewAddress.bind(139 iotaAuth.iotaClient.api140 );141 let code = 'ABCDEF';142 let isValid = await iotaAuth.isTransactionValid(code);143 expect(isValid).toBe(false);144});145test('isTransactionValid should return false for valid authentication if the address is reused', async () => {146 const seed =147 'PBGRWJXOALEOBXNUPCFUNWXSEXMYC9BVLLK9HMUDXNOETYJHSKBHDR9SWAWJIKVPFSBWNCNSQQJUFUPJM';148 const getAccountData = jest.fn().mockImplementation(function(seed, callback) {149 callback(null, require('./accountdata.addressreuse.json'));150 });151 const getNewAddress = jest152 .fn()153 .mockImplementation(function(seed, options, callback) {154 callback(155 null,156 [157 'QEL99XNPRACLRNEHKQXKNJXPKCPYNUYQIVNELMVFUQPQMVLIJTUGJL9XPDNKJFANOAJB9FCKKAMFEERSW',158 'YWNET9JHIIGBECEMCRULUOEYLDIRRPKRNJNUNXBBBWJWITEAYMSRGAPDGBLNUCYRLWPHTEKPSRZICEVYB',159 ],160 []161 );162 });163 const iotaAuth = new IotAuth(seed);164 iotaAuth.iotaClient.api.getAccountData = getAccountData.bind(165 iotaAuth.iotaClient.api166 );167 iotaAuth.iotaClient.api.getNewAddress = getNewAddress.bind(168 iotaAuth.iotaClient.api169 );170 let code = 'LMNOPQ';171 let isValid = await iotaAuth.isTransactionValid(code);172 expect(isValid).toBe(false);173});174test('isTransactionValid should return true for valid authentication if the address is reused but then corrected', async () => {175 const seed =176 'PBGRWJXOALEOBXNUPCFUNWXSEXMYC9BVLLK9HMUDXNOETYJHSKBHDR9SWAWJIKVPFSBWNCNSQQJUFUPJM';177 const getAccountData = jest.fn().mockImplementation(function(seed, callback) {178 callback(null, require('./accountdata.addressreuse.corrected.json'));179 });180 const getNewAddress = jest181 .fn()182 .mockImplementation(function(seed, options, callback) {183 callback(184 null,185 [186 'QEL99XNPRACLRNEHKQXKNJXPKCPYNUYQIVNELMVFUQPQMVLIJTUGJL9XPDNKJFANOAJB9FCKKAMFEERSW',187 'YWNET9JHIIGBECEMCRULUOEYLDIRRPKRNJNUNXBBBWJWITEAYMSRGAPDGBLNUCYRLWPHTEKPSRZICEVYB',188 'QYCMFMSLBK9SHOJLDFZMKGXNEGZOUWJJAMVDSMQEDQHKEAVXBHLKTKEB9ZWCNENHYTOASADLTVJVAETUW',189 ],190 []191 );192 });193 const iotaAuth = new IotAuth(seed);194 iotaAuth.iotaClient.api.getAccountData = getAccountData.bind(195 iotaAuth.iotaClient.api196 );197 iotaAuth.iotaClient.api.getNewAddress = getNewAddress.bind(198 iotaAuth.iotaClient.api199 );200 let code = 'LMNOPQ';201 let isValid = await iotaAuth.isTransactionValid(code);202 expect(isValid).toBe(true);203});204test('isTransactionValid should return true for valid authentication if no code is specified', async () => {205 const seed =206 'PBGRWJXOALEOBXNUPCFUNWXSEXMYC9BVLLK9HMUDXNOETYJHSKBHDR9SWAWJIKVPFSBWNCNSQQJUFUPJM';207 const getAccountData = jest.fn().mockImplementation(function(seed, callback) {208 callback(null, require('./accountdata.addressreuse.corrected.json'));209 });210 const getNewAddress = jest211 .fn()212 .mockImplementation(function(seed, options, callback) {213 callback(214 null,215 [216 'QEL99XNPRACLRNEHKQXKNJXPKCPYNUYQIVNELMVFUQPQMVLIJTUGJL9XPDNKJFANOAJB9FCKKAMFEERSW',217 'YWNET9JHIIGBECEMCRULUOEYLDIRRPKRNJNUNXBBBWJWITEAYMSRGAPDGBLNUCYRLWPHTEKPSRZICEVYB',218 'QYCMFMSLBK9SHOJLDFZMKGXNEGZOUWJJAMVDSMQEDQHKEAVXBHLKTKEB9ZWCNENHYTOASADLTVJVAETUW',219 ],220 []221 );222 });223 const iotaAuth = new IotAuth(seed);224 iotaAuth.iotaClient.api.getAccountData = getAccountData.bind(225 iotaAuth.iotaClient.api226 );227 iotaAuth.iotaClient.api.getNewAddress = getNewAddress.bind(228 iotaAuth.iotaClient.api229 );230 let code = 'LMNOPQ';231 let isValid = await iotaAuth.isTransactionValid();232 expect(isValid).toBe(true);...
startup-test.js
Source:startup-test.js
1/*2 * Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U3 *4 * This file is part of iotagent-ul5 *6 * fiware-iotagent-lib is free software: you can redistribute it and/or7 * modify it under the terms of the GNU Affero General Public License as8 * published by the Free Software Foundation, either version 3 of the License,9 * or (at your option) any later version.10 *11 * fiware-iotagent-lib is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.14 * See the GNU Affero General Public License for more details.15 *16 * You should have received a copy of the GNU Affero General Public17 * License along with fiware-iotagent-lib.18 * If not, seehttp://www.gnu.org/licenses/.19 *20 * For those usages not covered by the GNU Affero General Public License21 * please contact with::[contacto@tid.es]22 */23const config = require('../../lib/configService');24const iotAgentConfig = require('../config-test.js');25const fs = require('fs');26const sinon = require('sinon');27describe('Startup tests', function () {28 describe('When the MQTT transport is started with environment variables', function () {29 beforeEach(function () {30 sinon.stub(fs, 'statSync');31 process.env.IOTA_MQTT_HOST = '127.0.0.1';32 process.env.IOTA_MQTT_PORT = '1883';33 process.env.IOTA_MQTT_USERNAME = 'usermqtt';34 process.env.IOTA_MQTT_PASSWORD = 'passmqtt';35 process.env.IOTA_MQTT_PROTOCOL = 'xxx';36 process.env.IOTA_MQTT_CA = '/mqtt/xxx/ca';37 process.env.IOTA_MQTT_CERT = '/mqtt/xxx/cert.pem';38 process.env.IOTA_MQTT_KEY = '/mqtt/xxx/key.pem';39 process.env.IOTA_MQTT_REJECT_UNAUTHORIZED = 'true';40 process.env.IOTA_MQTT_QOS = '0';41 process.env.IOTA_MQTT_RETAIN = 'false';42 process.env.IOTA_MQTT_RETRIES = '2';43 process.env.IOTA_MQTT_RETRY_TIME = '5';44 process.env.IOTA_MQTT_KEEPALIVE = '0';45 });46 afterEach(function () {47 fs.statSync.restore();48 delete process.env.IOTA_MQTT_PROTOCOL;49 delete process.env.IOTA_MQTT_HOST;50 delete process.env.IOTA_MQTT_PORT;51 delete process.env.IOTA_MQTT_CA;52 delete process.env.IOTA_MQTT_CERT;53 delete process.env.IOTA_MQTT_KEY;54 delete process.env.IOTA_MQTT_REJECT_UNAUTHORIZED;55 delete process.env.IOTA_MQTT_USERNAME;56 delete process.env.IOTA_MQTT_PASSWORD;57 delete process.env.IOTA_MQTT_QOS;58 delete process.env.IOTA_MQTT_RETAIN;59 delete process.env.IOTA_MQTT_RETRIES;60 delete process.env.IOTA_MQTT_RETRY_TIME;61 delete process.env.IOTA_MQTT_KEEPALIVE;62 });63 it('should load the MQTT environment variables in the internal configuration', function (done) {64 config.setConfig(iotAgentConfig);65 config.getConfig().mqtt.host.should.equal('127.0.0.1');66 config.getConfig().mqtt.port.should.equal('1883');67 config.getConfig().mqtt.username.should.equal('usermqtt');68 config.getConfig().mqtt.password.should.equal('passmqtt');69 config.getConfig().mqtt.ca.should.equal('/mqtt/xxx/ca');70 config.getConfig().mqtt.cert.should.equal('/mqtt/xxx/cert.pem');71 config.getConfig().mqtt.key.should.equal('/mqtt/xxx/key.pem');72 config.getConfig().mqtt.rejectUnauthorized.should.equal(true);73 config.getConfig().mqtt.qos.should.equal('0');74 config.getConfig().mqtt.retain.should.equal(false);75 config.getConfig().mqtt.retries.should.equal('2');76 config.getConfig().mqtt.retryTime.should.equal('5');77 config.getConfig().mqtt.keepalive.should.equal('0');78 done();79 });80 });81 describe('When the AMQP transport is started with environment variables', function () {82 beforeEach(function () {83 process.env.IOTA_AMQP_HOST = 'localhost';84 process.env.IOTA_AMQP_PORT = '9090';85 process.env.IOTA_AMQP_USERNAME = 'useramqp';86 process.env.IOTA_AMQP_PASSWORD = 'passamqp';87 process.env.IOTA_AMQP_EXCHANGE = 'xxx';88 process.env.IOTA_AMQP_QUEUE = '0';89 process.env.IOTA_AMQP_DURABLE = 'true';90 process.env.IOTA_AMQP_RETRIES = '0';91 process.env.IOTA_AMQP_RETRY_TIME = '5';92 });93 afterEach(function () {94 delete process.env.IOTA_AMQP_HOST;95 delete process.env.IOTA_AMQP_PORT;96 delete process.env.IOTA_AMQP_USERNAME;97 delete process.env.IOTA_AMQP_PASSWORD;98 delete process.env.IOTA_AMQP_EXCHANGE;99 delete process.env.IOTA_AMQP_QUEUE;100 delete process.env.IOTA_AMQP_DURABLE;101 delete process.env.IOTA_AMQP_RETRIES;102 delete process.env.IOTA_AMQP_RETRY_TIME;103 });104 it('should load the AMQP environment variables in the internal configuration', function (done) {105 config.setConfig(iotAgentConfig);106 config.getConfig().amqp.host.should.equal('localhost');107 config.getConfig().amqp.port.should.equal('9090');108 config.getConfig().amqp.username.should.equal('useramqp');109 config.getConfig().amqp.password.should.equal('passamqp');110 config.getConfig().amqp.exchange.should.equal('xxx');111 config.getConfig().amqp.queue.should.equal('0');112 config.getConfig().amqp.options.durable.should.equal(true);113 config.getConfig().amqp.retries.should.equal('0');114 config.getConfig().amqp.retryTime.should.equal('5');115 done();116 });117 });118 describe('When the HTTP transport is started with environment variables', function () {119 beforeEach(function () {120 sinon.stub(fs, 'statSync');121 process.env.IOTA_HTTP_HOST = 'localhost';122 process.env.IOTA_HTTP_PORT = '2222';123 process.env.IOTA_HTTP_TIMEOUT = '5';124 process.env.IOTA_HTTP_KEY = '/http/bbb/key.pem';125 process.env.IOTA_HTTP_CERT = '/http/bbb/cert.pem';126 });127 afterEach(function () {128 fs.statSync.restore();129 delete process.env.IOTA_HTTP_HOST;130 delete process.env.IOTA_HTTP_PORT;131 delete process.env.IOTA_HTTP_TIMEOUT;132 delete process.env.IOTA_HTTP_KEY;133 delete process.env.IOTA_HTTP_CERT;134 });135 it('should load the HTTP environment variables in the internal configuration', function (done) {136 config.setConfig(iotAgentConfig);137 config.getConfig().http.host.should.equal('localhost');138 config.getConfig().http.port.should.equal('2222');139 config.getConfig().http.timeout.should.equal('5');140 config.getConfig().http.key.should.equal('/http/bbb/key.pem');141 config.getConfig().http.cert.should.equal('/http/bbb/cert.pem');142 done();143 });144 });...
Using AI Code Generation
1const fc = require("fast-check");2const { iota } = require("fast-check");3fc.assert(4 fc.property(iota(), (i) => {5 return i >= 0;6 })7);8{9 "dependencies": {10 }11}
Using AI Code Generation
1const fc = require('fast-check');2const { iota } = require('fast-check-monorepo');3fc.assert(4 fc.property(5 iota(0, 10),6 (i) => {7 return i >= 0 && i < 10;8 }9 { verbose: true }10);11{12 "scripts": {13 },14 "dependencies": {15 }16}
Using AI Code Generation
1const fc = require('fast-check');2const { iota } = require('fast-check');3fc.assert(4 fc.property(iota(), n => n >= 0)5);6const fc = require('fast-check');7const { iota } = require('fast-check/lib/arbitrary/IotaArbitrary.js');8fc.assert(9 fc.property(iota(), n => n >= 0)10);11import * as fc from 'fast-check';12describe('some test', () => {13 it('should pass', () => {14 fc.assert(15 fc.property(16 fc.string(),17 (s: string) => {18 expect(s).toBeDefined();19 },20 );21 });22});23import * as fc from 'fast-check';24describe('some test', () => {25 it('should pass', () => {26 fc.assert(27 fc.property(28 fc.string(),29 (s: string) => {30 expect(s).toBeDefined();31 },32 );33 });34});35import * as fc
Using AI Code Generation
1const { iota } = require('fast-check');2const { array } = require('fast-check');3const { map } = require('fast-check');4const { property } = require('fast-check');5const { tuple } = require('fast-check');6const { string } = require('fast-check');7const { option } = require('fast-check');8const { record } = require('fast-check');9const { constantFrom } = require('fast-check');10const { frequency } = require('fast-check');11const { oneof } = require('fast-check');12const { set } = require('fast-check');13const { object } = require('fast-check');14const { dictionary } = require('fast-check');15const { bigUintN } = require('fast-check');16const { bigIntN } = require('fast-check');17const { bigUint } = require('fast-check');18const { bigInt } = require('fast-check');19const { double } = require('fast-check');20const { float } = require('fast-check');21const { date } = require('fast-check');22const { maxSafeInteger } = require('fast-check');23const { minSafeInteger } = require('fast-check');24const { integer } = require('fast-check');25const { char } = require('fast-check');26const { unicode } = require('fast-check');27const { ascii } = require('fast-check');28const { fullUnicode } = require('fast-check');29const { fullAscii } = require('fast-check');30const { hexa } = require('fast-check');31const { base64 } = require('fast-check');32const { base32 } = require('fast-check');33const { base16 } = require('fast-check');34const { base10 } = require('fast-check');35const { byte } = require('fast-check');36const { boolean } = require('fast-check');37const { constant } = require('fast-check');38const { memo } = require('fast-check');39const { cloneMethod } = require('fast-check');40const { cloneFunction } = require('fast-check');41const { clone } = require('fast-check');42const { cloneMethodWithShrink } = require('fast-check');43const { cloneFunctionWithShrink } = require('fast-check');44const { cloneWithShrink } = require('fast-check');45const { cloneMethodWithShrinkOnPath } = require('fast-check');46const { cloneFunctionWithShrinkOnPath }
Using AI Code Generation
1import { check, property } from 'fast-check';2import { iota } from 'fast-check-monorepo';3check(property(iota(), (i) => i === 1));4{5 "compilerOptions": {6 "paths": {7 }8 }9}10{11 "devDependencies": {12 }13}14{15 "dependencies": {16 "fast-check": {17 "requires": {18 }19 },20 "fast-check-monorepo": {21 }22 }23}
Using AI Code Generation
1const fc = require('fast-check');2const { iota } = require('fast-check');3const myGenerator = iota(1, 100);4fc.assert(5 fc.property(6 (x) => x >= 1 && x <= 1007);8I have also tried to use the following code to import the iota method of fast-check-monorepo:9const fc = require('fast-check');10const { iota } = require('fast-check-monorepo');11const myGenerator = iota(1, 100);12fc.assert(13 fc.property(14 (x) => x >= 1 && x <= 10015);16I have also tried to use the following code to import the iota method of fast-check-monorepo:17const fc = require('fast-check');18const { iota } = require('fast-check-monorepo');19const myGenerator = iota(1, 100);20fc.assert(21 fc.property(22 (x) => x >= 1 && x <= 10023);24I have also tried to use the following code to import the iota method of fast-check-monorepo:25const fc = require('fast-check');26const { iota } = require('fast-check-monorepo');27const myGenerator = iota(1, 100);28fc.assert(29 fc.property(30 (x) => x >= 1 && x <= 10031);32I have also tried to use the following code to import the iota method of fast-check-monorepo:33const fc = require('fast-check');34const { iota } = require('fast-check-monorepo');35const myGenerator = iota(1, 100);36fc.assert(37 fc.property(38 (x) => x >= 1 && x <= 10039);40I have also tried to use the following code to import the iota method of fast-check-monorepo:
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!!