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