diff --git a/packages/bruno-cli/changelog.md b/packages/bruno-cli/changelog.md index 5ba0d6fc3..8a6c3ae1b 100644 --- a/packages/bruno-cli/changelog.md +++ b/packages/bruno-cli/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 0.10.0 + +- Support for proxying requests through a proxy server + ## 0.9.0 - `--output` flag to collect the results of your API tests diff --git a/packages/bruno-cli/package.json b/packages/bruno-cli/package.json index 38232046a..236c3d1cb 100644 --- a/packages/bruno-cli/package.json +++ b/packages/bruno-cli/package.json @@ -1,6 +1,6 @@ { "name": "@usebruno/cli", - "version": "0.9.0", + "version": "0.10.0", "license": "MIT", "main": "src/index.js", "bin": { diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index 845fbc033..087b85d48 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -165,6 +165,9 @@ const handler = async function (argv) { return; } + const brunoConfigFile = fs.readFileSync(brunoJsonPath, 'utf8'); + const brunoConfig = JSON.parse(brunoConfigFile); + if (filename && filename.length) { const pathExists = await exists(filename); if (!pathExists) { @@ -304,7 +307,8 @@ const handler = async function (argv) { collectionPath, collectionVariables, envVars, - processEnvVars + processEnvVars, + brunoConfig ); if (result) { diff --git a/packages/bruno-cli/src/runner/interpolate-vars.js b/packages/bruno-cli/src/runner/interpolate-vars.js index ae30a7b29..fb0221505 100644 --- a/packages/bruno-cli/src/runner/interpolate-vars.js +++ b/packages/bruno-cli/src/runner/interpolate-vars.js @@ -85,6 +85,17 @@ const interpolateVars = (request, envVars = {}, collectionVariables = {}, proces param.value = interpolate(param.value); }); + if (request.proxy) { + request.proxy.protocol = interpolate(request.proxy.protocol); + request.proxy.hostname = interpolate(request.proxy.hostname); + request.proxy.port = interpolate(request.proxy.port); + + if (request.proxy.auth) { + request.proxy.auth.username = interpolate(request.proxy.auth.username); + request.proxy.auth.password = interpolate(request.proxy.auth.password); + } + } + return request; }; diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index e8f1e6bfe..e8da96cf1 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -17,7 +17,8 @@ const runSingleRequest = async function ( collectionPath, collectionVariables, envVariables, - processEnvVars + processEnvVars, + brunoConfig ) { let request; @@ -39,7 +40,14 @@ const runSingleRequest = async function ( const preRequestVars = get(bruJson, 'request.vars.req'); if (preRequestVars && preRequestVars.length) { const varsRuntime = new VarsRuntime(); - varsRuntime.runPreRequestVars(preRequestVars, request, envVariables, collectionVariables, collectionPath); + varsRuntime.runPreRequestVars( + preRequestVars, + request, + envVariables, + collectionVariables, + collectionPath, + processEnvVars + ); } // run pre request script @@ -51,10 +59,37 @@ const runSingleRequest = async function ( request, envVariables, collectionVariables, - collectionPath + collectionPath, + null, + processEnvVars ); } + // set proxy if enabled + const proxyEnabled = get(brunoConfig, 'proxy.enabled', false); + if (proxyEnabled) { + const proxyProtocol = get(brunoConfig, 'proxy.protocol'); + const proxyHostname = get(brunoConfig, 'proxy.hostname'); + const proxyPort = get(brunoConfig, 'proxy.port'); + const proxyAuthEnabled = get(brunoConfig, 'proxy.auth.enabled', false); + + const proxyConfig = { + protocol: proxyProtocol, + hostname: proxyHostname, + port: proxyPort + }; + if (proxyAuthEnabled) { + const proxyAuthUsername = get(brunoConfig, 'proxy.auth.username'); + const proxyAuthPassword = get(brunoConfig, 'proxy.auth.password'); + proxyConfig.auth = { + username: proxyAuthUsername, + password: proxyAuthPassword + }; + } + + request.proxy = proxyConfig; + } + // interpolate variables inside request interpolateVars(request, envVariables, collectionVariables, processEnvVars); @@ -102,7 +137,8 @@ const runSingleRequest = async function ( response, envVariables, collectionVariables, - collectionPath + collectionPath, + processEnvVars ); } @@ -116,7 +152,9 @@ const runSingleRequest = async function ( response, envVariables, collectionVariables, - collectionPath + collectionPath, + null, + processEnvVars ); } @@ -155,7 +193,9 @@ const runSingleRequest = async function ( response, envVariables, collectionVariables, - collectionPath + collectionPath, + null, + processEnvVars ); testResults = get(result, 'results', []); } @@ -202,7 +242,8 @@ const runSingleRequest = async function ( err.response, envVariables, collectionVariables, - collectionPath + collectionPath, + processEnvVars ); } @@ -216,7 +257,9 @@ const runSingleRequest = async function ( err.response, envVariables, collectionVariables, - collectionPath + collectionPath, + null, + processEnvVars ); } @@ -255,7 +298,9 @@ const runSingleRequest = async function ( err.response, envVariables, collectionVariables, - collectionPath + collectionPath, + null, + processEnvVars ); testResults = get(result, 'results', []); }