forked from extern/bruno
Merge pull request #774 from jwetzell/main
fix cert/key loading in electron for relative path
This commit is contained in:
commit
c5a47ba7ec
@ -3,6 +3,7 @@ const fs = require('fs');
|
|||||||
const qs = require('qs');
|
const qs = require('qs');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const path = require('path');
|
||||||
const decomment = require('decomment');
|
const decomment = require('decomment');
|
||||||
const Mustache = require('mustache');
|
const Mustache = require('mustache');
|
||||||
const FormData = require('form-data');
|
const FormData = require('form-data');
|
||||||
@ -83,7 +84,14 @@ const getSize = (data) => {
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
const configureRequest = async (collectionUid, request, envVars, collectionVariables, processEnvVars) => {
|
const configureRequest = async (
|
||||||
|
collectionUid,
|
||||||
|
request,
|
||||||
|
envVars,
|
||||||
|
collectionVariables,
|
||||||
|
processEnvVars,
|
||||||
|
collectionPath
|
||||||
|
) => {
|
||||||
const httpsAgentRequestFields = {};
|
const httpsAgentRequestFields = {};
|
||||||
if (!preferencesUtil.shouldVerifyTls()) {
|
if (!preferencesUtil.shouldVerifyTls()) {
|
||||||
httpsAgentRequestFields['rejectUnauthorized'] = false;
|
httpsAgentRequestFields['rejectUnauthorized'] = false;
|
||||||
@ -100,18 +108,29 @@ const configureRequest = async (collectionUid, request, envVars, collectionVaria
|
|||||||
const clientCertConfig = get(brunoConfig, 'clientCertificates.certs', []);
|
const clientCertConfig = get(brunoConfig, 'clientCertificates.certs', []);
|
||||||
for (let clientCert of clientCertConfig) {
|
for (let clientCert of clientCertConfig) {
|
||||||
const domain = interpolateString(clientCert.domain, interpolationOptions);
|
const domain = interpolateString(clientCert.domain, interpolationOptions);
|
||||||
const certFilePath = interpolateString(clientCert.certFilePath, interpolationOptions);
|
|
||||||
const keyFilePath = interpolateString(clientCert.keyFilePath, interpolationOptions);
|
let certFilePath = interpolateString(clientCert.certFilePath, interpolationOptions);
|
||||||
|
certFilePath = path.isAbsolute(certFilePath) ? certFilePath : path.join(collectionPath, certFilePath);
|
||||||
|
|
||||||
|
let keyFilePath = interpolateString(clientCert.keyFilePath, interpolationOptions);
|
||||||
|
keyFilePath = path.isAbsolute(keyFilePath) ? keyFilePath : path.join(collectionPath, keyFilePath);
|
||||||
|
|
||||||
if (domain && certFilePath && keyFilePath) {
|
if (domain && certFilePath && keyFilePath) {
|
||||||
const hostRegex = '^https:\\/\\/' + domain.replaceAll('.', '\\.').replaceAll('*', '.*');
|
const hostRegex = '^https:\\/\\/' + domain.replaceAll('.', '\\.').replaceAll('*', '.*');
|
||||||
|
|
||||||
if (request.url.match(hostRegex)) {
|
if (request.url.match(hostRegex)) {
|
||||||
try {
|
try {
|
||||||
httpsAgentRequestFields['cert'] = fs.readFileSync(certFilePath);
|
httpsAgentRequestFields['cert'] = fs.readFileSync(certFilePath);
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Error reading cert file', err);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
httpsAgentRequestFields['key'] = fs.readFileSync(keyFilePath);
|
httpsAgentRequestFields['key'] = fs.readFileSync(keyFilePath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Error reading cert/key file', err);
|
console.log('Error reading key file', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
httpsAgentRequestFields['passphrase'] = interpolateString(clientCert.passphrase, interpolationOptions);
|
httpsAgentRequestFields['passphrase'] = interpolateString(clientCert.passphrase, interpolationOptions);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -389,7 +408,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
request,
|
request,
|
||||||
envVars,
|
envVars,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
collectionPath
|
||||||
);
|
);
|
||||||
|
|
||||||
let response, responseTime;
|
let response, responseTime;
|
||||||
@ -564,7 +584,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
preparedRequest,
|
preparedRequest,
|
||||||
envVars,
|
envVars,
|
||||||
collection.collectionVariables,
|
collection.collectionVariables,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
collectionPath
|
||||||
);
|
);
|
||||||
const response = await axiosInstance(preparedRequest);
|
const response = await axiosInstance(preparedRequest);
|
||||||
|
|
||||||
@ -695,7 +716,8 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
request,
|
request,
|
||||||
envVars,
|
envVars,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
collectionPath
|
||||||
);
|
);
|
||||||
|
|
||||||
timeStart = Date.now();
|
timeStart = Date.now();
|
||||||
|
Loading…
Reference in New Issue
Block a user