forked from extern/bruno
add ability to turn certificate validation off
This commit is contained in:
parent
b25d896dd6
commit
87119cee2e
@ -5,7 +5,7 @@ const { exists, isFile, isDirectory, getSubDirectories } = require('../utils/fil
|
||||
const { runSingleRequest } = require('../runner/run-single-request');
|
||||
const { bruToEnvJson, getEnvVars } = require('../utils/bru');
|
||||
const { rpad } = require('../utils/common');
|
||||
const { bruToJson } = require('../utils/bru');
|
||||
const { bruToJson, getOptions } = require('../utils/bru');
|
||||
|
||||
const command = 'run [filename]';
|
||||
const desc = 'Run a request';
|
||||
@ -117,6 +117,10 @@ const builder = async (yargs) => {
|
||||
describe: 'Environment variables',
|
||||
type: 'string',
|
||||
})
|
||||
.option('insecure', {
|
||||
type: 'boolean',
|
||||
description: 'Allow insecure server connections'
|
||||
})
|
||||
.example('$0 run request.bru', 'Run a request')
|
||||
.example('$0 run request.bru --env local', 'Run a request with the environment set to local')
|
||||
.example('$0 run folder', 'Run all requests in a folder')
|
||||
@ -128,6 +132,7 @@ const handler = async function (argv) {
|
||||
let {
|
||||
filename,
|
||||
env,
|
||||
insecure,
|
||||
r: recursive
|
||||
} = argv;
|
||||
const collectionPath = process.cwd();
|
||||
@ -170,6 +175,11 @@ const handler = async function (argv) {
|
||||
envVars = getEnvVars(envJson);
|
||||
}
|
||||
|
||||
const options = getOptions();
|
||||
if(insecure) {
|
||||
options['insecure'] = true
|
||||
}
|
||||
|
||||
const _isFile = await isFile(filename);
|
||||
if(_isFile) {
|
||||
console.log(chalk.yellow('Running Request \n'));
|
||||
|
@ -3,10 +3,12 @@ const chalk = require('chalk');
|
||||
const { forOwn, each, extend, get } = require('lodash');
|
||||
const FormData = require('form-data');
|
||||
const axios = require('axios');
|
||||
const https = require('https');
|
||||
const prepareRequest = require('./prepare-request');
|
||||
const interpolateVars = require('./interpolate-vars');
|
||||
const { ScriptRuntime, TestRuntime, VarsRuntime, AssertRuntime } = require('@usebruno/js');
|
||||
const { stripExtension } = require('../utils/filesystem');
|
||||
const { getOptions } = require('../utils/bru');
|
||||
|
||||
const runSingleRequest = async function (filename, bruJson, collectionPath, collectionVariables, envVariables) {
|
||||
let request;
|
||||
@ -42,6 +44,14 @@ const runSingleRequest = async function (filename, bruJson, collectionPath, coll
|
||||
// interpolate variables inside request
|
||||
interpolateVars(request, envVariables, collectionVariables);
|
||||
|
||||
const insecure = get(getOptions(), 'insecure', false);
|
||||
if(insecure) {
|
||||
console.log("Certificate validation has been disabled.");
|
||||
request.httpsAgent = new https.Agent({
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
}
|
||||
|
||||
// stringify the request url encoded params
|
||||
if(request.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
||||
request.data = qs.stringify(request.data);
|
||||
|
@ -80,8 +80,14 @@ const getEnvVars = (environment = {}) => {
|
||||
return envVars;
|
||||
};
|
||||
|
||||
const options = {};
|
||||
const getOptions = () => {
|
||||
return options;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
bruToJson,
|
||||
bruToEnvJson,
|
||||
getEnvVars
|
||||
getEnvVars,
|
||||
getOptions
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user