feat: add ssl-cert-list option for secure connections in CLI run command

This commit is contained in:
Pragadesh-45 2024-11-19 10:22:55 +05:30
parent 40001949b8
commit 9a325caeee

View File

@ -259,6 +259,11 @@ const builder = async (yargs) => {
type: 'boolean', type: 'boolean',
description: 'Stop execution after a failure of a request, test, or assertion' description: 'Stop execution after a failure of a request, test, or assertion'
}) })
.option('ssl-cert-list', {
type: 'string',
description: 'Path to the SSL client certificate list file used for securing the connection in the request'
})
.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')
@ -292,7 +297,8 @@ const builder = async (yargs) => {
.example( .example(
'$0 run folder --cacert myCustomCA.pem --ignore-truststore', '$0 run folder --cacert myCustomCA.pem --ignore-truststore',
'Use a custom CA certificate exclusively when validating the peers of the requests in the specified folder.' 'Use a custom CA certificate exclusively when validating the peers of the requests in the specified folder.'
); )
.example('$0 run --ssl-cert-list ssl-cert-list.json', 'Run a request with SSL client certificate list');
}; };
const handler = async function (argv) { const handler = async function (argv) {
@ -312,7 +318,8 @@ const handler = async function (argv) {
reporterHtml, reporterHtml,
sandbox, sandbox,
testsOnly, testsOnly,
bail bail,
sslCertList
} = argv; } = argv;
const collectionPath = process.cwd(); const collectionPath = process.cwd();
@ -330,6 +337,38 @@ const handler = async function (argv) {
const brunoConfig = JSON.parse(brunoConfigFile); const brunoConfig = JSON.parse(brunoConfigFile);
const collectionRoot = getCollectionRoot(collectionPath); const collectionRoot = getCollectionRoot(collectionPath);
if (sslCertList) {
try {
const sslCertListPathExists = await exists(sslCertList);
if (!sslCertListPathExists) {
console.error(chalk.red(`SSL Certificate List file "${sslCertList}" does not exist.`));
process.exit(constants.EXIT_STATUS.ERROR_FILE_NOT_FOUND);
}
const sslCertListFile = fs.readFileSync(sslCertList, 'utf8');
let sslCertListJson;
try {
sslCertListJson = JSON.parse(sslCertListFile);
} catch (err) {
console.error(chalk.red(`Failed to parse SSL Certificate List JSON: ${err.message}`));
process.exit(constants.EXIT_STATUS.ERROR_INVALID_JSON);
}
if (brunoConfig.clientCertificates) {
brunoConfig.clientCertificates = {
...brunoConfig.clientCertificates,
certs: [...brunoConfig.clientCertificates.certs, ...sslCertListJson]
};
} else {
brunoConfig.clientCertificates = { certs: sslCertListJson };
}
} catch (err) {
console.error(chalk.red(`Unexpected error: ${err.message}`));
process.exit(constants.EXIT_STATUS.ERROR_UNKNOWN);
}
}
if (filename && filename.length) { if (filename && filename.length) {
const pathExists = await exists(filename); const pathExists = await exists(filename);
if (!pathExists) { if (!pathExists) {