Skip to content

Commit 295c7a9

Browse files
committed
fix: use https proxy when proxy is set
1 parent 31f44db commit 295c7a9

13 files changed

+143
-71
lines changed

bin/commands/info.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const config = require("../helpers/config"),
66
utils = require("../helpers/utils"),
77
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails;
88

9+
const { setAxiosProxy } = require('../helpers/helper');
10+
911
module.exports = function info(args, rawArgs) {
1012
let bsConfigPath = utils.getConfigPath(args.cf);
1113

@@ -45,15 +47,18 @@ module.exports = function info(args, rawArgs) {
4547
let message = null;
4648
let messageType = null;
4749
let errorCode = null;
48-
50+
51+
options.config = {
52+
auth: {
53+
username: bsConfig.auth.username,
54+
password: bsConfig.auth.access_key
55+
},
56+
headers: options.headers
57+
};
58+
setAxiosProxy(options.config);
59+
4960
try {
50-
const response = await axios.get(options.url, {
51-
auth: {
52-
username: bsConfig.auth.username,
53-
password: bsConfig.auth.access_key
54-
},
55-
headers: options.headers
56-
});
61+
const response = await axios.get(options.url, options.config);
5762
let build = null;
5863
try {
5964
build = response.data;

bin/commands/runs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ module.exports = function run(args, rawArgs) {
301301
});
302302
} else if(!turboScaleSession){
303303
let stacktraceUrl = getStackTraceUrl();
304-
downloadBuildStacktrace(stacktraceUrl).then((message) => {
304+
downloadBuildStacktrace(stacktraceUrl, bsConfig).then((message) => {
305305
utils.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
306306
}).catch((err) => {
307307
let message = `Downloading build stacktrace failed with statuscode: ${err}. Please visit ${data.dashboard_url} for additional details.`;

bin/helpers/build.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const config = require('./config'),
77
utils = require('../helpers/utils'),
88
logger = require('../helpers/logger').winstonLogger;
99

10+
const { setAxiosProxy } = require('./helper');
11+
1012
const createBuild = (bsConfig, zip) => {
1113
return new Promise(function (resolve, reject) {
1214
capabilityHelper.caps(bsConfig, zip).then(async function(data){
@@ -23,14 +25,17 @@ const createBuild = (bsConfig, zip) => {
2325
body: data
2426
}
2527

28+
const axiosConfig = {
29+
auth: {
30+
username: options.auth.user,
31+
password: options.auth.password
32+
},
33+
headers: options.headers
34+
}
35+
setAxiosProxy(axiosConfig);
36+
2637
try {
27-
const response = await axios.post(options.url, data, {
28-
auth: {
29-
username: options.auth.user,
30-
password: options.auth.password
31-
},
32-
headers: options.headers
33-
});
38+
const response = await axios.post(options.url, data, axiosConfig);
3439
let build = null;
3540
try {
3641
build = response.data;

bin/helpers/buildArtifacts.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const HttpsProxyAgent = require('https-proxy-agent');
1313
const FormData = require('form-data');
1414
const decompress = require('decompress');
1515
const unzipper = require("unzipper");
16+
const { setAxiosProxy } = require('./helper');
1617

1718
let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
1819
let BUILD_ARTIFACTS_FAIL_COUNT = 0;
@@ -110,10 +111,12 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
110111
logger.debug(`Downloading build artifact for: ${filePath}`)
111112
return new Promise(async (resolve, reject) => {
112113
try {
113-
const response = await axios.get(url, {
114+
const axiosConfig = {
114115
responseType: 'stream',
115116
validateStatus: status => (status >= 200 && status < 300) || status === 404
116-
});
117+
};
118+
setAxiosProxy(axiosConfig);
119+
const response = await axios.get(url, axiosConfig);
117120
if(response.status != 200) {
118121
if (response.status === 404) {
119122
reject(Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND);
@@ -195,16 +198,19 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs, bu
195198
}
196199

197200
options.formData = data.toString();
201+
const axiosConfig = {
202+
auth: {
203+
username: options.auth.username,
204+
password: options.auth.password
205+
},
206+
headers: options.headers
207+
};
208+
setAxiosProxy(axiosConfig);
209+
198210
let responseData = null;
199211
return new Promise (async (resolve, reject) => {
200212
try {
201-
const response = await axios.post(options.url, data, {
202-
auth: {
203-
username: options.auth.username,
204-
password: options.auth.password
205-
},
206-
headers: options.headers
207-
});
213+
const response = await axios.post(options.url, data, axiosConfig);
208214
try {
209215
responseData = response.data;
210216
} catch(e) {
@@ -251,13 +257,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
251257
auth: options.auth,
252258
headers: options.headers
253259
}
254-
if(process.env.HTTP_PROXY){
255-
options.config.proxy = false;
256-
options.config.httpAgent = new HttpsProxyAgent(process.env.HTTP_PROXY);
257-
} else if (process.env.HTTPS_PROXY){
258-
options.config.proxy = false;
259-
options.config.httpAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY);
260-
}
260+
setAxiosProxy(options.config);
261261
let response;
262262
try {
263263
response = await axios.get(options.url, options.config);

bin/helpers/checkUploaded.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const crypto = require('crypto'),
1111
utils = require('./utils'),
1212
logger = require('./logger').winstonLogger;
1313

14+
const { setAxiosProxy } = require('./helper');
1415

1516
const checkSpecsMd5 = (runSettings, args, instrumentBlocks) => {
1617
return new Promise(function (resolve, reject) {
@@ -124,14 +125,18 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
124125
}
125126

126127
instrumentBlocks.markBlockStart("checkAlreadyUploaded.railsCheck");
128+
129+
const axiosConfig = {
130+
auth: {
131+
username: options.auth.user,
132+
password: options.auth.password
133+
},
134+
headers: options.headers
135+
};
136+
setAxiosProxy(axiosConfig);
137+
127138
try {
128-
const response = await axios.post(options.url, options.body, {
129-
auth: {
130-
username: options.auth.user,
131-
password: options.auth.password
132-
},
133-
headers: options.headers
134-
})
139+
const response = await axios.post(options.url, options.body, axiosConfig);
135140
let zipData = null;
136141
try {
137142
zipData = response.data;

bin/helpers/downloadBuildStacktrace.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
'use strict';
22
const { default: axios } = require('axios');
3+
const { setAxiosProxy } = require('./helper');
4+
5+
const downloadBuildStacktrace = async (url, bsConfig) => {
6+
const axiosConfig = {
7+
auth: {
8+
username: bsConfig.auth.username,
9+
password: bsConfig.auth.access_key
10+
},
11+
responseType: 'stream',
12+
};
13+
setAxiosProxy(axiosConfig);
314

4-
const downloadBuildStacktrace = async (url) => {
515
return new Promise(async (resolve, reject) => {
616
try {
7-
const response = await axios.get(url, { responseType: 'stream' });
17+
const response = await axios.get(url, axiosConfig);
818
if (response.status === 200) {
919
response.data.pipe(process.stdout);
1020
let error = null;

bin/helpers/getInitialDetails.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const logger = require('./logger').winstonLogger,
55
config = require("./config"),
66
Constants = require('./constants');
77

8+
const { setAxiosProxy } = require('./helper');
9+
810
exports.getInitialDetails = (bsConfig, args, rawArgs) => {
911
return new Promise(async (resolve, reject) => {
1012
let options = {
@@ -18,11 +20,15 @@ exports.getInitialDetails = (bsConfig, args, rawArgs) => {
1820
}
1921
};
2022
let responseData = {};
23+
24+
const axiosConfig = {
25+
auth: options.auth,
26+
headers: options.headers,
27+
}
28+
setAxiosProxy(axiosConfig);
29+
2130
try {
22-
const response = await axios.get(options.url, {
23-
auth: options.auth,
24-
headers: options.headers,
25-
});
31+
const response = await axios.get(options.url, axiosConfig);
2632
try {
2733
responseData = response.data;
2834
} catch (e) {

bin/helpers/helper.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const glob = require('glob');
1717
const pGitconfig = promisify(gitconfig);
1818
const { readCypressConfigFile } = require('./readCypressConfigUtil');
1919
const { MAX_GIT_META_DATA_SIZE_IN_BYTES, GIT_META_DATA_TRUNCATED } = require('./constants')
20+
const HttpsProxyAgent = require('https-proxy-agent');
2021

2122
exports.debug = (text, shouldReport = false, throwable = null) => {
2223
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
@@ -437,6 +438,13 @@ exports.truncateString = (field, truncateSizeInBytes) => {
437438
return field;
438439
};
439440

441+
exports.setAxiosProxy = (axiosConfig) => {
442+
if (process.env.HTTP_PROXY || process.env.HTTPS_PROXY) {
443+
const httpProxy = process.env.HTTP_PROXY || process.env.HTTPS_PROXY
444+
axiosConfig.httpsAgent = new HttpsProxyAgent(httpProxy);
445+
};
446+
};
447+
440448
exports.combineMacWinNpmDependencies = (runSettings) => {
441449
return Object.assign({}, runSettings.npm_dependencies, runSettings.win_npm_dependencies || {}, runSettings.mac_npm_dependencies || {})
442450
};

bin/helpers/reporterHTML.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const fs = require('fs'),
88
config = require("./config"),
99
decompress = require('decompress');
1010

11+
const { setAxiosProxy } = require('./helper');
12+
1113
let reportGenerator = async (bsConfig, buildId, args, rawArgs, buildReportData, cb) => {
1214
let options = {
1315
url: `${config.buildUrl}${buildId}/custom_report`,
@@ -26,14 +28,18 @@ let reportGenerator = async (bsConfig, buildId, args, rawArgs, buildReportData,
2628
let messageType = null;
2729
let errorCode = null;
2830
let build;
31+
32+
const axiosConfig = {
33+
auth: {
34+
username: options.auth.user,
35+
password: options.auth.password
36+
},
37+
headers: options.headers
38+
}
39+
setAxiosProxy(axiosConfig);
40+
2941
try {
30-
const response = await axios.get(options.url, {
31-
auth: {
32-
username: options.auth.user,
33-
password: options.auth.password
34-
},
35-
headers: options.headers
36-
});
42+
const response = await axios.get(options.url, axiosConfig);
3743
logger.debug('Received reports data from upstream.');
3844
try {
3945
build = response.data;
@@ -115,7 +121,11 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {
115121
logger.debug(`Fetching build reports zip.`)
116122
return new Promise(async (resolve, reject) => {
117123
try {
118-
const response = await axios.get(reportJsonUrl, {responseType: 'stream'});
124+
const axiosConfig = {
125+
responseType: 'stream',
126+
};
127+
setAxiosProxy(axiosConfig);
128+
const response = await axios.get(reportJsonUrl, axiosConfig);
119129
if(response.status === 200) {
120130
//ensure that the user can call `then()` only when the file has
121131
//been downloaded entirely.

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const config = require("../config"),
1111
tableStream = require('table').createStream,
1212
chalk = require('chalk');
1313

14+
const { setAxiosProxy } = require('../helper');
15+
1416
let whileLoop = true, whileTries = config.retries, options, timeout = 3000, n = 2, tableConfig, stream, endTime, startTime = Date.now(), buildStarted = false;
1517
let specSummary = {
1618
"buildError": null,
@@ -139,13 +141,16 @@ let printSpecsStatus = (bsConfig, buildDetails, rawArgs, buildReportData) => {
139141

140142
let whileProcess = async (whilstCallback) => {
141143
try {
142-
const response = await axios.post(options.url, null, {
144+
const axiosConfig = {
143145
auth: {
144146
username: options.auth.user,
145147
password: options.auth.password
146148
},
147149
headers: options.headers
148-
});
150+
};
151+
setAxiosProxy(axiosConfig);
152+
153+
const response = await axios.post(options.url, null, axiosConfig);
149154
whileTries = config.retries; // reset to default after every successful request
150155
switch (response.status) {
151156
case 202: // get data here and print it

0 commit comments

Comments
 (0)